Lock screen on long power press
authorEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 17:40:09 +0000 (18:40 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 17:40:09 +0000 (18:40 +0100)
src/app_power.vala

index f3affe700d2280ec2d1e34a3da2134fb8bd76cb2..cddcb4f0b100a1d55095fc66df35ca063ab8cf71 100644 (file)
@@ -101,21 +101,25 @@ public class Power : zavai.Resource, Object
                {
                        last_down = t->tv_sec;
                } else {
+                       time_t now = new time_t();
+                       bool short_press = now < last_down + 2;
                        if (screen_locked)
                        {
-                               time_t now = new time_t();
-                               if (now < last_down + 2)
-                               {
+                               if (short_press)
                                        // Short press: turn on backlight for a bit
                                        backlight.wiggle();
-                               } else {
+                               else
                                        // Long press: unlock
                                        set_screen_lock(false);
-                               }
                        }
                        else
                        {
-                               power_menu.toggle();
+                               if (short_press)
+                                       // Short press: toggle power menu
+                                       power_menu.toggle();
+                               else
+                                       // Long press: lock screen
+                                       set_screen_lock(true);
                        }
                        last_down = 0;
                }