2 * app_wm - zavai window management functions
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 class GPSOn(gtk.ToggleAction):
29 states = [_("GPS always on"), _("GPS on when needed")]
31 def __init__(self, registry, **kw):
33 super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
35 self.registry = registry
36 self.set_active(False)
38 self.connect("toggled", self.on_toggle)
40 def on_toggle(self, *args):
41 self.state = (self.state + 1) % len(self.states)
42 self.set_property("label", self.states[self.state])
49 self.registry.resource("gps").connect("gps", self)
52 self.registry.resource("gps").disconnect("gps", self)
54 class GPXTracer(gtk.ToggleAction):
55 states = [_("Start GPX trace"), _("Stop GPX trace")]
57 def __init__(self, registry, **kw):
59 super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
61 self.registry = registry
62 self.set_active(False)
64 self.connect("toggled", self.on_toggle)
66 def on_toggle(self, *args):
67 self.state = (self.state + 1) % len(self.states)
68 self.set_property("label", self.states[self.state])
75 zavai.info("GPX trace started")
76 self.registry.resource("gpx").connect("gpx", self)
79 zavai.info("GPX trace ended")
80 self.registry.resource("gpx").disconnect("gpx", self)
84 class GPXAudioTracer(gtk.ToggleAction):
85 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
87 def __init__(self, registry, **kw):
89 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
91 self.registry = registry
92 self.recorder = zavai.Recorder(registry)
93 self.set_active(False)
95 self.connect("toggled", self.on_toggle)
99 super(GPXAudioTracer, self).shutdown()
101 def on_toggle(self, *args):
102 self.state = (self.state + 1) % len(self.states)
103 self.set_property("label", self.states[self.state])
104 if self.get_active():
110 zavai.info("GPX trace started")
111 gpx = self.registry.resource("gpx")
112 gpx.connect("gpx", self)
113 gpx.add_activity_monitor(self.on_gpx_activity_changed)
116 zavai.info("GPX trace ended")
117 gpx = self.registry.resource("gpx")
118 gpx.disconnect("gpx", self)
120 gpx.del_activity_monitor(self.on_gpx_activity_changed)
122 def on_gpx_activity_changed(self, gpx, state):
124 self.recorder.start(gpx.basename + ".wav")
129 static void print_window_state(Gtk.Window w)
131 Gdk.WindowState state = w.window.get_state();
132 int istate = (int) state;
133 bool is_icon = (state & Gdk.WindowState.ICONIFIED) != 0;
134 bool is_visible = w.visible;
135 bool is_focus = w.is_focus;
136 bool has_focus = ((Gtk.Widget)w).has_focus;
137 bool is_active = w.is_active;
138 bool is_toplevel = w.is_toplevel();
139 bool is_tfocus = w.has_toplevel_focus;
141 stderr.printf("istate: %d; is_icon: %s; is_visible: %s; is_focus: %s; has_focus: %s, is_active: %s; is_toplevel: %s; is_tfocus: %s\n",
143 is_icon ? "true" : "false",
144 is_visible ? "true" : "false",
145 is_focus ? "true" : "false",
146 has_focus ? "true" : "false",
147 is_active ? "true" : "false",
148 is_toplevel ? "true" : "false",
149 is_tfocus ? "true" : "false"
153 public class RaiseIcon : Gtk.StatusIcon
156 public bool on_focus_in (Gdk.EventFocus event)
158 stderr.printf("FOCUS IN %c %d\n", event.send_event, event.in);
162 public bool on_focus_out (Gdk.EventFocus event)
164 stderr.printf("FOCUS OUT %c %d\n", event.send_event, event.in);
172 activate += on_activate;
173 zavai.app.visibility_changed += on_visibility_changed;
175 zavai.app.focus_in_event += on_focus_in;
176 zavai.app.focus_out_event += on_focus_out;
182 private void on_visibility_changed(bool visible)
187 private void on_activate()
189 zavai.app.toggle_visibility();
194 protected void update_icon()
196 string name = zavai.config.icondir + "/";
197 if (!zavai.app.visibility)
198 name += "kbd_on.png";
200 name += "kbd_off.png";
205 public class Test : BigButton
209 set_label("Window state");
210 clicked += on_clicked;
213 protected void on_clicked()
215 print_window_state(zavai.app);
221 public class Waypoint : BigButton
225 set_label("Take waypoint");
226 zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
227 clicked += on_clicked;
228 set_sensitive(zavai.gps.gpx.tracking);
231 protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
233 stderr.printf("Toggled %d\n", (int)new_state);
234 set_sensitive(new_state);
237 protected void on_clicked()
239 stderr.printf("Activate\n");
240 zavai.gps.gpx.waypoint();
246 public class GPSRequestLink : Gtk.ToggleButton
248 public GPSRequestLink()
251 status_icon = new Gtk.StatusIcon();
252 status_icon.set_visible(true);
253 status_icon.activate += on_status_activate;
257 private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
259 this.fix_status = fix_status;
263 private void on_toggled(Gtk.Button src)
265 Service s = zavai.registry.gets(service_name);
267 s.request("servicerequestlink");
269 s.release("servicerequestlink");
270 set_label(get_active() ? label_stop : label_start);
274 private void on_status_activate()
276 set_active(!get_active());
281 RaiseIcon raise_icon;
285 raise_icon = new RaiseIcon();
286 raise_icon.set_visible(true);
288 var menu_test = new Test();
289 zavai.registry.getmenu("menu.main").add_widget(menu_test);