Better attempt to detect long button down
authorEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 15:38:15 +0000 (16:38 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 15:38:15 +0000 (16:38 +0100)
src/app_power.vala

index ccf36d8a909715480ac0b1a4ab2501920c44d830..82ceaec4f973cfc9d21f85d2c544eca934991c62 100644 (file)
@@ -29,6 +29,9 @@ public class Power : zavai.Resource, Object
        public dynamic DBus.Object usage;
        public bool screen_locked;
        private int screen_lock_fd;
        public dynamic DBus.Object usage;
        public bool screen_locked;
        private int screen_lock_fd;
+       // Timestamp of the past power button pressed even (0 if the button has
+       // been released)
+       private time_t last_down;
 
        private bool hide_after_closing_power_menu;
 
 
        private bool hide_after_closing_power_menu;
 
@@ -37,6 +40,7 @@ public class Power : zavai.Resource, Object
                screen_locked = false;
                screen_lock_fd = -1;
                hide_after_closing_power_menu = false;
                screen_locked = false;
                screen_lock_fd = -1;
                hide_after_closing_power_menu = false;
+               last_down = 0;
 
                usage = zavai.registry.sbus.get_object(
                        "org.freesmartphone.ousaged",
 
                usage = zavai.registry.sbus.get_object(
                        "org.freesmartphone.ousaged",
@@ -87,12 +91,14 @@ public class Power : zavai.Resource, Object
 
        private void on_power_button(Posix.timeval* t, bool pressed)
        {
 
        private void on_power_button(Posix.timeval* t, bool pressed)
        {
-               if (!pressed)
+               if (pressed)
                {
                {
+                       last_down = t->tv_sec;
+               } else {
                        if (screen_locked)
                        {
                                time_t now = new time_t();
                        if (screen_locked)
                        {
                                time_t now = new time_t();
-                               if (now < t->tv_sec + 2)
+                               if (now < last_down + 2)
                                {
                                        // Short press: turn on backlight for a bit
                                        backlight.wiggle();
                                {
                                        // Short press: turn on backlight for a bit
                                        backlight.wiggle();
@@ -105,6 +111,7 @@ public class Power : zavai.Resource, Object
                        {
                                power_menu.toggle();
                        }
                        {
                                power_menu.toggle();
                        }
+                       last_down = 0;
                }
        }
 }
                }
        }
 }