Second attempt at a togglable power menu
authorEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 11:11:08 +0000 (12:11 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 11:11:08 +0000 (12:11 +0100)
src/app.vala
src/app_power.vala

index 2e4af1c5e462e1c2714e9951f6396ece3a98bb12..47f0af952c48c8184059098d425fcfb9e984977e 100644 (file)
@@ -28,7 +28,7 @@ public class Zavai : Gtk.Window, zavai.Resource
        public signal void visibility_changed(bool visible);
 
        zavai.Applet current;
-       public string current_name;
+       string current_name;
 
        public Zavai()
        {
index 04d71116027b5932695aee395bc9a5603930b881..9b49356b4b3b1bbc16b75ec7f9299143f97e5779 100644 (file)
@@ -91,26 +91,13 @@ public class Power : zavai.Resource, Object
                {
                        if (screen_locked)
                        {
-                               // TODO: short press: turn on backlight for a sec
+                               // TODO: short press: turn on backlight for a bit
                                // TODO: long press: unlock
                                set_screen_lock(false);
                        }
                        else
                        {
-                               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();
-                               }
+                               power_menu.toggle();
                        }
                }
        }
@@ -283,8 +270,60 @@ public class Backlight: zavai.Service
        }
 }
 
+public class PowerMenu : zavai.Resource, Gtk.Window
+{
+       protected Gtk.VBox vbox;
+       protected ScreenLockButton act_screen_lock;
+       protected SuspendButton act_suspend;
+       protected ShutdownButton act_shutdown;
+       protected RebootButton act_reboot;
+       protected ServiceRequestLink act_backlight_on;
+
+       public PowerMenu()
+       {
+               type = Gtk.WindowType.POPUP;
+               title = "Power Menu";
+
+               vbox = new Gtk.VBox(true, 0);
+               add(vbox);
+
+               //destroy += Gtk.main_quit;
+               //set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
+               //visibility_notify_event += on_visibility;
+               set_skip_pager_hint(true);
+               set_skip_taskbar_hint(true);
+               set_type_hint(Gdk.WindowTypeHint.POPUP_MENU);
+
+               act_screen_lock = new ScreenLockButton();
+               vbox.pack_start(act_screen_lock, false, false, 0);
+
+               act_suspend = new SuspendButton();
+               vbox.pack_start(act_suspend, false, false, 0);
+
+               act_shutdown = new ShutdownButton();
+               vbox.pack_start(act_shutdown, false, false, 0);
+
+               act_reboot = new RebootButton();
+               vbox.pack_start(act_reboot, false, false, 0);
+
+               act_backlight_on = new ServiceRequestLink("backlight", "Keep backlight on", "Let backlight fade");
+               vbox.pack_start(act_backlight_on, false, false, 0);
+       }
+
+       public void toggle()
+       {
+               // TODO: do more in case it is visible but has no visibility (is covered by others)
+               visible = !visible;
+               if (visible)
+                       present();
+       }
+
+       public void shutdown() {}
+}
+
 
 Power power;
+PowerMenu power_menu;
 BatteryIcon battery_icon;
 Backlight backlight;
 
@@ -297,16 +336,9 @@ public void init()
        battery_icon = new BatteryIcon();
        battery_icon.set_visible(true);
 
-    // Menus
-    var menu_power = new zavai.Menu("Power menu");
-       menu_power.add_widget(new ScreenLockButton());
-       menu_power.add_widget(new SuspendButton());
-       menu_power.add_widget(new ShutdownButton());
-       menu_power.add_widget(new RebootButton());
-    menu_power.add_service_toggle("backlight", "Keep backlight on", "Let backlight fade");
-    zavai.registry.register_menu("menu.power", menu_power);
-
-
+       power_menu = new PowerMenu();
+       zavai.registry.register_resource("powermenu", power_menu);
+       
     //zavai.registry.getmenu("menu.main").add_applet("menu.power");
 
     /*