[mutter/wip/xinput2r: 23/68] input-events: Add method to get the device for an event



commit 2d4cb715903d608bff0a659d3e843b19042530c8
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jun 11 22:16:28 2011 +0200

    input-events: Add method to get the device for an event

 src/core/input-events.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 src/core/input-events.h |    5 +++-
 2 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/src/core/input-events.c b/src/core/input-events.c
index b21a304..246582a 100644
--- a/src/core/input-events.c
+++ b/src/core/input-events.c
@@ -23,6 +23,8 @@
 
 #include <config.h>
 #include "input-events.h"
+#include "devices-core.h"
+#include "device-map.h"
 #include <X11/Xlib.h>
 
 #ifdef HAVE_XINPUT2
@@ -614,3 +616,62 @@ meta_input_event_get_crossing_details (MetaDisplay *display,
 
   return retval;
 }
+
+MetaDevice *
+meta_input_event_get_device (MetaDisplay *display,
+                             XEvent      *ev)
+{
+  guint evtype;
+
+  if (!meta_input_event_get_type (display, ev, &evtype))
+    return NULL;
+
+#ifdef HAVE_XINPUT2
+  if (ev->type == GenericEvent &&
+      ev->xcookie.extension == display->xinput2_opcode)
+    {
+      XIEvent *xev;
+
+      g_assert (display->have_xinput2 == TRUE);
+
+      xev = (XIEvent *) ev->xcookie.data;
+
+      switch (evtype)
+        {
+        case XI_Motion:
+        case XI_ButtonPress:
+        case XI_ButtonRelease:
+        case XI_KeyPress:
+        case XI_KeyRelease:
+          return meta_device_map_lookup (display->device_map,
+                                         ((XIDeviceEvent *) xev)->deviceid);
+        case XI_FocusIn:
+        case XI_FocusOut:
+        case XI_Enter:
+        case XI_Leave:
+          return meta_device_map_lookup (display->device_map,
+                                         ((XIEnterEvent *) xev)->deviceid);
+        default:
+          break;
+        }
+    }
+  else
+#endif
+    {
+      switch (ev->type)
+        {
+        case KeyPress:
+        case KeyRelease:
+        case FocusIn:
+        case FocusOut:
+          return meta_device_map_lookup (display->device_map,
+                                         META_CORE_KEYBOARD_ID);
+        default:
+          /* All other events are pointers' */
+          return meta_device_map_lookup (display->device_map,
+                                         META_CORE_POINTER_ID);
+        }
+    }
+
+  return NULL;
+}
diff --git a/src/core/input-events.h b/src/core/input-events.h
index 46eba80..1107055 100644
--- a/src/core/input-events.h
+++ b/src/core/input-events.h
@@ -33,7 +33,7 @@
 #include <config.h>
 #include <X11/Xlib.h>
 #include "display-private.h"
-
+#include "device-map.h"
 
 gboolean meta_input_event_get_type          (MetaDisplay *display,
                                              XEvent      *ev,
@@ -71,5 +71,8 @@ gboolean meta_input_event_get_crossing_details (MetaDisplay *display,
                                                 guint       *mode_out,
                                                 guint       *detail_out);
 
+MetaDevice *meta_input_event_get_device        (MetaDisplay *display,
+                                                XEvent      *ev);
+
 
 #endif /* META_EVENT_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]