[gtk+/multitouch: 14/27] gdk: Add GDK_SOURCE_MULTITOUCH



commit dd8c5cce8829efa66cbfee9972ddba1e06cbb977
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 27 22:25:54 2011 +0200

    gdk: Add GDK_SOURCE_MULTITOUCH
    
    There is now a difference between single touch and multitouch devices.
    Events coming from multitouch devices will typically produce double
    motion and touch events, so have gdk_windowing_got_event() filter
    the corresponding event depending on the touch mask and the device
    source.

 gdk/gdkdevice.h       |    4 ++-
 gdk/gdktouchcluster.c |    3 +-
 gdk/gdkwindow.c       |   60 +++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 51 insertions(+), 16 deletions(-)
---
diff --git a/gdk/gdkdevice.h b/gdk/gdkdevice.h
index 3cd97d1..6c11192 100644
--- a/gdk/gdkdevice.h
+++ b/gdk/gdkdevice.h
@@ -62,6 +62,7 @@ typedef enum
  * @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.
+ * @GDK_SOURCE_MULTITOUCH: the device is a multi-touch capable device
  *
  * An enumeration describing the type of an input device in general terms.
  */
@@ -72,7 +73,8 @@ typedef enum
   GDK_SOURCE_ERASER,
   GDK_SOURCE_CURSOR,
   GDK_SOURCE_KEYBOARD,
-  GDK_SOURCE_TOUCH
+  GDK_SOURCE_TOUCH,
+  GDK_SOURCE_MULTITOUCH
 } GdkInputSource;
 
 /**
diff --git a/gdk/gdktouchcluster.c b/gdk/gdktouchcluster.c
index 9bc0474..7d60efa 100644
--- a/gdk/gdktouchcluster.c
+++ b/gdk/gdktouchcluster.c
@@ -330,7 +330,8 @@ gdk_touch_cluster_set_device (GdkTouchCluster *cluster,
  *
  * Returns the slave/floating device this touch cluster pertains to,
  * only touch IDs from this device can be included in @cluster.
- * the #GdkDevice will typically have the %GDK_SOURCE_TOUCH input source.
+ * the #GdkDevice will typically have the %GDK_SOURCE_TOUCH or
+ * %GDK_SOURCE_MULTITOUCH input source.
  *
  * Returns: (transfer none): The #GdkDevice generating the contained touch IDs
  **/
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 29a7494..fde4946 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -9456,14 +9456,28 @@ proxy_pointer_event (GdkDisplay                 *display,
           gdk_window_get_device_events (event_win, device) == 0)
         return TRUE;
 
-      /* Block motion events coming from touch devices, only if
-       * the event mask allows both motion and touch events, since
-       * the latter will come right after.
-       */
       if ((evmask & GDK_TOUCH_MASK) &&
-          gdk_device_get_source (source_device) == GDK_SOURCE_TOUCH &&
           source_event->type == GDK_MOTION_NOTIFY)
-        return TRUE;
+        {
+          GdkInputSource input_source;
+
+          input_source = gdk_device_get_source (source_device);
+
+          if (input_source == GDK_SOURCE_MULTITOUCH)
+            {
+              /* Block motion events coming from touch devices, only if
+               * the event mask allows both motion and touch events, since
+               * the latter will come right after.
+               */
+              return TRUE;
+            }
+          else if (input_source == GDK_SOURCE_TOUCH)
+            {
+              /* Transform motion event into touch motion */
+              source_event->type = GDK_TOUCH_MOTION;
+              source_event->motion.touch_id = 0;
+            }
+        }
 
       is_hint = FALSE;
 
@@ -9629,17 +9643,35 @@ proxy_button_event (GdkEvent *source_event,
 				type, state,
 				&evmask, serial);
 
-  /* Block button press/release events coming from touch devices, only if
-   * the event mask allows both normal and touch events, since
-   * the latter will come right after.
-   */
-  if ((evmask & GDK_TOUCH_MASK) &&
-      gdk_device_get_source (source_device) == GDK_SOURCE_TOUCH &&
+  if ((evmask & GDK_TOUCH_MASK) != 0 &&
       source_event->type != GDK_TOUCH_PRESS &&
       source_event->type != GDK_TOUCH_RELEASE)
     {
-      *handle_ungrab = FALSE;
-      return TRUE;
+      GdkInputSource input_source;
+
+      input_source = gdk_device_get_source (source_device);
+
+      if (input_source == GDK_SOURCE_MULTITOUCH)
+        {
+          /* Block button press/release events coming from touch devices, only if
+           * the event mask allows both normal and touch events, since
+           * the latter will come right after.
+           */
+          *handle_ungrab = FALSE;
+          return TRUE;
+        }
+      else if (input_source == GDK_SOURCE_TOUCH)
+        {
+          /* Transform button press/release into
+           * touch event.
+           */
+          if (type == GDK_BUTTON_PRESS)
+            type = source_event->type = GDK_TOUCH_PRESS;
+          else if (type == GDK_BUTTON_RELEASE)
+            type = source_event->type = GDK_TOUCH_RELEASE;
+
+          source_event->button.touch_id = 0;
+        }
     }
 
   if (event_win == NULL || display->ignore_core_events)



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