op_lidsettings: Added new tool to change what happens when you close the lid (submitt...
authorMichael Mrozek <EvilDragon@openpandora.de>
Tue, 21 Jun 2011 22:26:51 +0000 (00:26 +0200)
committerMichael Mrozek <EvilDragon@openpandora.de>
Tue, 21 Jun 2011 22:26:51 +0000 (00:26 +0200)
recipes/pandora-system/pandora-scripts/op_lid.sh
recipes/pandora-system/pandora-scripts/op_lidsettings.pnd [new file with mode: 0644]
recipes/pandora-system/pandora-scripts/op_lidsettings.sh [new file with mode: 0644]
recipes/pandora-system/pandora-scripts/op_power.sh

index 757abcd..544676b 100644 (file)
@@ -3,29 +3,49 @@
 #only argument is 0 for open 1 for closed
 #may also be called after inactivity, like X DPMS
 
-if [ ! -e /tmp/powerstate ]; then #do nothing when in powersave mode
-  if [ "$1" = "1" ]; then #lid was closed
-    brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
-    if [ $brightness -gt 0 ]; then
-      echo $brightness > /tmp/oldbright
-    fi
-    echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
-    #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
-  elif [ "$1" = "0" ]; then # lid was opened
-    #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
-    #sleep 0.1s # looks cleaner, could flicker without
-    maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
-    oldbright=0
-    if [ -f /tmp/oldbright ]; then
-      oldbright=$(cat /tmp/oldbright)
-    fi
-    if [ $oldbright -eq 0 ]; then
-      oldbright=$(cat /etc/pandora/conf/brightness.state)
-    fi
-     if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then 
-      /usr/pandora/scripts/op_bright.sh $oldbright 
-     else
-      /usr/pandora/scripts/op_bright.sh $maxbright
-     fi
-  fi
-fi
+config=$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate)
+
+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 
+       if [ "$1" = "1" ]; then #lid was closed
+               case "$config" in
+                       "shutdown")
+                               /usr/pandora/scripts/op_power.sh 5
+                       ;;
+                       "lowpower")
+                               /usr/pandora/scripts/op_power.sh 1
+                               echo "2" > /tmp/powerstate
+                       ;;
+                       *)
+                               echo "$config"
+                               brightness=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness)
+                               if [ $brightness -gt 0 ]; then
+                                       echo $brightness > /tmp/oldbright
+                               fi
+                               echo 0 > /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/brightness
+                               #echo 1 > /sys/devices/platform/omapfb/graphics/fb0/blank
+                       esac
+       elif [ "$1" = "0" ]; then # lid was opened
+               case "$config" in
+                       "lowpower")
+                               /usr/pandora/scripts/op_power.sh 1
+                       ;;
+                       *)
+                               #echo 0 > /sys/devices/platform/omapfb/graphics/fb0/blank
+                               #sleep 0.1s # looks cleaner, could flicker without
+                               maxbright=$(cat /sys/devices/platform/twl4030-pwm0-bl/backlight/twl4030-pwm0-bl/max_brightness)
+                               oldbright=0
+                               if [ -f /tmp/oldbright ]; then
+                                       oldbright=$(cat /tmp/oldbright)
+                               fi
+                               if [ $oldbright -eq 0 ]; then
+                                       oldbright=$(cat /etc/pandora/conf/brightness.state)
+                               fi
+                               if [ $oldbright -ge 3 ] && [ $oldbright -le $maxbright ]; then 
+                                       /usr/pandora/scripts/op_bright.sh $oldbright 
+                               else
+                                       /usr/pandora/scripts/op_bright.sh $maxbright
+                               fi
+                       ;;
+               esac
+       fi
+fi
\ No newline at end of file
diff --git a/recipes/pandora-system/pandora-scripts/op_lidsettings.pnd b/recipes/pandora-system/pandora-scripts/op_lidsettings.pnd
new file mode 100644 (file)
index 0000000..878ef70
Binary files /dev/null and b/recipes/pandora-system/pandora-scripts/op_lidsettings.pnd differ
diff --git a/recipes/pandora-system/pandora-scripts/op_lidsettings.sh b/recipes/pandora-system/pandora-scripts/op_lidsettings.sh
new file mode 100644 (file)
index 0000000..c52adcd
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+# change what to do when the lid is closed/opened
+case "$(cat $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate)" in
+       "lowpower")
+               current="the Pandora goes into low power mode"
+       ;;
+       "shutdown")
+               current="the Pandora is shut down"      
+       ;;
+       *)
+               current="the screen is turned off"
+       ;;
+esac
+
+sel=$(zenity --title="Lid settings" --height=230 --list --column "id" --column "Please select" --hide-column=1 --text="What should happen when you close the Pandora's lid?\nAt the moment $current when you close the lid." "brightness" "Turn off the screen." "lowpower" "Go into low power mode (same as when pressing the
+power button for less than 3 seconds)" "shutdown" "Shut the pandora down.") || exit
+echo "$sel" > $(grep /etc/passwd -e $(ps u -C xfce4-session | tail -n1 | awk '{print $1}')| cut -f 6 -d ":")/.lidstate 
index bc87602..42b92ef 100644 (file)
@@ -8,7 +8,7 @@ if [ "$1" -le "2" ]; then # button was pressed 1-2sec, "suspend"
   else
     powerstate=0
   fi
-  if [ $powerstate -eq "1" ]; then
+  if [ $powerstate -ne 0 ]; then
     #switch from lowpower to normal mode
     oldspeed=$(cat /tmp/oldspeed)
     /usr/pandora/scripts/op_cpuspeed.sh $oldspeed