Keyboard icon gives feedback on screen lock
authorEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 17:36:53 +0000 (18:36 +0100)
committerEnrico Zini <enrico@enricozini.org>
Sun, 16 Aug 2009 17:36:53 +0000 (18:36 +0100)
icons/screen_lock.png [new file with mode: 0644]
src/app_keyboard.vala
src/app_power.vala

diff --git a/icons/screen_lock.png b/icons/screen_lock.png
new file mode 100644 (file)
index 0000000..deea728
Binary files /dev/null and b/icons/screen_lock.png differ
index ad2e69356febcb58de88a778549fad60f156bced..b67e44e636972ed1fab3eae9e07d75878fed0457 100644 (file)
@@ -73,129 +73,6 @@ public class Keyboard : Service
        }
 }
 
-/*
-class GPSOn(gtk.ToggleAction):
-    states = [_("GPS always on"), _("GPS on when needed")]
-
-    def __init__(self, registry, **kw):
-        self.state = 0
-        super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
-
-        self.registry = registry
-        self.set_active(False)
-
-        self.connect("toggled", self.on_toggle)
-
-    def on_toggle(self, *args):
-        self.state = (self.state + 1) % len(self.states)
-        self.set_property("label", self.states[self.state])
-        if self.get_active():
-            self.start()
-        else:
-            self.stop()
-
-    def start(self):
-        self.registry.resource("gps").connect("gps", self)
-
-    def stop(self):
-        self.registry.resource("gps").disconnect("gps", self)
-
-class GPXTracer(gtk.ToggleAction):
-    states = [_("Start GPX trace"), _("Stop GPX trace")]
-
-    def __init__(self, registry, **kw):
-        self.state = 0
-        super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
-
-        self.registry = registry
-        self.set_active(False)
-
-        self.connect("toggled", self.on_toggle)
-
-    def on_toggle(self, *args):
-        self.state = (self.state + 1) % len(self.states)
-        self.set_property("label", self.states[self.state])
-        if self.get_active():
-            self.start()
-        else:
-            self.stop()
-
-    def start(self):
-        zavai.info("GPX trace started")
-        self.registry.resource("gpx").connect("gpx", self)
-
-    def stop(self):
-        zavai.info("GPX trace ended")
-        self.registry.resource("gpx").disconnect("gpx", self)
-
-public class Waypoint : BigButton
-{
-    public Waypoint()
-    {
-        set_label("Take waypoint");
-        zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
-        clicked += on_clicked;
-        set_sensitive(zavai.gps.gpx.tracking);
-    }
-
-    protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
-    {
-stderr.printf("Toggled %d\n", (int)new_state);
-        set_sensitive(new_state);
-    }
-
-    protected void on_clicked()
-    {
-stderr.printf("Activate\n");
-        zavai.gps.gpx.waypoint();
-    }
-}
-
-class GPXAudioTracer(gtk.ToggleAction):
-    states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
-
-    def __init__(self, registry, **kw):
-        self.state = 0
-        super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
-
-        self.registry = registry
-        self.recorder = zavai.Recorder(registry)
-        self.set_active(False)
-
-        self.connect("toggled", self.on_toggle)
-
-    def shutdown(self):
-        self.recorder.stop()
-        super(GPXAudioTracer, self).shutdown()
-
-    def on_toggle(self, *args):
-        self.state = (self.state + 1) % len(self.states)
-        self.set_property("label", self.states[self.state])
-        if self.get_active():
-            self.start()
-        else:
-            self.stop()
-
-    def start(self):
-        zavai.info("GPX trace started")
-        gpx = self.registry.resource("gpx")
-        gpx.connect("gpx", self)
-        gpx.add_activity_monitor(self.on_gpx_activity_changed)
-
-    def stop(self):
-        zavai.info("GPX trace ended")
-        gpx = self.registry.resource("gpx")
-        gpx.disconnect("gpx", self)
-        self.recorder.stop()
-        gpx.del_activity_monitor(self.on_gpx_activity_changed)
-
-    def on_gpx_activity_changed(self, gpx, state):
-        if state:
-            self.recorder.start(gpx.basename + ".wav")
-        else:
-            self.recorder.stop()
-*/
-
 public class KeyboardIcon : Gtk.StatusIcon
 {
        bool requested = false;
@@ -203,6 +80,8 @@ public class KeyboardIcon : Gtk.StatusIcon
        public KeyboardIcon()
        {
                activate += on_activate;
+        zavai.ui.power.power.screen_lock_changed += on_screen_lock_changed;
+
                update_icon();
        }
 
@@ -216,9 +95,18 @@ public class KeyboardIcon : Gtk.StatusIcon
                        keyboard.release("keyboardicon");
        }
 
+    protected void on_screen_lock_changed(bool val)
+    {
+        update_icon();
+    }
+
        protected void update_icon()
        {
-               string name = zavai.config.icondir + "/" + (requested ? "kbd_on.png" : "kbd_off.png");
+               string name = zavai.config.icondir + "/";
+        if (zavai.ui.power.power.screen_locked)
+            name += "screen_lock.png";
+        else
+            name += (requested ? "kbd_on.png" : "kbd_off.png");
                stderr.printf("load icon from %s\n", name);
                set_from_file(name);
        }
index 82ceaec4f973cfc9d21f85d2c544eca934991c62..f3f587b01585312271754f352d26ef58b3bcfdd4 100644 (file)
@@ -35,6 +35,8 @@ public class Power : zavai.Resource, Object
 
        private bool hide_after_closing_power_menu;
 
+       public signal void screen_lock_changed(bool state);
+
        public Power()
        {
                screen_locked = false;
@@ -87,6 +89,8 @@ public class Power : zavai.Resource, Object
                        Posix.close(screen_lock_fd);
                }
                screen_locked = locked;
+
+               screen_lock_changed(locked);
        }
 
        private void on_power_button(Posix.timeval* t, bool pressed)