[gtk+/gtk-3-22] gtkwidget: Emulate motion before button press on fallback touch handler



commit 9b874a40ac11d36b9eefb955593281a17b25691a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Oct 19 13:55:34 2017 +0200

    gtkwidget: Emulate motion before button press on fallback touch handler
    
    The code has been shuffled so GDK_TOUCH_BEGIN results in a
    GDK_MOTION_NOTIFY to the new position and a GDK_BUTTON_PRESS on that same
    place. This makes pointer emulation consistent with what X11 does. Even
    though button presses have x/y arguments, there's code out there relying
    on getting prior motion events.

 gtk/gtkwidget.c |   56 ++++++++++++++++++++++++++++++------------------------
 1 files changed, 31 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 864edf6..44112e5 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7179,17 +7179,43 @@ gtk_widget_real_touch_event (GtkWidget     *widget,
                              GdkEventTouch *event)
 {
   GdkEvent *bevent;
-  gboolean return_val;
-  gint signum;
+  gboolean return_val = FALSE;
 
   if (!event->emulating_pointer)
     return _gtk_widget_run_controllers (widget, (GdkEvent*) event,
                                         GTK_PHASE_BUBBLE);
 
+  if (event->type == GDK_TOUCH_UPDATE ||
+      event->type == GDK_TOUCH_BEGIN)
+    {
+      bevent = gdk_event_new (GDK_MOTION_NOTIFY);
+      bevent->any.window = g_object_ref (event->window);
+      bevent->any.send_event = FALSE;
+      bevent->motion.time = event->time;
+      bevent->button.state = event->state;
+      bevent->motion.x_root = event->x_root;
+      bevent->motion.y_root = event->y_root;
+      bevent->motion.x = event->x;
+      bevent->motion.y = event->y;
+      bevent->motion.device = event->device;
+      bevent->motion.is_hint = FALSE;
+      bevent->motion.axes = g_memdup (event->axes,
+                                      sizeof (gdouble) * gdk_device_get_n_axes (event->device));
+      gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
+
+      if (event->type == GDK_TOUCH_UPDATE)
+        bevent->motion.state |= GDK_BUTTON1_MASK;
+
+      g_signal_emit (widget, widget_signals[MOTION_NOTIFY_EVENT], 0, bevent, &return_val);
+
+      gdk_event_free (bevent);
+    }
+
   if (event->type == GDK_TOUCH_BEGIN ||
       event->type == GDK_TOUCH_END)
     {
       GdkEventType type;
+      gint signum;
 
       if (event->type == GDK_TOUCH_BEGIN)
         {
@@ -7218,31 +7244,11 @@ gtk_widget_real_touch_event (GtkWidget     *widget,
 
       if (event->type == GDK_TOUCH_END)
         bevent->button.state |= GDK_BUTTON1_MASK;
-    }
-  else if (event->type == GDK_TOUCH_UPDATE)
-    {
-      signum = MOTION_NOTIFY_EVENT;
-      bevent = gdk_event_new (GDK_MOTION_NOTIFY);
-      bevent->any.window = g_object_ref (event->window);
-      bevent->any.send_event = FALSE;
-      bevent->motion.time = event->time;
-      bevent->motion.state = event->state | GDK_BUTTON1_MASK;
-      bevent->motion.x_root = event->x_root;
-      bevent->motion.y_root = event->y_root;
-      bevent->motion.x = event->x;
-      bevent->motion.y = event->y;
-      bevent->motion.device = event->device;
-      bevent->motion.is_hint = FALSE;
-      bevent->motion.axes = g_memdup (event->axes,
-                                      sizeof (gdouble) * gdk_device_get_n_axes (event->device));
-      gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
-    }
-  else
-    return FALSE;
 
-  g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
+      g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
 
-  gdk_event_free (bevent);
+      gdk_event_free (bevent);
+    }
 
   return return_val;
 }


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