]> git.sthu.org Git - shutils.git/commitdiff
x220-acpi: Add acpi event scripts for Lenovo X220
authorStefan Huber <shuber@sthu.org>
Tue, 5 Nov 2013 20:30:53 +0000 (21:30 +0100)
committerStefan Huber <shuber@sthu.org>
Tue, 5 Nov 2013 20:30:53 +0000 (21:30 +0100)
29 files changed:
lenovo-x220-linuxacpi/etc/acpi/actions/ac.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-battery.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-cammic.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-hibernate.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-lock.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-suspend.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-touchpad.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-vga.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-vgapause.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/btn-wireless.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/lm_ac_adapter.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/lm_battery.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/lm_lid.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/actions/powerbtn.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/default.sh [new file with mode: 0755]
lenovo-x220-linuxacpi/etc/acpi/events/ac.sh [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn12 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn2 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn3 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn4 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn5 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn6 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn7 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn8 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/btn-fn9 [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/default [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/lm_ac_adapter [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/lm_battery [new file with mode: 0644]
lenovo-x220-linuxacpi/etc/acpi/events/lm_lid [new file with mode: 0644]

diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/ac.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/ac.sh
new file mode 100755 (executable)
index 0000000..5be83b6
--- /dev/null
@@ -0,0 +1,3 @@
+#! /bin/sh
+logger "AC event..."
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-battery.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-battery.sh
new file mode 100755 (executable)
index 0000000..50d4884
--- /dev/null
@@ -0,0 +1 @@
+#! /bin/sh
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-cammic.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-cammic.sh
new file mode 100755 (executable)
index 0000000..3bf0d69
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+/etc/init.d/autofs restart
+
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-hibernate.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-hibernate.sh
new file mode 100755 (executable)
index 0000000..9f8dd70
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+pm-hibernate
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-lock.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-lock.sh
new file mode 100755 (executable)
index 0000000..7ddecfd
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+logger "Locking screen..."
+
+LOG=/var/log/btn-lock.log
+date >> $LOG
+
+/usr/local/bin/lockkde.sh
+echo "Locked..." >> $LOG
+
+. /usr/local/bin/getXenv.inc
+
+#Thinkpad acceleration alert
+su $user -c /usr/local/bin/tp_alert.sh >> $LOG 2>&1
+
+
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-suspend.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-suspend.sh
new file mode 100755 (executable)
index 0000000..9db84cd
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+#PM_DEBUG=true pm-suspend
+pm-suspend
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-touchpad.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-touchpad.sh
new file mode 100755 (executable)
index 0000000..b837bcb
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. /usr/local/bin/getXenv.inc
+
+if (synclient -l | grep TouchpadOff | grep -q 0) ; then
+       echo "touchpad on, turning it off"
+       su $user -c "synclient TouchpadOff=1"
+else
+       echo "touchpad off, turning it on"
+       su $user -c "synclient TouchpadOff=0"
+fi
+
+
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
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-vgapause.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-vgapause.sh
new file mode 100755 (executable)
index 0000000..16db1f3
--- /dev/null
@@ -0,0 +1,9 @@
+#! /bin/bash
+. /usr/local/bin/getXenv.inc
+
+logger "Disabeling VGA"
+xrandr --output VGA1 --off
+echo "off" > /var/run/vgastate
+
+
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/btn-wireless.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/btn-wireless.sh
new file mode 100755 (executable)
index 0000000..a8b7c3e
--- /dev/null
@@ -0,0 +1,2 @@
+#! /bin/sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/lm_ac_adapter.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/lm_ac_adapter.sh
new file mode 100755 (executable)
index 0000000..87f5a33
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+test -f /usr/sbin/laptop_mode || exit 0
+
+# ac on/offline event handler
+
+/usr/sbin/laptop_mode auto
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/lm_battery.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/lm_battery.sh
new file mode 100755 (executable)
index 0000000..0bce5a7
--- /dev/null
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+test -f /usr/sbin/laptop_mode || exit 0
+
+# Automatically disable laptop mode when the battery almost runs out,
+# and re-enable it when it 
+
+/usr/sbin/laptop_mode auto
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/lm_lid.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/lm_lid.sh
new file mode 100755 (executable)
index 0000000..e3ffb71
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+test -f /usr/sbin/laptop_mode || exit 0
+
+# lid button pressed/released event handler
+
+/usr/sbin/laptop_mode auto
diff --git a/lenovo-x220-linuxacpi/etc/acpi/actions/powerbtn.sh b/lenovo-x220-linuxacpi/etc/acpi/actions/powerbtn.sh
new file mode 100755 (executable)
index 0000000..39a3d9b
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+# /etc/acpi/powerbtn.sh
+# Taken from Debian's 2.0.4-1 diff file.  This version handles KDE4.
+# Power Button event handler.
+# Checks to see if gnome or KDE are already handling the power button.
+# If not, initiates a plain shutdown.
+
+# getXuser gets the X user belonging to the display in $displaynum.
+# If you want the foreground X user, use getXconsole!
+# Input:
+#   displaynum - X display number
+# Output: 
+#   XUSER - the name of the user
+#   XAUTHORITY - full pathname of the user's .Xauthority file
+getXuser() {
+        user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
+        if [ x"$user" = x"" ]; then
+                startx=`pgrep -n startx`
+                if [ x"$startx" != x"" ]; then
+                        user=`ps -o user --no-headers $startx`
+                fi
+        fi
+        if [ x"$user" != x"" ]; then
+                userhome=`getent passwd $user | cut -d: -f6`
+                export XAUTHORITY=$userhome/.Xauthority
+        else
+                export XAUTHORITY=""
+        fi
+        export XUSER=$user
+}
+
+# Gets the X display number for the active virtual terminal.
+# Output:
+#   DISPLAY - the X display number
+#   See getXuser()'s output.
+getXconsole() {
+        console=`fgconsole`;
+        displaynum=`ps t tty$console | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
+        if [ x"$displaynum" != x"" ]; then
+                export DISPLAY=":$displaynum"
+                getXuser
+        fi
+}
+
+# Skip if we are just in the middle of resuming.
+test -f /var/lock/acpisleep && exit 0
+
+# If the current X console user is running a power management daemon that
+# handles suspend/resume requests, let them handle policy.
+
+getXconsole
+
+# A list of power management system process names.
+PMS="gnome-power-manager kpowersave xfce4-power-manager"
+PMS="$PMS guidance-power-manager.py dalston-power-applet"
+
+# If one of those is running or any of several others,
+if pidof x $PMS > /dev/null ||
+       ( test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon) ||
+       ( test "$XUSER" != "" && test -x /usr/bin/qdbus && test -r /proc/$(pidof kded4)/environ && su - $XUSER -c "eval $(echo -n 'export '; cat /proc/$(pidof kded4)/environ |tr '\0' '\n'|grep DBUS_SESSION_BUS_ADDRESS); qdbus org.kde.kded" | grep -q powerdevil) ; then
+       # Get out as the power manager that is running will take care of things.
+    exit
+fi
+
+# No power managment system appears to be running.  Just initiate a plain 
+# shutdown.
+/sbin/shutdown -h now "Power button pressed"
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/default.sh b/lenovo-x220-linuxacpi/etc/acpi/default.sh
new file mode 100755 (executable)
index 0000000..8be6f3e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# /etc/acpi/default.sh
+# Default acpi script that takes an entry for all actions
+
+set $*
+
+group=${1%%/*}
+action=${1#*/}
+device=$2
+id=$3
+value=$4
+
+log_unhandled() {
+       logger "ACPI event unhandled: $*"
+}
+
+case "$group" in
+       button)
+               case "$action" in
+                       power)
+                               /etc/acpi/actions/powerbtn.sh
+                               ;;
+
+                       # if your laptop doesnt turn on/off the display via hardware
+                       # switch and instead just generates an acpi event, you can force
+                       # X to turn off the display via dpms.  note you will have to run
+                       # 'xhost +local:0' so root can access the X DISPLAY.
+                       #lid)
+                       #       xset dpms force off
+                       #       ;;
+
+                       *)      log_unhandled $* ;;
+               esac
+               ;;
+
+       ac_adapter)
+               case "$value" in
+                       # Add code here to handle when the system is unplugged
+                       # (maybe change cpu scaling to powersave mode).  For
+                       # multicore systems, make sure you set powersave mode
+                       # for each core!
+                       #*0)
+                       #       cpufreq-set -g powersave
+                       #       ;;
+
+                       # Add code here to handle when the system is plugged in
+                       # (maybe change cpu scaling to performance mode).  For
+                       # multicore systems, make sure you set performance mode
+                       # for each core!
+                       #*1)
+                       #       cpufreq-set -g performance
+                       #       ;;
+
+                       *)      log_unhandled $* ;;
+               esac
+               ;;
+
+       *)      log_unhandled $* ;;
+esac
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/ac.sh b/lenovo-x220-linuxacpi/etc/acpi/events/ac.sh
new file mode 100644 (file)
index 0000000..fac7bcb
--- /dev/null
@@ -0,0 +1,3 @@
+#event=ibm/hotkey HKEY 00000080 00006030
+#action=/etc/acpi/actions/ac.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn12 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn12
new file mode 100644 (file)
index 0000000..076932e
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 0000100c
+action=/etc/acpi/actions/btn-hibernate.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn2 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn2
new file mode 100644 (file)
index 0000000..89da49c
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001002
+action=/etc/acpi/actions/btn-lock.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn3 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn3
new file mode 100644 (file)
index 0000000..edebad5
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001003
+action=/etc/acpi/actions/btn-battery.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn4 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn4
new file mode 100644 (file)
index 0000000..fb93bc7
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001004
+action=/etc/acpi/actions/btn-suspend.sh %e
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn5 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn5
new file mode 100644 (file)
index 0000000..e5260b3
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001005
+action=/etc/acpi/actions/btn-wireless.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn6 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn6
new file mode 100644 (file)
index 0000000..2dae64a
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001006
+action=/etc/acpi/actions/btn-cammic.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn7 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn7
new file mode 100644 (file)
index 0000000..16d105d
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001007
+action=/etc/acpi/actions/btn-vga.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn8 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn8
new file mode 100644 (file)
index 0000000..bea0e4b
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001008
+action=/etc/acpi/actions/btn-touchpad.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn9 b/lenovo-x220-linuxacpi/etc/acpi/events/btn-fn9
new file mode 100644 (file)
index 0000000..03c0a88
--- /dev/null
@@ -0,0 +1,3 @@
+event=ibm/hotkey HKEY 00000080 00001009
+action=/etc/acpi/actions/btn-vgapause.sh
+
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/default b/lenovo-x220-linuxacpi/etc/acpi/events/default
new file mode 100644 (file)
index 0000000..a07c182
--- /dev/null
@@ -0,0 +1,19 @@
+# /etc/acpi/events/default
+# This is the ACPID default configuration, it takes all
+# events and passes them to /etc/acpi/default.sh for further
+# processing.
+
+# event keeps a regular expression matching the event. To get
+# power events only, just use something like "event=button[ /]power.*"
+# to catch it.
+# action keeps the command to be executed after an event occurs
+# In case of the power event above, your entry may look this way:
+#event=button[ /]power.*
+#action=/sbin/init 0
+
+# Optionally you can specify the placeholder %e. It will pass
+# through the whole kernel event message to the program you've
+# specified.
+
+event=.*
+action=/etc/acpi/default.sh %e
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/lm_ac_adapter b/lenovo-x220-linuxacpi/etc/acpi/events/lm_ac_adapter
new file mode 100644 (file)
index 0000000..66bd653
--- /dev/null
@@ -0,0 +1,2 @@
+event=ac_adapter.*
+action=/etc/acpi/actions/lm_ac_adapter.sh
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/lm_battery b/lenovo-x220-linuxacpi/etc/acpi/events/lm_battery
new file mode 100644 (file)
index 0000000..b632817
--- /dev/null
@@ -0,0 +1,2 @@
+event=battery.*
+action=/etc/acpi/actions/lm_battery.sh %e
diff --git a/lenovo-x220-linuxacpi/etc/acpi/events/lm_lid b/lenovo-x220-linuxacpi/etc/acpi/events/lm_lid
new file mode 100644 (file)
index 0000000..3c5c9ee
--- /dev/null
@@ -0,0 +1,2 @@
+event=button[ /]lid
+action=/etc/acpi/actions/lm_lid.sh %e