Keyboard icon gives feedback on screen lock
[gregoa/zavai.git] / src / app_power.vala
index 98d351ab4937471e4935d856ad74d346c198dcf2..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;
        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;
 
+       public signal void screen_lock_changed(bool state);
+
        public Power()
        {
                screen_locked = false;
                screen_lock_fd = -1;
                hide_after_closing_power_menu = false;
        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",
 
                usage = zavai.registry.sbus.get_object(
                        "org.freesmartphone.ousaged",
@@ -83,22 +89,33 @@ public class Power : zavai.Resource, Object
                        Posix.close(screen_lock_fd);
                }
                screen_locked = locked;
                        Posix.close(screen_lock_fd);
                }
                screen_locked = locked;
+
+               screen_lock_changed(locked);
        }
 
        }
 
-       private void on_power_button(Posix.timeval* time, 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)
                        {
                        if (screen_locked)
                        {
-                               // TODO: short press: turn on backlight for a bit
-                               // TODO: long press: unlock
-                               set_screen_lock(false);
+                               time_t now = new time_t();
+                               if (now < last_down + 2)
+                               {
+                                       // Short press: turn on backlight for a bit
+                                       backlight.wiggle();
+                               } else {
+                                       // Long press: unlock
+                                       set_screen_lock(false);
+                               }
                        }
                        else
                        {
                                power_menu.toggle();
                        }
                        }
                        else
                        {
                                power_menu.toggle();
                        }
+                       last_down = 0;
                }
        }
 }
                }
        }
 }
@@ -245,6 +262,14 @@ public class Backlight: zavai.Service
                        "org.freesmartphone.Usage");
        }
 
                        "org.freesmartphone.Usage");
        }
 
+       // Turn the backlight and then let it fade off
+       public void wiggle()
+       {
+               // There must be a better method
+               usage.RequestResource("Display");
+               usage.ReleaseResource("Display");
+       }
+
        /// Request GPS resource
        public override void start()
        {
        /// Request GPS resource
        public override void start()
        {