Keyboard icon gives feedback on screen lock
[gregoa/zavai.git] / src / app_power.vala
index ccf36d8a909715480ac0b1a4ab2501920c44d830..f3f587b01585312271754f352d26ef58b3bcfdd4 100644 (file)
@@ -29,14 +29,20 @@ public class Power : zavai.Resource, Object
        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;
 
+       public signal void screen_lock_changed(bool state);
+
        public Power()
        {
                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",
@@ -83,16 +89,20 @@ public class Power : zavai.Resource, Object
                        Posix.close(screen_lock_fd);
                }
                screen_locked = locked;
+
+               screen_lock_changed(locked);
        }
 
        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 (now < t->tv_sec + 2)
+                               if (now < last_down + 2)
                                {
                                        // Short press: turn on backlight for a bit
                                        backlight.wiggle();
@@ -105,6 +115,7 @@ public class Power : zavai.Resource, Object
                        {
                                power_menu.toggle();
                        }
+                       last_down = 0;
                }
        }
 }