Added dbus config
[gregoa/zavai.git] / src / input.vala
index 7eeb9a8d2a05e5289e03d758953416d4e2a2442e..8527ac101b3a6f97320bea22d402bd9742b97631 100644 (file)
@@ -48,14 +48,19 @@ public abstract class DevInput : zavai.Service
     {
                if (condition != IOCondition.IN) return true;
 
-        stderr.printf("GOT INPUT ON %s %d\n", device, source.unix_get_fd());
+        //stderr.printf("GOT INPUT ON %s %d\n", device, source.unix_get_fd());
         char[] buf = new char[sizeof(LinuxInput.Event)];
                size_t count_read;
-               source.read_chars(buf, out count_read);
-        stderr.printf("READ %zu chars\n", count_read);
+               try {
+                       source.read_chars(buf, out count_read);
+               } catch (Error e) {
+                       zavai.log.error("Reading from " + device + ": " + e.message);
+                       return true;
+               }
+        //stderr.printf("READ %zu chars\n", count_read);
 
                LinuxInput.Event* ie = (LinuxInput.Event*)buf;
-        stderr.printf("INPUT EVENT time %lu.%lu type %hu code %hu val %d\n", (ulong)ie->time.tv_sec, ie->time.tv_usec, ie->type, ie->code, ie->val);
+        //stderr.printf("INPUT EVENT time %lu.%lu type %hu code %hu val %d\n", (ulong)ie->time.tv_sec, ie->time.tv_usec, ie->type, ie->code, ie->val);
 
         /*
         ts1, ts2, type, code, value = struct.unpack("LLHHI", buf)
@@ -92,7 +97,11 @@ public abstract class DevInput : zavai.Service
         // Open the device and listed to it using the GObject main loop
                zavai.log.info("Opening device " + device);
         fd = new IOChannel.file(device, "r");
-               fd.set_encoding(null);
+               try {
+                       fd.set_encoding(null);
+               } catch (Error e) {
+                       zavai.log.error("Setting encoding to null on " + device + ": " + e.message);
+               }
                fd.set_buffered(false);
         fd_watch = fd.add_watch(IOCondition.IN, on_input_data);
 
@@ -127,7 +136,6 @@ public class PowerButton : DevInput
         device = "/dev/input/event0";
 
                event += on_event;
-               power_button += on_power_button;
     }
 
        protected bool on_event(LinuxInput.Event* ev)
@@ -139,14 +147,6 @@ public class PowerButton : DevInput
                }
                return true;
        }
-
-       protected void on_power_button(Posix.timeval* time, bool pressed)
-       {
-               if (!pressed)
-               {
-                       zavai.app.push_applet("menu.power");
-               }
-       }
 }
 
 /*
@@ -289,32 +289,6 @@ class Audio:
         if res != 0:
             raise RuntimeError("Setting mixer failed")
 */
-public class CommandButton : Gtk.Button
-{
-       private string command;
-
-       public CommandButton(string name, string command)
-       {
-               label = name;
-               this.command = command;
-               clicked += on_clicked;
-               set_size_request(0, zavai.config.min_button_height);
-       }
-
-       public void on_clicked()
-       {
-               zavai.log.info("Run program: " + command);
-               string[] args = command.split(" ");
-               Pid pid;
-               Process.spawn_async(
-                       Environment.get_home_dir(),
-                       args,
-                       null,
-                       SpawnFlags.SEARCH_PATH,
-                       null,
-                       out pid);
-       }
-}
 
 
 public PowerButton power_button = null;
@@ -326,17 +300,5 @@ public void init()
        zavai.registry.register_service(power_button);
 }
 
-public void ui_init()
-{
-    // Menus
-    var menu_power = new zavai.Menu("Power menu");
-       menu_power.add_widget(new CommandButton("Suspend", "apm -s"));
-       menu_power.add_widget(new CommandButton("Shutdown", "shutdown -h now"));
-       menu_power.add_widget(new CommandButton("Reboot", "shutdown -r now"));
-    zavai.registry.register_menu("menu.power", menu_power);
-
-    zavai.registry.getmenu("menu.main").add_applet("menu.power");
-}
-
 }
 }