[mutter/wip/carlosg/grabs-pt2: 9/9] core: Handle redirection changes in and out of ClutterGrab grabs




commit 49070a5cc49b12f0d3f65af62c2d2ab57d8961b9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Nov 17 23:31:11 2021 +0100

    core: Handle redirection changes in and out of ClutterGrab grabs
    
    Wayland event processing and WM operations are themselves outside the
    ClutterGrab loop so far. Until this is sorted out, these pieces of
    event handling have got to learn to stay aside while there is a
    ClutterGrab going on.
    
    So, synchronize foci and other state when grabs come in or out, and
    make it sure that Wayland event processing does not happen while
    grabs happen.

 clutter/clutter/clutter-stage.c        |  9 ++++++---
 src/core/events.c                      | 28 ++++++++++++++++++++++++++++
 src/wayland/meta-wayland-pointer.c     |  6 ++++++
 src/wayland/meta-wayland-tablet-tool.c |  8 ++++++++
 4 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 82c8e2c406..df4d05e681 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -3425,7 +3425,8 @@ clutter_stage_update_device (ClutterStage         *stage,
                                          CLUTTER_LEAVE, 0,
                                          old_actor, new_actor,
                                          point, time);
-          _clutter_actor_handle_event (old_actor, root, event);
+          if (!_clutter_event_process_filters (event))
+            _clutter_actor_handle_event (old_actor, root, event);
 
           clutter_event_free (event);
         }
@@ -3437,7 +3438,8 @@ clutter_stage_update_device (ClutterStage         *stage,
                                          CLUTTER_ENTER, 0,
                                          new_actor, old_actor,
                                          point, time);
-          _clutter_actor_handle_event (new_actor, root, event);
+          if (!_clutter_event_process_filters (event))
+            _clutter_actor_handle_event (new_actor, root, event);
 
           clutter_event_free (event);
         }
@@ -3558,7 +3560,8 @@ clutter_stage_notify_grab_on_entry (ClutterStage       *stage,
                                      grab_actor : old_grab_actor,
                                      entry->coords,
                                      CLUTTER_CURRENT_TIME);
-      _clutter_actor_handle_event (deepmost, topmost, event);
+      if (!_clutter_event_process_filters (event))
+        _clutter_actor_handle_event (deepmost, topmost, event);
       clutter_event_free (event);
     }
 }
diff --git a/src/core/events.c b/src/core/events.c
index 8afc720efd..f77c45d0c1 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -66,6 +66,15 @@ stage_has_key_focus (void)
   return clutter_stage_get_key_focus (CLUTTER_STAGE (stage)) == stage;
 }
 
+static gboolean
+stage_has_grab (void)
+{
+  MetaBackend *backend = meta_get_backend ();
+  ClutterActor *stage = meta_backend_get_stage (backend);
+
+  return clutter_stage_get_grab_actor (CLUTTER_STAGE (stage)) != NULL;
+}
+
 static MetaWindow *
 get_window_for_event (MetaDisplay        *display,
                       const ClutterEvent *event)
@@ -207,6 +216,17 @@ meta_display_handle_event (MetaDisplay        *display,
   MetaGestureTracker *gesture_tracker;
   ClutterEventSequence *sequence;
 
+  if (meta_is_wayland_compositor () &&
+      (event->type == CLUTTER_ENTER ||
+       event->type == CLUTTER_LEAVE) &&
+      (event->any.flags & CLUTTER_EVENT_FLAG_GRAB_NOTIFY) != 0)
+    {
+      meta_display_sync_wayland_input_focus (display);
+
+      if (event->type == CLUTTER_LEAVE)
+        meta_display_cancel_touch (display);
+    }
+
   sequence = clutter_event_get_event_sequence (event);
 
   /* Set the pointer emulating sequence on touch begin, if eligible */
@@ -393,6 +413,13 @@ meta_display_handle_event (MetaDisplay        *display,
       goto out;
     }
 
+  if (stage_has_grab ())
+    {
+      bypass_wayland = TRUE;
+      bypass_clutter = FALSE;
+      goto out;
+    }
+
   if (window)
     {
       /* Events that are likely to trigger compositor gestures should
@@ -463,6 +490,7 @@ meta_display_handle_event (MetaDisplay        *display,
     }
 
  out:
+
   /* If the compositor has a grab, don't pass that through to Wayland */
   if (display->event_route == META_EVENT_ROUTE_COMPOSITOR_GRAB)
     bypass_wayland = TRUE;
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index abd779ad79..15b1cab906 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -249,8 +249,10 @@ sync_focus_surface (MetaWaylandPointer *pointer)
   MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
   ClutterBackend *clutter_backend = clutter_get_default_backend ();
   ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
+  ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
 
   if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) &&
+      clutter_stage_get_grab_actor (stage) != NULL &&
       !clutter_seat_is_unfocus_inhibited (clutter_seat))
     {
       meta_wayland_pointer_set_focus (pointer, NULL);
@@ -422,10 +424,14 @@ default_grab_focus (MetaWaylandPointerGrab *grab,
   MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
   ClutterBackend *clutter_backend = clutter_get_default_backend ();
   ClutterSeat *clutter_seat = clutter_backend_get_default_seat (clutter_backend);
+  ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
 
   if (!meta_wayland_seat_has_pointer (seat))
     return;
 
+  if (clutter_stage_get_grab_actor (stage) != NULL)
+    return;
+
   if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) &&
       !clutter_seat_is_unfocus_inhibited (clutter_seat))
     return;
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 51e4e7d5d4..8d4b9c942c 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -549,6 +549,14 @@ sync_focus_surface (MetaWaylandTabletTool *tool,
                     const ClutterEvent    *event)
 {
   MetaDisplay *display = meta_get_display ();
+  MetaBackend *backend = meta_get_backend ();
+  ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
+
+  if (clutter_stage_get_grab_actor (stage))
+    {
+      meta_wayland_tablet_tool_set_focus (tool, NULL, event);
+      return;
+    }
 
   switch (display->event_route)
     {


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