2 * app_keyboard - zavai keyboard show/hide 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
27 public class Keyboard : Service
33 Object(name: "keyboard");
36 private void on_child_quit(Pid pid, int status)
38 Process.close_pid(pid);
43 protected override void start()
45 string script = zavai.config.find_script("keyboard");
46 if (script == null) return;
48 string[] args = { script, null };
52 Gdk.Screen.get_default(),
56 SpawnFlags.SEARCH_PATH | SpawnFlags.STDOUT_TO_DEV_NULL | SpawnFlags.STDERR_TO_DEV_NULL,
60 ChildWatch.add(pid, on_child_quit);
63 log.error("Running " + zavai.config.homedir + "/keyboard: " + e.message);
68 protected override void stop()
72 Posix.kill((int)pid, 15);
79 public class KeyboardIcon : Gtk.StatusIcon
81 bool requested = false;
85 activate += on_activate;
86 zavai.ui.power.power.screen_lock_changed += on_screen_lock_changed;
91 private void on_activate()
93 requested = !requested;
96 keyboard.request("keyboardicon");
98 keyboard.release("keyboardicon");
101 protected void on_screen_lock_changed(bool val)
106 protected void update_icon()
108 string name = zavai.config.icondir + "/";
109 if (zavai.ui.power.power.screen_locked)
110 name += "screen_lock.png";
112 name += (requested ? "kbd_on.png" : "kbd_off.png");
113 stderr.printf("load icon from %s\n", name);
119 public class GPSRequestLink : Gtk.ToggleButton
121 public GPSRequestLink()
124 status_icon = new Gtk.StatusIcon();
125 status_icon.set_visible(true);
126 status_icon.activate += on_status_activate;
130 private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
132 this.fix_status = fix_status;
136 private void on_toggled(Gtk.Button src)
138 Service s = zavai.registry.gets(service_name);
140 s.request("servicerequestlink");
142 s.release("servicerequestlink");
143 set_label(get_active() ? label_stop : label_start);
147 private void on_status_activate()
149 set_active(!get_active());
159 if (zavai.config.profile != "laptop")
161 keyboard = new Keyboard();
162 icon = new KeyboardIcon();
163 icon.set_visible(true);