[gtk/wip/carlosg/rewritten-events-from-other-toplevels] gtk/main: Make coords out of surface when rewriting events for grabs




commit de8b29513ffa9ce257716b5085e25fc7e6de79a2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 14 13:29:11 2022 +0100

    gtk/main: Make coords out of surface when rewriting events for grabs
    
    If a grab is held on a toplevel surface tree, and events happen on a
    different surface tree from another toplevel/window group, we rewrite
    these events so they look like generated on the window group that
    holds the grab, but it missed that coordinates would fail to be
    translated, so these would stay unchanged and "pointing" to random
    parts of the toplevel that is holding the grab and handling the events.
    
    If we find this situation, and as it is not possible to translate
    coordinates between toplevels on some platforms, make it at least sure
    that the coordinates will be pointing outside the grabbing surface.
    The grabbing window will still handle the events, but the coordinates
    in these will be harmlessly moot.
    
    Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4760

 gtk/gtkmain.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index aa32930242..97ccacb8fc 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -917,10 +917,11 @@ rewrite_event_for_surface (GdkEvent  *event,
     case GDK_TOUCHPAD_PINCH:
     case GDK_TOUCHPAD_HOLD:
       gdk_event_get_position (event, &x, &y);
-      gdk_surface_translate_coordinates (gdk_event_get_surface (event), new_surface, &x, &y);
+      if (!gdk_surface_translate_coordinates (gdk_event_get_surface (event), new_surface, &x, &y))
+        x = y = -G_MAXDOUBLE;
       break;
     default:
-      x = y = 0;
+      x = y = -G_MAXDOUBLE;
       break;
     }
 


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