First attempt at hiding power menu if power button is pressed again
authorEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 10:44:34 +0000 (11:44 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 10:44:34 +0000 (11:44 +0100)
src/app.vala
src/app_power.vala

index 2478d2bac4e5d1b576eb03c06d3423e98162d8eb..2e4af1c5e462e1c2714e9951f6396ece3a98bb12 100644 (file)
@@ -28,7 +28,7 @@ public class Zavai : Gtk.Window, zavai.Resource
        public signal void visibility_changed(bool visible);
 
        zavai.Applet current;
-       string current_name;
+       public string current_name;
 
        public Zavai()
        {
@@ -66,6 +66,13 @@ public class Zavai : Gtk.Window, zavai.Resource
                }
        }
 
+       public void hide()
+       {
+               visible = false;
+               visibility = false;
+               visibility_changed(visibility);
+       }
+
        public void ensure_visible()
        {
                if (!visibility)
index 70eb57e117c6917b0a09b069f5d3b72e865bfa7e..04d71116027b5932695aee395bc9a5603930b881 100644 (file)
@@ -30,10 +30,13 @@ public class Power : zavai.Resource, Object
        public bool screen_locked;
        private int screen_lock_fd;
 
+       private bool hide_after_closing_power_menu;
+
        public Power()
        {
                screen_locked = false;
                screen_lock_fd = -1;
+               hide_after_closing_power_menu = false;
 
                usage = zavai.registry.sbus.get_object(
                        "org.freesmartphone.ousaged",
@@ -87,11 +90,27 @@ public class Power : zavai.Resource, Object
                if (!pressed)
                {
                        if (screen_locked)
+                       {
+                               // TODO: short press: turn on backlight for a sec
+                               // TODO: long press: unlock
                                set_screen_lock(false);
+                       }
                        else
                        {
-                               zavai.app.push_applet("menu.power");
-                               zavai.app.ensure_visible();
+                               if (zavai.app.current_name == "menu.power" && zavai.app.visibility)
+                               {
+                                       // Hide or back
+                                       zavai.app.back();
+                                       if (hide_after_closing_power_menu)
+                                               zavai.app.hide();
+                               } else if (zavai.app.current_name == "menu.power") {
+                                       // Unhide
+                                       zavai.app.ensure_visible();
+                               } else {
+                                       zavai.app.push_applet("menu.power");
+                                       hide_after_closing_power_menu = !zavai.app.visibility;
+                                       zavai.app.ensure_visible();
+                               }
                        }
                }
        }