Added battery icon
[gregoa/zavai.git] / src / app.vala
index 05e81667bcfa250b6a7ee5da9e33d30a017712ea..43802f3e92bbef28f7f6abaad0bc3abbeb2339e1 100644 (file)
@@ -24,6 +24,9 @@ namespace zavai {
 
 public class Zavai : Gtk.Window, zavai.Resource
 {
+       public bool visibility = true;
+       public signal void visibility_changed(bool visible);
+
        zavai.Applet current;
        string current_name;
 
@@ -33,6 +36,45 @@ public class Zavai : Gtk.Window, zavai.Resource
                current = null;
                current_name = null;
                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.DESKTOP);
+       }
+
+       private bool on_visibility(Gdk.Event event)
+       {
+               visibility = (event.visibility.state == Gdk.VisibilityState.UNOBSCURED);
+               visibility_changed(visibility);
+               return true;
+       }
+
+       public void toggle_visibility()
+       {
+               if (visibility)
+               {
+                       visible = false;
+                       visibility = false;
+                       visibility_changed(visibility);
+                       //zavai.app.iconify();
+               } else {
+                       visible = true;
+                       present();
+                       set_skip_pager_hint(true);
+                       set_skip_taskbar_hint(true);
+               }
+       }
+
+       public void ensure_visible()
+       {
+               if (!visibility)
+               {
+                       visible = true;
+                       present();
+                       set_skip_pager_hint(true);
+                       set_skip_taskbar_hint(true);
+               }
        }
 
        public void show_applet(string name)
@@ -58,6 +100,10 @@ public class Zavai : Gtk.Window, zavai.Resource
 
        public void push_applet(string name)
        {
+               // Make the function idempotent
+               if (current_name == name)
+                       return;
+
 stderr.printf("push applet %s -> %s\n", current_name, name);
                zavai.Applet applet = zavai.registry.geta(name);