Access linux/input.h via a vapi file
authorEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 18:40:13 +0000 (19:40 +0100)
committerEnrico Zini <enrico@enricozini.org>
Tue, 11 Aug 2009 18:40:13 +0000 (19:40 +0100)
src/Makefile.am
src/input.vala
src/linux-input.vapi [new file with mode: 0644]

index d369317e71eee282c29556cc9f32197b33602929..0da250a8aaaf0b414760ae80ad5a701dc5ba042f 100644 (file)
@@ -1,4 +1,4 @@
-VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0
+VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input
 
 #zavai: $(SOURCES)
 #      valac -o zavai $(VFLAGS) $^
 
 #zavai: $(SOURCES)
 #      valac -o zavai $(VFLAGS) $^
@@ -42,13 +42,15 @@ zavai_VALASOURCES = \
        app_debug.vala \
        zavai.vala
 
        app_debug.vala \
        zavai.vala
 
+zavai_VAPIS = linux-input.vapi 
+
 zavai_SOURCES = \
        zavai.vala.stamp \
        $(zavai_VALASOURCES:.vala=.c) \
        $(zavai_VALASOURCES:.vala=.h)
 
 zavai_SOURCES = \
        zavai.vala.stamp \
        $(zavai_VALASOURCES:.vala=.c) \
        $(zavai_VALASOURCES:.vala=.h)
 
-zavai.vapi zavai.vala.stamp: $(zavai_VALASOURCES)
-       $(VALAC) -C --basedir $(top_srcdir) $(VFLAGS) $^
+zavai.vapi zavai.vala.stamp: $(zavai_VALASOURCES) $(zavai_VAPIS)
+       $(VALAC) -C --basedir $(top_srcdir) $(VFLAGS) $(zavai_VALASOURCES)
        touch $@
 
 zavai_LDADD = \
        touch $@
 
 zavai_LDADD = \
@@ -64,5 +66,5 @@ zavai_LDADD = \
 #      gee-1.0.vapi \
 #      $(NULL)
 
 #      gee-1.0.vapi \
 #      $(NULL)
 
-EXTRA_DIST = sat-monitor
+EXTRA_DIST = $(zavai_VAPIS) sat-monitor
 #$(libgee_la_VALASOURCES) gee-1.0.vapi gee.vala.stamp
 #$(libgee_la_VALASOURCES) gee-1.0.vapi gee.vala.stamp
index 805fc97750f628927edeee2bc770925c4c055310..7b99f1a1b688001698ee61c6fbaa355fb1170e50 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-[Compact]
-[CCode (cname = "input_event", cheader_filename = "linux/input.h")]
-public struct InputEvent
-{
-       public Posix.timeval time;
-       public uint16 type;
-       public uint16 code;
-       public int32 val;
-}
-
 /*
 import sys
 import os
 /*
 import sys
 import os
@@ -84,17 +74,14 @@ 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());
                if (condition != IOCondition.IN) return true;
 
         stderr.printf("GOT INPUT ON %s %d\n", device, source.unix_get_fd());
-        char[] buf = new char[sizeof(InputEvent)];
+        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);
 
                size_t count_read;
                source.read_chars(buf, out count_read);
         stderr.printf("READ %zu chars\n", count_read);
 
-               InputEvent* ie = (InputEvent*)buf;
+               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);
 
-        //ssize_t count = Posix.read(source.unix_get_fd(), buf, 16);
-        //stderr.printf("READ %zd chars: %m\n", count);
-
         /*
         ts1, ts2, type, code, value = struct.unpack("LLHHI", buf)
         #print ts1, ts2, type, code, value
         /*
         ts1, ts2, type, code, value = struct.unpack("LLHHI", buf)
         #print ts1, ts2, type, code, value
@@ -156,7 +143,8 @@ public class Buttons : DevInput
     public Buttons()
     {
         name = "input.buttons";
     public Buttons()
     {
         name = "input.buttons";
-        // FIXME: change to event4 for the moko
+        // FIXME: change to event0 for the power button
+        // FIXME: change to event4 for the aux button and headset button
         device = "/dev/input/event1";
     }
 }
         device = "/dev/input/event1";
     }
 }
@@ -640,6 +628,8 @@ public void init()
        buttons = new Buttons();
 
        zavai.registry.register_service(buttons);
        buttons = new Buttons();
 
        zavai.registry.register_service(buttons);
+
+       stderr.printf("ANTANI %d\n", LinuxInput.Key.POWER);
 }
 
 }
 }
 
 }
diff --git a/src/linux-input.vapi b/src/linux-input.vapi
new file mode 100644 (file)
index 0000000..673015f
--- /dev/null
@@ -0,0 +1,19 @@
+[CCode (lower_case_cprefix="", cprefix="", cheader_filename="linux/input.h")]
+namespace LinuxInput
+{
+       [CCode (cname = "struct input_event")]
+       public struct Event
+       {
+               public Posix.timeval time;
+               public uint16 type;
+               public uint16 code;
+               [CCode (cname="value")]
+               public int32 val;
+       }
+
+       [CCode (cprefix="KEY_")]
+       public enum Key
+       {
+               POWER
+       }
+}