#!/bin/bash # # handler -- anrxc's acpid handler for Lenovo ThinkPad T420 # # Primary functions # - power button shuts down (if it generates an ACPI event on this board) # - sleep button suspends the machine to memory # - AC events start laptop_mode which also controls cpufreq (or throttling on old CPUs) # - battery alarm events auto-hibernate on low battery through laptop_mode # - lid handlers lock the screen when someone tries to open it # X server configuration xuser="anrxc" xauth="/home/$xuser/.Xauthority" xdisp=":0.0" # CPU frequency configuration cmins=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq) cmaxs=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq) csets="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" set $* case "$1" in button/power) case "$2" in PWRF|PBTN) logger "PowerButton pressed: $2 - system shutdown" /sbin/shutdown -h now ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/sleep) case "$2" in SLPB|SBTN) logger "SleepButton pressed: $2 - suspending to RAM" /usr/sbin/pm-suspend ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/battery) case "$2" in BAT) logger "BatteryButton pressed: $2 - not acting" #XAUTHORITY=$xauth /bin/su $xuser -c "acpitool -b | xmessage -display $xdisp -timeout 10 -file -" ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/zoom) case "$2" in ZOOM) logger "ZoomButton pressed: $2 - not acting" ;; *) logger "ACPI action undefined: $2" ;; esac ;; button/lid) case "$3" in close) XAUTHORITY=$xauth /usr/bin/xset -display $xdisp dpms force off logger "ACPI action executed: DPMS forced off" ;; open) XAUTHORITY=$xauth /bin/su $xuser -c "/usr/lib/kde4/libexec/kscreenlocker --forcelock --display $xdisp" logger "ACPI action executed: screen lock" ;; *) logger "ACPI action undefined: $2" ;; esac ;; ac_adapter) case "$2" in AC|ACAD|ADP0|ADP1|ACPI0003:00) case "$4" in 00000000) /etc/rc.d/laptop-mode restart #echo -n $cmins >$csets logger "ACPI action executed: ADP ($2) offline" ;; 00000001) /etc/rc.d/laptop-mode restart #echo -n $cmaxs >$csets logger "ACPI action executed: ADP ($2) online" ;; esac ;; *) logger "ACPI action undefined: $2" ;; esac ;; battery) case "$2" in BAT0|BAT1|PNP0C0A:00) case "$4" in 00000000) #/usr/sbin/laptop_mode auto logger "ACPI action executed: no action for BAT ($2) offline" ;; 00000001) /usr/sbin/laptop_mode auto logger "ACPI action executed: BAT ($2) online or ALARM triggered" ;; esac ;; CPU0) logger "ACPI action executed: no action for CPU ($2) battery related event" ;; *) logger "ACPI action undefined: $2" ;; esac ;; processor) case "$2" in CPU0|CPU1|LNXCPU:01) logger "ACPI action executed: CPU ($2) no action for possible thermal event" ;; *) logger "ACPI action undefined: $2" ;; esac ;; video/brightnessup) case "$2" in BRTUP) logger "ACPI action executed: no action for brightnessup" ;; *) logger "ACPI action undefined: $2" ;; esac ;; video/brightnessdown) case "$2" in BRTDN) logger "ACPI action executed: no action for brightnessdown" ;; *) logger "ACPI action undefined: $2" ;; esac ;; *) logger "ACPI group/action undefined: $1 / $2" ;; esac