From 5e35a4b69a4a2a53a13dc5df5fb209b7bfb6745a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 17 May 2020 01:22:02 -0400 Subject: tooltip: Fix positioning There are a few more places where we were forgetting to apply the surface->native transform. With these changes, tooltips are positioned correctly when the toplevel has padding applied. Fixes: #1619 --- gtk/gtktooltip.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'gtk/gtktooltip.c') diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c index a6962641af..2e65ee1ca5 100644 --- a/gtk/gtktooltip.c +++ b/gtk/gtktooltip.c @@ -35,7 +35,7 @@ #include "gtkwindowprivate.h" #include "gtkwidgetprivate.h" #include "gtkaccessible.h" -#include "gtknative.h" +#include "gtknativeprivate.h" /** * SECTION:gtktooltip @@ -426,6 +426,7 @@ _gtk_widget_find_at_coords (GdkSurface *surface, { GtkWidget *event_widget; GtkWidget *picked_widget; + int native_x, native_y; g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL); @@ -434,6 +435,10 @@ _gtk_widget_find_at_coords (GdkSurface *surface, if (!event_widget) return NULL; + gtk_native_get_surface_transform (GTK_NATIVE (event_widget), &native_x, &native_y); + surface_x -= native_x; + surface_y -= native_y; + picked_widget = gtk_widget_pick (event_widget, surface_x, surface_y, GTK_PICK_INSENSITIVE); if (picked_widget != NULL) @@ -583,17 +588,22 @@ gtk_tooltip_position (GtkTooltip *tooltip, int rect_anchor_dx = 0; int cursor_size; int anchor_rect_padding; + int native_x, native_y; gtk_widget_realize (GTK_WIDGET (tooltip->window)); tooltip->tooltip_widget = new_tooltip_widget; toplevel = GTK_WIDGET (gtk_widget_get_native (new_tooltip_widget)); + gtk_native_get_surface_transform (GTK_NATIVE (toplevel), &native_x, &native_y); + if (gtk_widget_compute_bounds (new_tooltip_widget, toplevel, &anchor_bounds)) { anchor_rect = (GdkRectangle) { - floorf (anchor_bounds.origin.x), floorf (anchor_bounds.origin.y), - ceilf (anchor_bounds.size.width), ceilf (anchor_bounds.size.height) + floorf (anchor_bounds.origin.x + native_x), + floorf (anchor_bounds.origin.y + native_y), + ceilf (anchor_bounds.size.width), + ceilf (anchor_bounds.size.height) }; } else @@ -896,16 +906,26 @@ _gtk_tooltip_handle_event (GtkWidget *target, { GdkEventType event_type; GdkSurface *surface; - gdouble dx, dy; + double x, y; + int native_x, native_y; + int tx, ty; + GtkWidget *native; if (!tooltips_enabled (event)) return; event_type = gdk_event_get_event_type (event); surface = gdk_event_get_surface (event); - gdk_event_get_position (event, &dx, &dy); + gdk_event_get_position (event, &x, &y); + native = GTK_WIDGET (gtk_widget_get_native (target)); + + gtk_native_get_surface_transform (GTK_NATIVE (native), &native_x, &native_y); + gtk_widget_translate_coordinates (native, target, + x - native_x, + y - native_y, + &tx, &ty); - gtk_tooltip_handle_event_internal (event_type, surface, target, dx, dy); + gtk_tooltip_handle_event_internal (event_type, surface, target, tx, ty); } /* dx/dy must be in @target_widget's coordinates */ @@ -913,8 +933,8 @@ static void gtk_tooltip_handle_event_internal (GdkEventType event_type, GdkSurface *surface, GtkWidget *target_widget, - gdouble dx, - gdouble dy) + gdouble dx, + gdouble dy) { int x = dx, y = dy; GdkDisplay *display; -- cgit v1.2.1