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;
47 string[] args = { script, null };
51 Gdk.Screen.get_default(),
55 SpawnFlags.SEARCH_PATH | SpawnFlags.STDOUT_TO_DEV_NULL | SpawnFlags.STDERR_TO_DEV_NULL,
59 ChildWatch.add(pid, on_child_quit);
62 log.error("Running " + zavai.config.homedir + "/keyboard: " + e.message);
67 protected override void stop()
71 Posix.kill((int)pid, 15);
78 public class KeyboardIcon : Gtk.StatusIcon
80 bool requested = false;
84 activate += on_activate;
85 zavai.ui.power.power.screen_lock_changed += on_screen_lock_changed;
90 private void on_activate()
92 requested = !requested;
95 keyboard.request("keyboardicon");
97 keyboard.release("keyboardicon");
100 protected void on_screen_lock_changed(bool val)
105 protected void update_icon()
107 string name = zavai.config.icondir + "/";
108 if (zavai.ui.power.power.screen_locked)
109 name += "screen_lock.png";
111 name += (requested ? "kbd_on.png" : "kbd_off.png");
112 stderr.printf("load icon from %s\n", name);
123 if (zavai.config.profile != "laptop")
125 keyboard = new Keyboard();
126 icon = new KeyboardIcon();
127 icon.set_visible(true);