]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/app_keyboard.vala
Use find_and_run_script more thoroughly
[gregoa/zavai.git] / src / app_keyboard.vala
index 794bf01c9e02bbfa70d7901503839d3e06f2dbd0..18efc2b70f47b8ea72b0616bfec5a8819f0e9ef9 100644 (file)
@@ -26,103 +26,106 @@ namespace kbd {
 
 public class Keyboard : Service
 {
-       protected Pid pid;
-
-       public Keyboard()
-       {
-               name = "keyboard";
-       }
-
-       private void on_child_quit(Pid pid, int status)
-       {
-               Process.close_pid(pid);
-               pid = (Pid)0;
-               stop();
-       }
-
-       protected override void start()
-       {
-               string[] args = { zavai.config.homedir + "/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 " + zavai.config.homedir + "/keyboard: " + e.message);
-                       pid = (Pid)0;
-               }
-       }
-
-       protected override void stop()
-       {
-               if ((int)pid != 0)
-               {
-                       Posix.kill((int)pid, 15);
-                       pid = (Pid)0;
-               }
-               base.stop();
-       }
+    protected Pid pid;
+
+    public Keyboard()
+    {
+        Object(name: "keyboard");
+    }
+
+    private void on_child_quit(Pid pid, int status)
+    {
+        Process.close_pid(pid);
+        pid = (Pid)0;
+        stop();
+    }
+
+    protected override void start()
+    {
+        string script = zavai.config.find_script("keyboard");
+        if (script == null) return;
+
+        string[] args = { script, 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 " + zavai.config.homedir + "/keyboard: " + e.message);
+            pid = (Pid)0;
+        }
+    }
+
+    protected override void stop()
+    {
+        if ((int)pid != 0)
+        {
+            Posix.kill((int)pid, 15);
+            pid = (Pid)0;
+        }
+        base.stop();
+    }
 }
 
 public class KeyboardIcon : Gtk.StatusIcon
 {
-       bool requested = false;
+    bool requested = false;
 
-       public KeyboardIcon()
-       {
-               activate += on_activate;
+    public KeyboardIcon()
+    {
+        activate += on_activate;
         zavai.ui.power.power.screen_lock_changed += on_screen_lock_changed;
 
-               update_icon();
-       }
+        update_icon();
+    }
 
-       private void on_activate()
-       {
-               requested = !requested;
-               update_icon();
-               if (requested)
-                       keyboard.request("keyboardicon");
-               else
-                       keyboard.release("keyboardicon");
-       }
+    private void on_activate()
+    {
+        requested = !requested;
+        update_icon();
+        if (requested)
+            keyboard.request("keyboardicon");
+        else
+            keyboard.release("keyboardicon");
+    }
 
     protected void on_screen_lock_changed(bool val)
     {
         update_icon();
     }
 
-       protected void update_icon()
-       {
-               string name = zavai.config.icondir + "/";
+    protected void update_icon()
+    {
+        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);
-       }
+        stderr.printf("load icon from %s\n", name);
+        set_from_file(name);
+    }
 }
 
 /*
 public class GPSRequestLink : Gtk.ToggleButton
 {
-       public GPSRequestLink()
-       {
+    public GPSRequestLink()
+    {
         // GPS status icon
         status_icon = new Gtk.StatusIcon();
         status_icon.set_visible(true);
         status_icon.activate += on_status_activate;
         update_icon();
-       }
+    }
 
     private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
     {
@@ -130,16 +133,16 @@ public class GPSRequestLink : Gtk.ToggleButton
         update_icon();
     }
 
-       private void on_toggled(Gtk.Button src)
-       {
-               Service s = zavai.registry.gets(service_name);
-               if (get_active())
-                       s.request("servicerequestlink");
-               else
-                       s.release("servicerequestlink");
-               set_label(get_active() ? label_stop : label_start);
+    private void on_toggled(Gtk.Button src)
+    {
+        Service s = zavai.registry.gets(service_name);
+        if (get_active())
+            s.request("servicerequestlink");
+        else
+            s.release("servicerequestlink");
+        set_label(get_active() ? label_stop : label_start);
         update_icon();
-       }
+    }
 
     private void on_status_activate()
     {
@@ -153,11 +156,12 @@ KeyboardIcon icon;
 
 public void init()
 {
-stderr.printf("INIT KBD\n");
-       keyboard = new Keyboard();
-       zavai.registry.register_service(keyboard);
-       icon = new KeyboardIcon();
-       icon.set_visible(true);
+    if (zavai.config.profile != "laptop")
+    {
+        keyboard = new Keyboard();
+        icon = new KeyboardIcon();
+        icon.set_visible(true);
+    }
 }
 
 }