x220-acpi: Add acpi event scripts for Lenovo X220
[shutils.git] / lenovo-x220-linuxacpi / etc / acpi / actions / btn-vga.sh
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-vga.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-vga.sh
new file mode 100755 (executable)
index 0000000..629b400
--- /dev/null
@@ -0,0 +1,72 @@
+#! /bin/sh
+
+. /usr/local/bin/getXenv.inc
+
+STATEFILE="/var/run/vgastate"
+LVDS1_defaultmode="1366x768"
+
+function vgaoff
+{
+       logger "Turn external video off, putting LVDS1 to standard setup"
+       xrandr --output VGA1 --off \
+               --output HDMI2 --off \
+               --output LVDS1 --primary --mode $LVDS1_defaultmode --scale 1x1
+       echo "vgaoff" > $STATEFILE
+}
+
+function vgamirror
+{
+       logger "Mirror LVDS1 to $1"
+       xrandr --output $1 --primary --auto \
+               --output LVDS1 --mode 1024x768 --same-as VGA1
+       echo "vgamirror" > $STATEFILE
+}
+
+function vgarightof
+{
+       logger "Putting $1 right of of LVDS1"
+       xrandr --output LVDS1 --primary --auto --mode $LVDS1_defaultmode \
+               --output $1 --auto --right-of LVDS1
+       echo "vgarightof" > $STATEFILE
+}
+
+function vgaleftof
+{
+       logger "Putting $1 left of of LVDS1"
+       xrandr --output LVDS1 --primary --auto --mode $LVDS1_defaultmode \
+               --output $1 --auto --left-of LVDS1
+       echo "vgaleftof" > $STATEFILE
+}
+
+
+extconn=""
+xrandr | grep "VGA1 connected" && extconn="VGA1"
+xrandr | grep "HDMI2 connected" && extconn="HDMI2"
+
+if [ -n "$extconn" ]; then
+       case `cat $STATEFILE 2> /dev/null` in
+
+               vgarightof)
+                       vgaleftof $extconn
+                       exit 0
+               ;;
+       
+               vgaleftof)
+                       vgamirror $extconn
+                       exit 0
+               ;;
+
+
+               vgamirror)
+                       vgaoff
+                       exit 0
+               ;;
+
+               *)
+                       vgarightof $extconn
+                       exit 0
+               ;;              
+       esac
+else
+       vgaoff
+fi