From d89447d68e0ee54088ff1432bd02670015904d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 14 Dec 2023 14:36:25 +0100 Subject: [PATCH] gtkgesture: Preserve accuracy when translating events gtk_widget_translate_coordinates() uses int argument and thus cuts off any decimal parts. This can leads to reduces accuracy when e.g. measuring the distance of a drag. GTK4 is not affected as the translations is done differently. --- gtk/gtkgesture.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c index a867a5fd1d..48cf9ba4de 100644 --- a/gtk/gtkgesture.c +++ b/gtk/gtkgesture.c @@ -504,8 +504,11 @@ _update_widget_coordinates (GtkGesture *gesture, gtk_widget_translate_coordinates (event_widget, widget, event_x, event_y, &x, &y); - data->widget_x = x; - data->widget_y = y; + /* gtk_widget_translate() loses the fractional part so we need to + * add it back to not lose accuracy */ + data->widget_x = x + (event_x - (int)event_x); + data->widget_y = y + (event_y - (int)event_y); + } static GtkEventSequenceState