[gtk+/gestures: 38/92] gesture: Offer always coordinates in the gesture widget coordinate space



commit 27097c46c9a41593e0fb1c97fccc8116b5b5e587
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 24 13:04:51 2014 +0100

    gesture: Offer always coordinates in the gesture widget coordinate space
    
    Translate events meant for other widgets/windows, so gtk_gesture_get_point()
    always returns coordinates based on the gtk_event_controller_get_widget()
    allocation.

 gtk/gtkgesture.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index e4f9306..861003c 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -21,7 +21,7 @@
 #include <gtk/gtkgesture.h>
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
-#include "gtkmarshalers.h"
+#include "gtkmain.h"
 #include "gtkintl.h"
 
 typedef struct _GtkGesturePrivate GtkGesturePrivate;
@@ -45,6 +45,8 @@ enum {
 struct _PointData
 {
   GdkEvent *event;
+  gdouble widget_x;
+  gdouble widget_y;
   guint press_handled : 1;
   guint state : 2;
 };
@@ -230,6 +232,43 @@ _find_widget_window (GtkGesture *gesture,
   return NULL;
 }
 
+static void
+_update_widget_coordinates (GtkGesture *gesture,
+                            PointData  *data)
+{
+  GdkWindow *window, *event_widget_window;
+  GtkWidget *event_widget, *widget;
+  GtkAllocation allocation;
+  gdouble event_x, event_y;
+  gint wx, wy, x, y;
+
+  event_widget = gtk_get_event_widget (data->event);
+  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
+  event_widget_window = gtk_widget_get_window (event_widget);
+  gdk_event_get_coords (data->event, &event_x, &event_y);
+  window = data->event->any.window;
+
+  while (window != event_widget_window)
+    {
+      gdk_window_get_position (window, &wx, &wy);
+      event_x += wx;
+      event_y += wy;
+      window = gdk_window_get_effective_parent (window);
+    }
+
+  if (!gtk_widget_get_has_window (event_widget))
+    {
+      gtk_widget_get_allocation (event_widget, &allocation);
+      event_x -= allocation.x;
+      event_y -= allocation.y;
+    }
+
+  gtk_widget_translate_coordinates (event_widget, widget,
+                                    event_x, event_y, &x, &y);
+  data->widget_x = x;
+  data->widget_y = y;
+}
+
 static gboolean
 _gtk_gesture_update_point (GtkGesture     *gesture,
                            const GdkEvent *event,
@@ -290,6 +329,7 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
     gdk_event_free (data->event);
 
   data->event = gdk_event_copy (event);
+  _update_widget_coordinates (gesture, data);
 
   return TRUE;
 }
@@ -737,7 +777,12 @@ gtk_gesture_get_point (GtkGesture       *gesture,
                                      NULL, (gpointer *) &data))
     return FALSE;
 
-  return gdk_event_get_coords (data->event, x, y);
+  if (x)
+    *x = data->widget_x;
+  if (y)
+    *y = data->widget_y;
+
+  return TRUE;
 }
 
 /**


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