<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://hybrid-graphics-linux.tuxfamily.org/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Asus-switcheroo_graphics-switch.sh&amp;feed=atom&amp;action=history</id>
		<title>Asus-switcheroo graphics-switch.sh - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Asus-switcheroo_graphics-switch.sh&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Asus-switcheroo_graphics-switch.sh&amp;action=history"/>
		<updated>2013-05-22T00:07:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.5</generator>

	<entry>
		<id>http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Asus-switcheroo_graphics-switch.sh&amp;diff=37&amp;oldid=prev</id>
		<title>87.93.107.172: Inserted graphics-switch.sh script.</title>
		<link rel="alternate" type="text/html" href="http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Asus-switcheroo_graphics-switch.sh&amp;diff=37&amp;oldid=prev"/>
				<updated>2011-05-12T09:21:13Z</updated>
		
		<summary type="html">&lt;p&gt;Inserted graphics-switch.sh script.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin&lt;br /&gt;
&lt;br /&gt;
# periodically checks /home/user/switcheroo.txt for changes&lt;br /&gt;
# and uses display-settings to switch to the other graphics card,&lt;br /&gt;
# first allowing for safe termination of the user's session.&lt;br /&gt;
# NOTE: should be run as root inside a screen or by graphics-switch-daemon&lt;br /&gt;
# from init.d.&lt;br /&gt;
&lt;br /&gt;
# vgaswitcheroo location.&lt;br /&gt;
switcheroo=/sys/kernel/debug/vgaswitcheroo/switch&lt;br /&gt;
# Wait for termination of this before acting.&lt;br /&gt;
SESSION=&amp;quot;gnome-session&amp;quot;&lt;br /&gt;
# Which user has the switcheroo.txt file in their home directory.&lt;br /&gt;
U=&amp;quot;vermind&amp;quot;&lt;br /&gt;
# How often to check for switcheroo.txt changes.&lt;br /&gt;
INTERVAL=60&lt;br /&gt;
&lt;br /&gt;
function switch {&lt;br /&gt;
    if [ -f /etc/init.d/gdm3 ]; then&lt;br /&gt;
        /etc/init.d/gdm3 stop&lt;br /&gt;
    else&lt;br /&gt;
        /etc/init.d/gdm stop&lt;br /&gt;
    fi&lt;br /&gt;
    sleep 1&lt;br /&gt;
    /etc/init.d/display-settings autodetect&lt;br /&gt;
    sleep 1&lt;br /&gt;
    if [ -f /etc/init.d/gdm3 ]; then&lt;br /&gt;
        /etc/init.d/gdm3 start&lt;br /&gt;
    else&lt;br /&gt;
        /etc/init.d/gdm start&lt;br /&gt;
    fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function read_switcheroo {&lt;br /&gt;
    if [ -n &amp;quot;${target}&amp;quot; ]; then&lt;br /&gt;
        old=${target}&lt;br /&gt;
    fi&lt;br /&gt;
    target=$( cat /home/${U}/switcheroo.txt )&lt;br /&gt;
    if [ -n &amp;quot;${old}&amp;quot; -a &amp;quot;${target}&amp;quot; != &amp;quot;${old}&amp;quot; ]; then&lt;br /&gt;
        changed=true&lt;br /&gt;
    else&lt;br /&gt;
        unset changed&lt;br /&gt;
    fi&lt;br /&gt;
    # Now, if the target is different than what the switch file says&lt;br /&gt;
 	isIntel=$( cat &amp;quot;${switcheroo}&amp;quot; | grep &amp;quot;IGD:+&amp;quot; )&lt;br /&gt;
	# only switch if not on intel yet&lt;br /&gt;
	if [ &amp;quot;${target}&amp;quot; == &amp;quot;intel&amp;quot; -a -z &amp;quot;${isIntel}&amp;quot; ]; then&lt;br /&gt;
        changed=true&lt;br /&gt;
	else&lt;br /&gt;
		# either already intel, or nvidia wanted&lt;br /&gt;
		# only switch if not on nvidia (i.e. on intel)&lt;br /&gt;
		if [ &amp;quot;${target}&amp;quot; == &amp;quot;nvidia&amp;quot; -a -n &amp;quot;${isIntel}&amp;quot; ]; then&lt;br /&gt;
            changed=true&lt;br /&gt;
		else&lt;br /&gt;
            unset changed&lt;br /&gt;
        fi&lt;br /&gt;
	fi&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function notify_user {&lt;br /&gt;
    sudo -u &amp;quot;$U&amp;quot; env DISPLAY=:0 notify-send &amp;quot;Scheduled switch to ${target}&amp;quot; \&lt;br /&gt;
    &amp;quot;Switch will be performed after your session is closed&amp;quot; \&lt;br /&gt;
    -i system-log-out&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function checkx {&lt;br /&gt;
    xrunning=$( ps -ef | awk -v U=&amp;quot;$U&amp;quot; -v SESSION=&amp;quot;$SESSION&amp;quot; '$1 == U { if ( $8 == SESSION ) print $8}' )&lt;br /&gt;
    #echo &amp;quot;xrunning=$xrunning&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function stuff {&lt;br /&gt;
    #echo &amp;quot;user=$U interval=$INTERVAL session=$SESSION&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    # Actions&lt;br /&gt;
    while true; do&lt;br /&gt;
        read_switcheroo&lt;br /&gt;
        echo &amp;quot;target=$target changed=$changed old=$old&amp;quot;&lt;br /&gt;
        if [ -z &amp;quot;${changed}&amp;quot; ]; then&lt;br /&gt;
            sleep ${INTERVAL}&lt;br /&gt;
            continue;&lt;br /&gt;
        fi&lt;br /&gt;
        # changed&lt;br /&gt;
        notify_user&lt;br /&gt;
        checkx&lt;br /&gt;
        while [ -n &amp;quot;${xrunning}&amp;quot; ]; do&lt;br /&gt;
            sleep ${INTERVAL}&lt;br /&gt;
            checkx&lt;br /&gt;
        done&lt;br /&gt;
        # User session has been closed, switch now&lt;br /&gt;
        switch &amp;quot;${target}&amp;quot;&lt;br /&gt;
        sleep ${INTERVAL}&lt;br /&gt;
        # So we do not switch again too soon in case of errors&lt;br /&gt;
    done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Do stuff!&lt;br /&gt;
stuff&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>87.93.107.172</name></author>	</entry>

	</feed>