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