op_lidsettings: Added new tool to change what happens when you close the lid (submitt...
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_lid.sh
1 #!/bin/bash
2 #actions done when the lid is closed
3 #only argument is 0 for open 1 for closed
4 #may also be called after inactivity, like X DPMS
5
6 config=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate)
7
8 if [[ ! -e /tmp/powerstate || "$(cat /tmp/powerstate)" = "2" ]]; then #do nothing when in powersave mode unless we went into it because of a closed lid 
9         if [ "$1" = "1" ]; then #lid was closed
10                 case "$config" in
11                         "shutdown")
12                                 /usr/pandora/scripts/op_power.sh 5
13                         ;;
14                         "lowpower")
15                                 /usr/pandora/scripts/op_power.sh 1
16                                 echo "2" > /tmp/powerstate
17                         ;;
18                         *)
19                                 echo "$config"
20                                 brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
21                                 if [ $brightness -gt 0 ]; then
22                                         echo $brightness > /tmp/oldbright
23                                 fi
24                                 echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
25                                 #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
26                         esac
27         elif [ "$1" = "0" ]; then # lid was opened
28                 case "$config" in
29                         "lowpower")
30                                 /usr/pandora/scripts/op_power.sh 1
31                         ;;
32                         *)
33                                 #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
34                                 #sleep 0.1s # looks cleaner, could flicker without
35                                 maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
36                                 oldbright=0
37                                 if [ -f /tmp/oldbright ]; then
38                                         oldbright=$(cat /tmp/oldbright)
39                                 fi
40                                 if [ $oldbright -eq 0 ]; then
41                                         oldbright=$(cat /etc/pandora/conf/brightness.state)
42                                 fi
43                                 if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then 
44                                         /usr/pandora/scripts/op_bright.sh $oldbright 
45                                 else
46                                         /usr/pandora/scripts/op_bright.sh $maxbright
47                                 fi
48                         ;;
49                 esac
50         fi
51 fi