[gtk+/multitouch-for-3.4: 75/89] gdk: Listen to touch events by default on the native window



commit 0f03962185ab70447017ef7cad1070d217462aaf
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 ba9459e..0b66d8a 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -1245,11 +1245,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;
     }
@@ -8167,6 +8168,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)
@@ -9229,7 +9238,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;
@@ -9361,6 +9372,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)
@@ -9554,6 +9574,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;
 
@@ -9561,7 +9595,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;
@@ -9609,7 +9645,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)
         {
@@ -9856,7 +9894,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]