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.

Since off-surface coordinates are not specially meaningful, and in
fact impossible to obtain in some backends, just fake the coordinates
making it sure that all rewritten events point outside the 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
This commit is contained in:
Carlos Garnacho 2022-03-14 13:29:11 +01:00
parent eb599653e6
commit aa43d97a80

View File

@ -899,31 +899,11 @@ rewrite_event_for_surface (GdkEvent *event,
GdkSurface *new_surface)
{
GdkEventType type;
double x, y;
double x = -G_MAXDOUBLE, y = -G_MAXDOUBLE;
double dx, dy;
type = gdk_event_get_event_type (event);
switch ((guint) type)
{
case GDK_BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
case GDK_MOTION_NOTIFY:
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
case GDK_TOUCH_END:
case GDK_TOUCH_CANCEL:
case GDK_TOUCHPAD_SWIPE:
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);
break;
default:
x = y = 0;
break;
}
switch ((guint) type)
{
case GDK_BUTTON_PRESS: