x220-acpi: Add acpi event scripts for Lenovo X220
[shutils.git] / lenovo-x220-linuxacpi / etc / acpi / actions / btn-vga.sh
1 #! /bin/sh
2
3 . /usr/local/bin/getXenv.inc
4
5 STATEFILE="/var/run/vgastate"
6 LVDS1_defaultmode="1366x768"
7
8 function vgaoff
9 {
10 logger "Turn external video off, putting LVDS1 to standard setup"
11 xrandr --output VGA1 --off \
12 --output HDMI2 --off \
13 --output LVDS1 --primary --mode $LVDS1_defaultmode --scale 1x1
14 echo "vgaoff" > $STATEFILE
15 }
16
17 function vgamirror
18 {
19 logger "Mirror LVDS1 to $1"
20 xrandr --output $1 --primary --auto \
21 --output LVDS1 --mode 1024x768 --same-as VGA1
22 echo "vgamirror" > $STATEFILE
23 }
24
25 function vgarightof
26 {
27 logger "Putting $1 right of of LVDS1"
28 xrandr --output LVDS1 --primary --auto --mode $LVDS1_defaultmode \
29 --output $1 --auto --right-of LVDS1
30 echo "vgarightof" > $STATEFILE
31 }
32
33 function vgaleftof
34 {
35 logger "Putting $1 left of of LVDS1"
36 xrandr --output LVDS1 --primary --auto --mode $LVDS1_defaultmode \
37 --output $1 --auto --left-of LVDS1
38 echo "vgaleftof" > $STATEFILE
39 }
40
41
42 extconn=""
43 xrandr | grep "VGA1 connected" && extconn="VGA1"
44 xrandr | grep "HDMI2 connected" && extconn="HDMI2"
45
46 if [ -n "$extconn" ]; then
47 case `cat $STATEFILE 2> /dev/null` in
48
49 vgarightof)
50 vgaleftof $extconn
51 exit 0
52 ;;
53
54 vgaleftof)
55 vgamirror $extconn
56 exit 0
57 ;;
58
59
60 vgamirror)
61 vgaoff
62 exit 0
63 ;;
64
65 *)
66 vgarightof $extconn
67 exit 0
68 ;;
69 esac
70 else
71 vgaoff
72 fi