[gtk+] tooltip: Fix tooltip positions



commit f8d235ecc22808e64131026a373d4a92b7d47f2f
Author: Timm Bäder <mail baedert org>
Date:   Sat Jan 13 10:38:13 2018 +0100

    tooltip: Fix tooltip positions
    
    Since gtk_widget_get_allocation doesn't return x/y values relative to
    the GdkWindow anymore, we need to manually translate the widget
    coordinates here.

 gtk/gtktooltip.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c
index 9ad7a1b..91f1d54 100644
--- a/gtk/gtktooltip.c
+++ b/gtk/gtktooltip.c
@@ -621,8 +621,8 @@ static void
 get_bounding_box (GtkWidget    *widget,
                   GdkRectangle *bounds)
 {
+  GtkWidget *toplevel;
   GtkAllocation allocation;
-  GtkBorder border = { 0, };
   GdkWindow *window;
   gint x, y;
   gint w, h;
@@ -636,12 +636,32 @@ get_bounding_box (GtkWidget    *widget,
     window = gtk_widget_get_window (widget);
 
   gtk_widget_get_allocation (widget, &allocation);
+
+  x = allocation.x;
+  y = allocation.y;
+  w = allocation.width;
+  h = allocation.height;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (GTK_IS_WINDOW (toplevel) && !GTK_IS_WINDOW (widget))
+    {
+      GtkWidget *parent = gtk_widget_get_parent (widget);
+
+      gtk_widget_translate_coordinates (parent, toplevel,
+                                        x, y,
+                                        &x, &y);
+    }
+
   if (GTK_IS_WINDOW (widget))
-    _gtk_window_get_shadow_width (GTK_WINDOW (widget), &border);
-  x = allocation.x + border.left;
-  y = allocation.y + border.right;
-  w = allocation.width - border.left - border.right;
-  h = allocation.height - border.top - border.bottom;
+    {
+      GtkBorder border = { 0, };
+
+      _gtk_window_get_shadow_width (GTK_WINDOW (widget), &border);
+      x += border.left;
+      y += border.right;
+      w -= border.left + border.right;
+      h -= border.top + border.bottom;
+    }
 
   gdk_window_get_root_coords (window, x, y, &x1, &y1);
   gdk_window_get_root_coords (window, x + w, y, &x2, &y2);


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