[gtk+/multitouch: 15/40] xi2: Use GDK_SOURCE_TOUCH for multitouch devices



commit 97c91692c03b99090fd9ef9b1d5a2efce9a941ab
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 27 22:30:14 2011 +0200

    xi2: Use GDK_SOURCE_TOUCH for multitouch devices
    
    Any device with XITouchValuatorClassInfo classes qualify as
    multitouch now.

 gdk/x11/gdkdevicemanager-xi2.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index c9c262f..df7381f 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -264,6 +264,28 @@ translate_device_classes (GdkDisplay      *display,
   g_object_thaw_notify (G_OBJECT (device));
 }
 
+static gint
+count_device_touches (XIAnyClassInfo **classes,
+		      guint            n_classes)
+{
+  gint n_touches = 0;
+#ifdef XINPUT_2_1
+  guint i;
+
+  for (i = 0; i < n_classes; i++)
+    {
+      XITouchValuatorClassInfo *valuator_info = (XITouchValuatorClassInfo *) classes[i];
+
+      if (valuator_info->type != XITouchValuatorClass)
+        continue;
+
+      n_touches = MAX (n_touches, valuator_info->number);
+    }
+#endif
+
+  return n_touches;
+}
+
 static GdkDevice *
 create_device (GdkDeviceManager *device_manager,
                GdkDisplay       *display,
@@ -276,6 +298,9 @@ create_device (GdkDeviceManager *device_manager,
 
   if (dev->use == XIMasterKeyboard || dev->use == XISlaveKeyboard)
     input_source = GDK_SOURCE_KEYBOARD;
+  else if (dev->use == XISlavePointer &&
+           count_device_touches (dev->classes, dev->num_classes) > 0)
+    input_source = GDK_SOURCE_TOUCH;
   else
     {
       gchar *tmp_name;
@@ -293,8 +318,6 @@ 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;
 



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