[gtk/wip/carlosg/rewritten-events-from-other-toplevels: 2/2] gtk/main: Fix handling of !owner_events grabs




commit e5dc66b10e7553073f118223789e1f2b38d1acbb
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Mar 15 14:32:10 2022 +0100

    gtk/main: Fix handling of !owner_events grabs
    
    These are meant to always redirect events to the grabbing surface,
    even for other surfaces of the same client. We weren't doing that
    (instead letting the event go through unmodified), fix this handling
    so GTK sees the events consistenty.

 gtk/gtkmain.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 470dc54315..ab6ddba96e 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1013,8 +1013,7 @@ rewrite_event_for_grabs (GdkEvent *event)
       display = gdk_event_get_display (event);
       device = gdk_event_get_device (event);
 
-      if (!gdk_device_grab_info (display, device, &grab_surface, &owner_events) ||
-          !owner_events)
+      if (!gdk_device_grab_info (display, device, &grab_surface, &owner_events))
         return NULL;
       break;
     default:
@@ -1024,11 +1023,24 @@ rewrite_event_for_grabs (GdkEvent *event)
   event_widget = gtk_get_event_widget (event);
   grab_widget = GTK_WIDGET (gtk_native_get_for_surface (grab_surface));
 
-  if (grab_widget &&
-      gtk_main_get_window_group (grab_widget) != gtk_main_get_window_group (event_widget))
-    return rewrite_event_for_surface (event, grab_surface);
-  else
+  if (!grab_widget)
+    return NULL;
+
+  /* If owner_events was set, events in client surfaces get forwarded
+   * as normal, but we consider other window groups foreign surfaces.
+   */
+  if (owner_events &&
+      gtk_main_get_window_group (grab_widget) == gtk_main_get_window_group (event_widget))
     return NULL;
+
+  /* If owner_events was not set, events only get sent to the grabbing
+   * surface.
+   */
+  if (!owner_events &&
+      grab_surface == gtk_native_get_surface (gtk_widget_get_native (event_widget)))
+    return NULL;
+
+  return rewrite_event_for_surface (event, grab_surface);
 }
 
 static GdkEvent *


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