[gtk+/multitouch: 73/121] Add initial handling of TouchMotion events.



commit 0ae645e55c1cc378a1e4a5a6ef70a3a54069d40d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 28 21:14:50 2011 +0100

    Add initial handling of TouchMotion events.
    
    GdkDeviceManagerXI2 now handles TouchMotion and TouchMotionUnowned
    events, which are translated to GDK_TOUCH_MOTION events.

 gdk/gdkwindow.c                |    1 +
 gdk/x11/gdkdevice-xi2.c        |   11 ++++++
 gdk/x11/gdkdevicemanager-x11.c |    4 ++
 gdk/x11/gdkdevicemanager-xi2.c |   78 ++++++++++++++++++++++++++++++---------
 4 files changed, 76 insertions(+), 18 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 1862abe..acda2d0 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8133,6 +8133,7 @@ static const guint type_masks[] = {
   0, /* GDK_OWNER_CHANGE = 34 */
   0, /* GDK_GRAB_BROKEN = 35 */
   0, /* GDK_DAMAGE = 36 */
+  GDK_TOUCH_MASK | GDK_BUTTON_MOTION_MASK /* GDK_TOUCH_MOTION = 37 */
 };
 G_STATIC_ASSERT (G_N_ELEMENTS (type_masks) == GDK_EVENT_LAST);
 
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index bc6261b..bd9cb2e 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -690,6 +690,17 @@ _gdk_x11_device_xi2_translate_event_mask (GdkEventMask  event_mask,
       XISetMask (mask, XI_FocusOut);
     }
 
+#ifdef XINPUT_2_1
+  if (event_mask & GDK_TOUCH_MASK)
+    {
+      XISetMask (mask, XI_TouchBegin);
+      XISetMask (mask, XI_TouchMotion);
+      XISetMask (mask, XI_TouchMotionUnowned);
+      XISetMask (mask, XI_TouchEnd);
+      XISetMask (mask, XI_TouchOwnership);
+    }
+#endif /* XINPUT_2_1 */
+
   return mask;
 }
 
diff --git a/gdk/x11/gdkdevicemanager-x11.c b/gdk/x11/gdkdevicemanager-x11.c
index 3faff6d..9d20ad9 100644
--- a/gdk/x11/gdkdevicemanager-x11.c
+++ b/gdk/x11/gdkdevicemanager-x11.c
@@ -54,7 +54,11 @@ _gdk_x11_device_manager_new (GdkDisplay *display)
           int major, minor;
 
           major = 2;
+#ifdef XINPUT_2_1
+	  minor = 1;
+#else
           minor = 0;
+#endif /* XINPUT_2_1 */
 
           if (!_gdk_disable_multidevice &&
               XIQueryVersion (xdisplay, &major, &minor) != BadRequest)
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index cec2596..99bd4f9 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -166,8 +166,10 @@ _gdk_x11_device_manager_xi2_select_events (GdkDeviceManager *device_manager,
 static void
 translate_valuator_class (GdkDisplay          *display,
                           GdkDevice           *device,
-                          XIValuatorClassInfo *info,
-                          gint                 n_valuator)
+                          Atom                 valuator_label,
+                          gdouble              min,
+                          gdouble              max,
+                          gdouble              resolution)
 {
   static gboolean initialized = FALSE;
   static Atom label_atoms [GDK_AXIS_LAST] = { 0 };
@@ -188,24 +190,19 @@ translate_valuator_class (GdkDisplay          *display,
 
   for (i = GDK_AXIS_IGNORE; i < GDK_AXIS_LAST; i++)
     {
-      if (label_atoms[i] == info->label)
+      if (label_atoms[i] == valuator_label)
         {
           use = i;
           break;
         }
     }
 
-  if (info->label != None)
-    label = gdk_x11_xatom_to_atom_for_display (display, info->label);
+  if (valuator_label != None)
+    label = gdk_x11_xatom_to_atom_for_display (display, valuator_label);
   else
     label = GDK_NONE;
 
-  _gdk_device_add_axis (device,
-                        label,
-                        use,
-                        info->min,
-                        info->max,
-                        info->resolution);
+  _gdk_device_add_axis (device, label, use, min, max, resolution);
 }
 
 static void
@@ -214,7 +211,7 @@ translate_device_classes (GdkDisplay      *display,
                           XIAnyClassInfo **classes,
                           guint            n_classes)
 {
-  gint i, n_valuator = 0;
+  gint i;
 
   g_object_freeze_notify (G_OBJECT (device));
 
@@ -236,11 +233,28 @@ translate_device_classes (GdkDisplay      *display,
           }
           break;
         case XIValuatorClass:
-          translate_valuator_class (display, device,
-                                    (XIValuatorClassInfo *) class_info,
-                                    n_valuator);
-          n_valuator++;
+          {
+            XIValuatorClassInfo *valuator_info = (XIValuatorClassInfo *) class_info;
+            translate_valuator_class (display, device,
+                                      valuator_info->label,
+                                      valuator_info->min,
+                                      valuator_info->max,
+                                      valuator_info->resolution);
+          }
+          break;
+#ifdef XINPUT_2_1
+        case XITouchValuatorClass:
+          {
+            XITouchValuatorClassInfo *valuator_info = (XITouchValuatorClassInfo *) class_info;
+
+            translate_valuator_class (display, device,
+                                      valuator_info->label,
+                                      valuator_info->min,
+                                      valuator_info->max,
+                                      valuator_info->resolution);
+          }
           break;
+#endif /* XINPUT_2_1 */
         default:
           /* Ignore */
           break;
@@ -279,6 +293,8 @@ create_device (GdkDeviceManager *device_manager,
       else if (strstr (tmp_name, "wacom") ||
                strstr (tmp_name, "pen"))
         input_source = GDK_SOURCE_PEN;
+      else if (strstr (tmp_name, "multitouch"))
+        input_source = GDK_SOURCE_TOUCH;
       else
         input_source = GDK_SOURCE_MOUSE;
 
@@ -859,6 +875,10 @@ get_event_window (GdkEventTranslator *translator,
     case XI_ButtonPress:
     case XI_ButtonRelease:
     case XI_Motion:
+#ifdef XINPUT_2_1
+    case XI_TouchMotion:
+    case XI_TouchMotionUnowned:
+#endif /* XINPUT_2_1 */
       {
         XIDeviceEvent *xev = (XIDeviceEvent *) ev;
 
@@ -1178,11 +1198,32 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
         break;
       }
     case XI_Motion:
+#ifdef XINPUT_2_1
+    case XI_TouchMotion:
+    case XI_TouchMotionUnowned:
+      /* FIXME: Unowned events should be rollback-able,
+       * the easiest way to go could be just storing the
+       * events so they can be replayed in arrival order
+       * when an ownership event arrives, needs further
+       * investigation though.
+       */
+#endif /* XINPUT_2_1 */
       {
         XIDeviceEvent *xev = (XIDeviceEvent *) ev;
         GdkDevice *source_device;
 
-        event->motion.type = GDK_MOTION_NOTIFY;
+        if (ev->evtype == XI_Motion)
+          {
+            event->motion.touch_id = 0;
+            event->motion.type = GDK_MOTION_NOTIFY;
+          }
+#ifdef XINPUT_2_1
+        else
+          {
+            event->motion.touch_id = xev->detail;
+            event->motion.type = GDK_TOUCH_MOTION;
+          }
+#endif
 
         event->motion.window = window;
 
@@ -1316,7 +1357,8 @@ gdk_x11_device_manager_xi2_get_handled_events (GdkEventTranslator *translator)
           GDK_BUTTON2_MOTION_MASK |
           GDK_BUTTON3_MOTION_MASK |
           GDK_BUTTON_MOTION_MASK |
-          GDK_FOCUS_CHANGE_MASK);
+          GDK_FOCUS_CHANGE_MASK |
+          GDK_TOUCH_MASK);
 }
 
 static void



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