#!/bin/sh # # anrxc's acpid handler for Lenovo ThinkPad SL510 # # Power button starts a system shutdown. # Sleep button suspends the machine to ram. # - delegated this to my WM (Fn+F12 to disk, Fn+F4 to ram) # AC events start laptop_mode (which also controls cpufreq or throttling). # Battery events auto-hibernate on low battery through laptop_mode. # Lid handler locks the screen when someone tries to open it. minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq` maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq` setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" set $* case "$1" in button/power) #echo "PowerButton pressed!">/dev/tty5 case "$2" in PWRF) /sbin/shutdown -h now ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/sleep) case "$2" in SLPB) #/usr/sbin/pm-suspend ;; *) logger "ACPI action undefined: $2" ;; esac ;; ac_adapter) case "$2" in ACAD|AC) case "$4" in 00000000) /usr/sbin/laptop_mode auto #echo -n $minspeed >$setspeed ;; 00000001) /usr/sbin/laptop_mode auto #echo -n $maxspeed >$setspeed ;; esac ;; *) logger "ACPI action undefined: $2" ;; esac ;; battery) case "$2" in BAT1) case "$4" in 00000000) /usr/sbin/laptop_mode auto #echo "BAT1 offline" >/dev/tty5 ;; 00000001) /usr/sbin/laptop_mode auto #echo "BAT1 online" >/dev/tty5 ;; esac ;; CPU0) ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/lid) case "$2" in LID) grep -q open /proc/acpi/button/lid/*/state if [ $? = 0 ]; then XAUTHORITY=/home/anrxc/.Xauthority /bin/su - anrxc -c "/usr/lib/kde4/libexec/kscreenlocker --forcelock --display :0.0" #XAUTHORITY=/home/anrxc/.Xauthority /usr/bin/xset -display :0.0 dpms force on logger "ACPI action executed: DPMS forced on / screen lock" else XAUTHORITY=/home/anrxc/.Xauthority /usr/bin/xset -display :0.0 dpms force off logger "ACPI action executed: DPMS forced off" fi ;; *) logger "ACPI action undefined: $2" ;; esac ;; *) logger "ACPI group/action undefined: $1 / $2" ;; esac