Skip to content

Instantly share code, notes, and snippets.

@jmar71n
Created May 16, 2011 10:10
Show Gist options
  • Save jmar71n/974188 to your computer and use it in GitHub Desktop.
Save jmar71n/974188 to your computer and use it in GitHub Desktop.
acpi handler.sh script for IBM x41 / X41T
#!/bin/bash
set $*
case "$1" in
ibm/hotkey)
case "$4" in
00001004)
/usr/sbin/pm-suspend
;;
00005009)
xrandr -display :0 --output LVDS1 --rotate right
xsetwacom --display :0 --set 'Serial Wacom Tablet stylus' Rotate CW
;;
0000500a)
xrandr -display :0 --output LVDS1 --rotate normal
xsetwacom --display :0 --set 'Serial Wacom Tablet stylus' Rotate NONE
;;
00001003)
/usr/bin/xset dpms force off
;;
00001007)
INT=LVDS1
EXT=VGA1
get_state() {
local output=$1
local state=$(xrandr | grep $output)
if [[ $state =~ disconnected ]]; then
echo disconnected
else
if [[ $state =~ [0-9]+x[0-9]+ ]]; then
echo on
else
echo off
fi
fi
}
INT_STATE=$(get_state $INT)
EXT_STATE=$(get_state $EXT)
if [[ $EXT_STATE = "disconnected" ]]; then
xrandr --output $INT --auto --output $EXT --off
elif [[ $INT_STATE = "on" && $EXT_STATE = "off" ]]; then
xrandr --output $INT --auto --output $EXT --auto
elif [[ $INT_STATE = "on" && $EXT_STATE = "on" ]]; then
xrandr --output $INT --off --output $EXT --auto
elif [[ $INT_STATE = "off" && $EXT_STATE = "on" ]]; then
xrandr --output $INT --auto --output $EXT --off
fi
;;
esac
;;
ac_adapter)
case "$4" in
00000000)
if [ $(/bin/awk '{print $2}' /proc/acpi/button/lid/LID/state) = "closed" ]; then
/usr/sbin/pm-suspend
fi
;;
esac
;;
button/power)
case "$2" in
PWRF)
/sbin/init 0
;;
esac
;;
button/lid)
if [ $(/bin/awk '{print $2}' /proc/acpi/button/lid/LID/state) = "closed" ]; then
if [ $(/bin/awk '{print $2}' /proc/acpi/ac_adapter/AC/state) = "off-line" ]; then
/usr/sbin/pm-suspend
fi
fi
;;
esac
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment