[gtk+/multitouch: 39/40] gdk: Listen to touch events by default on the native window



commit 0580c3e61300c4663f0268c1d3cb9cc71c76849a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 5 01:04:15 2012 +0100

    gdk: Listen to touch events by default on the native window
    
    GDK will only receive touch events when dealing with a multitouch
    device, so these must be transformed to pointer events if the
    client-side window receiving the event doesn't listen to touch
    events, and the touch sequence the event is from does emulate
    the pointer.
    
    If a sequence emulates pointer events, it will result in a
    button-press, N motions with GDK_BUTTON1_MASK set and a
    button-release event, and it will deliver crossing events
    as specified by the current device grab.

 gdk/gdkwindow.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 49 insertions(+), 9 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index b35bb27..88b37cb 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -1256,11 +1256,12 @@ get_native_device_event_mask (GdkWindow *private,
        * lists due to some non-native child window.
        */
       if (gdk_window_is_toplevel (private) ||
-	  mask & GDK_BUTTON_PRESS_MASK)
-	mask |=
-	  GDK_POINTER_MOTION_MASK |
-	  GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-	  GDK_SCROLL_MASK;
+          mask & GDK_BUTTON_PRESS_MASK)
+        mask |=
+          GDK_TOUCH_MASK |
+          GDK_POINTER_MOTION_MASK |
+          GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+          GDK_SCROLL_MASK;
 
       return mask;
     }
@@ -8200,6 +8201,14 @@ is_motion_type (GdkEventType type)
 	 type == GDK_LEAVE_NOTIFY;
 }
 
+static gboolean
+is_touch_type (GdkEventType type)
+{
+  return type == GDK_TOUCH_PRESS ||
+         type == GDK_TOUCH_RELEASE ||
+         type == GDK_TOUCH_MOTION;
+}
+
 static GdkWindow *
 find_common_ancestor (GdkWindow *win1,
 		      GdkWindow *win2)
@@ -9474,7 +9483,9 @@ proxy_pointer_event (GdkDisplay                 *display,
     non_linear = TRUE;
 
   if (pointer_info->need_touch_press_enter &&
-      gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCH)
+      gdk_device_get_source (pointer_info->last_slave) != GDK_SOURCE_TOUCH &&
+      (source_event->type != GDK_TOUCH_MOTION ||
+       _gdk_event_get_pointer_emulated (source_event)))
     {
       pointer_info->need_touch_press_enter = FALSE;
       need_synthetic_enter = TRUE;
@@ -9606,6 +9617,15 @@ proxy_pointer_event (GdkDisplay                 *display,
                                     &evmask,
                                     serial);
 
+      if ((evmask & GDK_TOUCH_MASK) == 0 &&
+          source_event->type == GDK_TOUCH_MOTION)
+        {
+          if (_gdk_event_get_pointer_emulated (source_event))
+            source_event->type = GDK_MOTION_NOTIFY;
+          else
+            return TRUE;
+        }
+
       if (event_win &&
           gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER &&
           gdk_window_get_device_events (event_win, device) == 0)
@@ -9824,6 +9844,20 @@ proxy_button_event (GdkEvent *source_event,
                                 type, state,
                                 &evmask, serial);
 
+  if ((evmask & GDK_TOUCH_MASK) == 0 &&
+      (type == GDK_TOUCH_PRESS || type == GDK_TOUCH_RELEASE))
+    {
+      if (_gdk_event_get_pointer_emulated (source_event))
+        {
+          if (type == GDK_TOUCH_PRESS)
+            source_event->type = type = GDK_BUTTON_PRESS;
+          else if (type == GDK_TOUCH_RELEASE)
+            source_event->type = type = GDK_BUTTON_RELEASE;
+        }
+      else
+        return TRUE;
+    }
+
   if (event_win == NULL || display->ignore_core_events)
     return TRUE;
 
@@ -9831,7 +9865,9 @@ proxy_button_event (GdkEvent *source_event,
       gdk_window_get_device_events (event_win, device) == 0)
     return TRUE;
 
-  if (type == GDK_BUTTON_PRESS &&
+  if ((type == GDK_BUTTON_PRESS ||
+       (type == GDK_TOUCH_PRESS &&
+        _gdk_event_get_pointer_emulated (source_event))) &&
       pointer_info->need_touch_press_enter)
     {
       GdkCrossingMode mode;
@@ -9879,7 +9915,9 @@ proxy_button_event (GdkEvent *source_event,
 
       if (type == GDK_BUTTON_PRESS)
         _gdk_event_button_generate (display, event);
-      else if (type == GDK_BUTTON_RELEASE &&
+      else if ((type == GDK_BUTTON_RELEASE ||
+                (type == GDK_TOUCH_RELEASE &&
+                 _gdk_event_get_pointer_emulated (source_event))) &&
                pointer_window == pointer_info->window_under_pointer &&
                gdk_device_get_source (source_device) == GDK_SOURCE_TOUCH)
         {
@@ -10150,7 +10188,9 @@ _gdk_windowing_got_event (GdkDisplay *display,
 	}
     }
 
-  if (pointer_info)
+  if (pointer_info &&
+      (!is_touch_type (event->type) ||
+       _gdk_event_get_pointer_emulated (event)))
     {
       /* Store last pointer window and position/state */
       old_state = pointer_info->state;



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