More of keyboard
[gregoa/zavai.git] / src / app_keyboard.vala
index a518c221381cb4ddbce44e799c62f542ecc254c9..790ffa1097a682b07e8f184894d9d3dde9f39d1e 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+using GLib;
+
 namespace zavai {
 namespace ui {
 namespace kbd {
 
+public class Keyboard : Service
+{
+       protected Pid pid;
+
+       private void on_child_quit(Pid pid, int status)
+       {
+               Process.close_pid(pid);
+               pid = (Pid)0;
+               stop();
+       }
+
+       protected override void start()
+       {
+               string[] args = { "/usr/bin/matchbox-keyboard", null };
+               int opid;
+               try {
+                       Gdk.spawn_on_screen(
+                               Gdk.Screen.get_default(),
+                               "/",
+                               args,
+                               null,
+                               SpawnFlags.SEARCH_PATH | SpawnFlags.STDOUT_TO_DEV_NULL | SpawnFlags.STDERR_TO_DEV_NULL,
+                               null,
+                               out opid);
+                       pid = (Pid)opid;
+                       ChildWatch.add(pid, on_child_quit);
+                       base.start();
+               } catch (Error e) {
+                       log.error("Running matchbox-keyboard: " + e.message);
+                       pid = (Pid)0;
+               }
+       }
+
+       protected override void stop()
+       {
+               if ((int)pid != 0)
+               {
+                       Posix.kill((int)pid, 15);
+                       pid = (Pid)0;
+               }
+               base.stop();
+       }
+}
+
 /*
 class GPSOn(gtk.ToggleAction):
     states = [_("GPS always on"), _("GPS on when needed")]