op_power: make sure powersave is off when turning on display
authorGrazvydas Ignotas <notasas@gmail.com>
Fri, 24 Aug 2012 21:39:23 +0000 (00:39 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Fri, 24 Aug 2012 21:39:23 +0000 (00:39 +0300)
recipes/pandora-system/pandora-scripts/op_power.sh

index 85843d8..35e01cf 100644 (file)
@@ -109,6 +109,7 @@ lowPowerOn(){ #switch from normal to lowpower mode
 lowPowerOff(){ # switch from lowpower to normal mode
        oldspeed=$(cat /tmp/oldspeed)
        /usr/pandora/scripts/op_cpuspeed.sh -n $oldspeed
+       rm -f /tmp/oldspeed
 
        display_on
        resume_net
@@ -121,6 +122,18 @@ lowPowerOff(){ # switch from lowpower to normal mode
        echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
 }
 
+display_on_with_checks() {
+       # after turning on the display, we don't want lowpower state
+       # (which could be active because of some races)
+       if [ "$powerstate" = "buttonlowpower" -o "$powerstate" = "lidlowpower" -o \
+            -e /tmp/oldspeed ]
+       then
+               lowPowerOff
+       else
+               display_on
+       fi
+}
+
 show_message() {
        # TODO: check if desktop is visible; maybe use layer3?
        xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
@@ -277,7 +290,7 @@ elif [[ "$2" == "lid" ]]; then
                                        powerstate="on"
                                ;;
                                *)
-                                       (debug && echo "display_on") || display_on
+                                       (debug && echo "display_on") || display_on_with_checks
                                        powerstate="on"
                                ;;
                        esac
@@ -305,7 +318,8 @@ elif [[ "$2" == "screensaver" ]]; then
        unset DISPLAY
 
        if [[ "$1" == 0 ]]; then # deactivate screensaver
-               display_on
+               display_on_with_checks
+               powerstate="on"
        elif [[ "$1" == 1 ]]; then # activate screensaver
                display_off
        fi