Added the power menu
authorEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 20:37:28 +0000 (21:37 +0100)
committerEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 20:37:28 +0000 (21:37 +0100)
src/input.vala
src/zavai.vala

index 81a07b24112cbb8f976cffb5097074bf88bb649b..a49223e76c8b01393ea71a263d1f6197b25e8816 100644 (file)
@@ -115,7 +115,7 @@ public abstract class DevInput : zavai.Service
 
 public class PowerButton : DevInput
 {
-       public signal void power_button(bool pressed);
+       public signal void power_button(Posix.timeval* time, bool pressed);
 
     public PowerButton()
     {
@@ -126,6 +126,7 @@ public class PowerButton : DevInput
         device = "/dev/input/event0";
 
                event += on_event;
+               power_button += on_power_button;
     }
 
        protected bool on_event(LinuxInput.Event* ev)
@@ -133,10 +134,18 @@ public class PowerButton : DevInput
                if (ev->type == LinuxInput.Type.KEY && 
                        ev->code == LinuxInput.Key.POWER)
                {
-                       power_button(ev->val == 0 ? false : true);
+                       power_button(&(ev->time), ev->val == 0 ? false : true);
                }
                return true;
        }
+
+       protected void on_power_button(Posix.timeval* time, bool pressed)
+       {
+               if (!pressed)
+               {
+                       zavai.app.push_applet("menu.power");
+               }
+       }
 }
 
 /*
@@ -279,6 +288,33 @@ class Audio:
         if res != 0:
             raise RuntimeError("Setting mixer failed")
 */
+public class CommandButton : Gtk.Button
+{
+       private string command;
+
+       public CommandButton(string name, string command)
+       {
+               label = name;
+               this.command = command;
+               clicked += on_clicked;
+               set_size_request(0, zavai.config.min_button_height);
+       }
+
+       public void on_clicked()
+       {
+               zavai.log.info("Run program: " + command);
+               string[] args = command.split(" ");
+               Pid pid;
+               Process.spawn_async(
+                       Environment.get_home_dir(),
+                       args,
+                       null,
+                       SpawnFlags.SEARCH_PATH,
+                       null,
+                       out pid);
+       }
+}
+
 
 public PowerButton power_button = null;
 
@@ -289,5 +325,17 @@ public void init()
        zavai.registry.register_service(power_button);
 }
 
+public void ui_init()
+{
+    // Menus
+    var menu_power = new zavai.Menu("Power menu");
+       menu_power.add_widget(new CommandButton("Suspend", "apm -s"));
+       menu_power.add_widget(new CommandButton("Shutdown", "shutdown -h now"));
+       menu_power.add_widget(new CommandButton("Reboot", "shutdown -r now"));
+    zavai.registry.register_menu("menu.power", menu_power);
+
+    zavai.registry.getmenu("menu.main").add_applet("menu.power");
+}
+
 }
 }
index c11b2065214be7bb8cb091fe5ab4ae4af947c2b5..a8719050d6937f2cb2cf9adccc111467670295ac 100644 (file)
@@ -68,6 +68,7 @@ static int main (string[] args) {
        zavai.ui.kbd.init();
        zavai.ui.wm.init();
        zavai.ui.powerbutton.init();
+       zavai.input.ui_init();
        zavai.ui.debug.init();
 
        zavai.app.show_applet("menu.main");