updated on Thu Jan 19 00:16:31 UTC 2012
[aur-mirror.git] / acpi-eee904 / lid.sh
blob333852fbfd66de00abc3be22cb802abc2ddfabd7
1 #!/bin/sh
2 # This script handles all lid events
4 source /etc/acpi/eee.conf
6 if [ -S /tmp/.X11-unix/X0 ]; then
7 export DISPLAY=:0
8 user=$(who | grep "vc/7" | awk '{ if ($(NF) == "(:0)") print $1 }')
9 if [ "$user" = "" ];
10 then
11 logger "Could not verify user for X:"
12 logger $(who)
13 logger "Falling back to XUSER: $XUSER"
14 user="$XUSER"
15 else
16 logger "Found X session user: $user"
18 XAUTHORITY=/home/$user/.Xauthority
19 [ -f $XAUTHORITY ] && export XAUTHORITY
20 else
21 logger "X not probably running, lets launch the command anyway"
22 user="$XUSER"
23 XAUTHORITY=/home/$user/.Xauthority
24 [ -f $XAUTHORITY ] && export XAUTHORITY
27 lidstate=$(cat /proc/acpi/button/lid/LID/state | awk '{print $2}' )
28 ac_state=$(cat /proc/acpi/ac_adapter/AC0/state | awk '{print $2}' )
29 logger Lid state: $lidstate
30 logger AC state: $ac_state
31 case $lidstate in
32 open)
33 # screen on
34 xset dpms force on
36 closed)
37 # screen off
38 xset dpms force off
39 if [ "$COMMAND_ON_LID_CLOSE" == "yes" ];
40 then
41 case $ac_state in
42 on-line)
43 # AC adapter plugged in
44 ($ON_AC_LID_CLOSE_ACTION &)
46 off-line)
47 # Battery powered
48 ($ON_BATTERY_LID_CLOSE_ACTION &)
50 esac
52 # if both AC/BATTERY-variables are unset and SUSPEND_SCRIPT is set: execute SUSPEND_SCRIPT
53 # This is for backward compatibility.
54 if [ -z "$ON_AC_LID_CLOSE_ACTION" ] && [ -z "$ON_BATTERY_LID_CLOSE_ACTION" ] && [ -n "$SUSPEND_SCRIPT" ];
55 then
56 ($SUSPEND_SCRIPT &)
61 logger "Unknown lid state"
63 esac
65 exit 0