[gtk+/wip/carlosg/event-delivery: 22/24] gtkwidget: Make gtk_widget_event() Accept pointing events in root coordinates



commit dba2c735434424cfd008bd2edad053324794c34a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 31 18:25:04 2017 +0200

    gtkwidget: Make gtk_widget_event() Accept pointing events in root coordinates
    
    This function will, at the last minute, ensure the event contains the right
    widget-relative coordinates for the widget the event is being emitted to.

 gtk/gtkwidget.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index e323736..4f67c86 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -6904,6 +6904,28 @@ event_window_is_still_viewable (GdkEvent *event)
     }
 }
 
+static void
+translate_coordinates (GdkEvent  *event,
+                       GtkWidget *widget)
+{
+  GtkWidget *event_widget;
+  gdouble xd, yd;
+  gint x, y;
+
+  if (!gdk_event_get_coords (event, &xd, &yd))
+    return;
+  if (!widget->priv->event_controllers)
+    return;
+  event_widget = gtk_get_event_widget (event);
+
+  /* FIXME: loses precision */
+  x = xd;
+  y = yd;
+  gtk_widget_translate_coordinates (event_widget, widget,
+                                    x, y, &x, &y);
+  gdk_event_set_coords (event, x, y);
+}
+
 static gint
 gtk_widget_event_internal (GtkWidget *widget,
                           GdkEvent  *event)
@@ -6918,6 +6940,8 @@ gtk_widget_event_internal (GtkWidget *widget,
   if (!event_window_is_still_viewable (event))
     return TRUE;
 
+  translate_coordinates (event, widget);
+
   g_object_ref (widget);
 
   if (widget == gtk_get_event_widget (event))


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