Difference between revisions of "Sample Fn-F7 script"

From ThinkWiki
Jump to: navigation, search
Line 1: Line 1:
 
This setup will let you use fn-F7 key combination to toggle between internal, external, or both screens.  Tested on ThinkPad X60s running Fedora 8.
 
This setup will let you use fn-F7 key combination to toggle between internal, external, or both screens.  Tested on ThinkPad X60s running Fedora 8.
  
Note: you will need to change the internal and external resolution until someone fixes this script to figure it out from xrandr.
+
Note: you will need to change the internal and external resolution until someone fixes this script to figure it out from xrandr, you may also need to change output names from "VGA" and "LVDS" to what your xrandr tells you.
  
 
Create /etc/acpi/events/thinkpad.conf:
 
Create /etc/acpi/events/thinkpad.conf:
Line 15: Line 15:
 
<code>
 
<code>
 
#!/bin/sh
 
#!/bin/sh
 +
 +
EXTERNAL_OUTPUT=VGA
 +
EXTERNAL_MODE=1600x1200
 +
 +
INTERNAL_OUTPUT=LVDS
 +
INTERNAL_MODE=1024x768
  
 
DO=$(basename $0)
 
DO=$(basename $0)
Line 29: Line 35:
  
 
function screen_external(){
 
function screen_external(){
         $SU "xrandr --output LVDS --off"
+
         $SU "xrandr --output $INTERNAL_OUTPUT --off"
         $SU "xrandr --output VGA --mode 1600x1200 --left-of LVDS"
+
         $SU "xrandr --output $EXTERNAL_OUTPUT --mode $EXTERNAL_MODE --left-of LVDS"
 
         echo "external" > $STATE_FILE
 
         echo "external" > $STATE_FILE
 
}
 
}
  
 
function screen_internal(){
 
function screen_internal(){
         $SU "xrandr --output VGA --off"
+
         $SU "xrandr --output $EXTERNAL_OUTPUT --off"
         $SU "xrandr --output LVDS --mode 1024x768 --right-of VGA"
+
         $SU "xrandr --output $INTERNAL_OUTPUT --mode $INTERNAL_MODE --right-of VGA"
 
         echo "internal" > $STATE_FILE
 
         echo "internal" > $STATE_FILE
 
}
 
}
  
 
function screen_both(){
 
function screen_both(){
         $SU "xrandr --output VGA --mode 1600x1200 --left-of LVDS"
+
         $SU "xrandr --output $EXTERNAL_OUTPUT --mode $EXTERNAL_MODE --left-of LVDS"
         $SU "xrandr --output LVDS --mode 1024x768 --right-of VGA"
+
         $SU "xrandr --output $INTERNAL_OUTPUT --mode $INTERNAL_MODE --right-of VGA"
 
         echo "both" > $STATE_FILE
 
         echo "both" > $STATE_FILE
 
}
 
}
Line 73: Line 79:
 
                 ;;
 
                 ;;
 
esac
 
esac
 +
 
</code>
 
</code>
  

Revision as of 18:51, 9 November 2007

This setup will let you use fn-F7 key combination to toggle between internal, external, or both screens. Tested on ThinkPad X60s running Fedora 8.

Note: you will need to change the internal and external resolution until someone fixes this script to figure it out from xrandr, you may also need to change output names from "VGA" and "LVDS" to what your xrandr tells you.

Create /etc/acpi/events/thinkpad.conf:

  1. fn-F7

event=ibm/hotkey HKEY 00000080 00001007 action=/usr/local/sbin/thinkpad-f7

Create /usr/local/sbin/thinkpad-f7:

  1. !/bin/sh

EXTERNAL_OUTPUT=VGA EXTERNAL_MODE=1600x1200

INTERNAL_OUTPUT=LVDS INTERNAL_MODE=1024x768

DO=$(basename $0)

SU="su $(w -h -s | grep ":[0-9]" | head -1 | awk '{print $1}') -c" export DISPLAY=$(w -h -s | grep ":[0-9]" | head -1 | awk '{print $3}')

STATE_FILE=/var/lib/thinkpad/screen.state; if [ ! -e $STATE_FILE ]; then

       echo "internal" > $STATE_FILE

fi

STATE=$(cat $STATE_FILE)

function screen_external(){

       $SU "xrandr --output $INTERNAL_OUTPUT --off"
       $SU "xrandr --output $EXTERNAL_OUTPUT --mode $EXTERNAL_MODE --left-of LVDS"
       echo "external" > $STATE_FILE

}

function screen_internal(){

       $SU "xrandr --output $EXTERNAL_OUTPUT --off"
       $SU "xrandr --output $INTERNAL_OUTPUT --mode $INTERNAL_MODE --right-of VGA"
       echo "internal" > $STATE_FILE

}

function screen_both(){

       $SU "xrandr --output $EXTERNAL_OUTPUT --mode $EXTERNAL_MODE --left-of LVDS"
       $SU "xrandr --output $INTERNAL_OUTPUT --mode $INTERNAL_MODE --right-of VGA"
       echo "both" > $STATE_FILE

}

case "$DO" in

       thinkpad-toggle | thinkpad-f7)
               case "$STATE" in
                       internal)
                               screen_external
                               ;;
                       external)
                               screen_both
                               ;;
                       both)
                               screen_internal
                               ;;
                       *)
                               screen_internal
                               ;;
               esac
               ;;
       thinkpad-dock)
               screen_internal
               ;;
       thinkpad-undock)
               screen_external
               ;;
       *)
               echo "usage: rename to thinkpad-dock, thinkpad-undock, or thinkpad-toggle" >&2
               ;;

esac

As root,

mkdir -p /var/lib/thinkpad echo "internal" > /var/lib/thinkpad/screen.state chmod 755 /usr/local/sbin/thinkpad-f7 service acpid restart