[gtk+/xi21: 3/12] Add initial handling of TouchMotion events.



commit a898575fdd4a642986d904b6ed5920e703132a7c
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/gdkdevice.h                |    4 ++-
 gdk/gdkwindow.c                |    1 +
 gdk/x11/gdkdevice-xi2.c        |   11 ++++++
 gdk/x11/gdkdevicemanager-x11.c |    4 ++
 gdk/x11/gdkdevicemanager-xi2.c |   79 +++++++++++++++++++++++++++++++---------
 5 files changed, 80 insertions(+), 19 deletions(-)
---
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index a6ceac0..2ae8067 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -61,6 +61,7 @@ typedef enum
  *                     of a stylus on a graphics tablet.
  * @GDK_SOURCE_CURSOR: the device is a graphics tablet "puck" or similar device.
  * @GDK_SOURCE_KEYBOARD: the device is a keyboard.
+ * @GDK_SOURCE_TOUCH: the device is a touch capable device.
  *
  * An enumeration describing the type of an input device in general terms.
  */
@@ -70,7 +71,8 @@ typedef enum
   GDK_SOURCE_PEN,
   GDK_SOURCE_ERASER,
   GDK_SOURCE_CURSOR,
-  GDK_SOURCE_KEYBOARD
+  GDK_SOURCE_KEYBOARD,
+  GDK_SOURCE_TOUCH
 } GdkInputSource;
 
 /**
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 8318b99..febf5c4 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -8066,6 +8066,7 @@ static const guint type_masks[] = {
   0, /* GDK_OWNER_CHANGE = 34 */
   0, /* GDK_GRAB_BROKEN = 35 */
   0, /* GDK_DAMAGE = 36 */
+  GDK_TOUCH_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 96715df..6e48a95 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -687,6 +687,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 a19a05e..465d0b8 100644
--- a/gdk/x11/gdkdevicemanager-x11.c
+++ b/gdk/x11/gdkdevicemanager-x11.c
@@ -47,7 +47,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 e84c1e3..c527d5a 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -147,8 +147,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 };
@@ -169,24 +171,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
@@ -195,7 +192,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));
 
@@ -217,11 +214,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;
@@ -256,6 +270,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;
 
@@ -883,6 +899,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;
 
@@ -1161,11 +1181,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;
 
@@ -1252,6 +1293,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
 
         return_val = FALSE;
       }
+      break;
     default:
       return_val = FALSE;
       break;
@@ -1297,7 +1339,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]