summaryrefslogtreecommitdiff
path: root/gtk/gtktooltip.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-05-17 01:22:02 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-05-17 01:22:02 -0400
commit5e35a4b69a4a2a53a13dc5df5fb209b7bfb6745a (patch)
treea9cb619fbe3774f431978f661249d29dcf2ab9a6 /gtk/gtktooltip.c
parent3035bf1e39f4f85c3499cf79860e89471ac8bd4f (diff)
downloadgtk+-5e35a4b69a4a2a53a13dc5df5fb209b7bfb6745a.tar.gz
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
Diffstat (limited to 'gtk/gtktooltip.c')
-rw-r--r--gtk/gtktooltip.c36
1 files changed, 28 insertions, 8 deletions
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;