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




commit 2b22e19679c887a73e2f2db57ce7029fb8ce25dc
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        |  3 ++-
 src/compositor/compositor-private.h    |  3 +++
 src/compositor/compositor.c            |  4 ++--
 src/core/display-private.h             |  1 +
 src/core/events.c                      | 40 ++++++++++++++++++++++++++++++++++
 src/wayland/meta-wayland-pointer.c     | 10 +++++++--
 src/wayland/meta-wayland-tablet-tool.c |  8 +++++++
 7 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 4506be95a8..df1fadcb1a 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -3659,7 +3659,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/compositor/compositor-private.h b/src/compositor/compositor-private.h
index 580618e481..4e4194f127 100644
--- a/src/compositor/compositor-private.h
+++ b/src/compositor/compositor-private.h
@@ -82,6 +82,9 @@ gboolean meta_compositor_is_switching_workspace (MetaCompositor *compositor);
 
 MetaLaters * meta_compositor_get_laters (MetaCompositor *compositor);
 
+void meta_compositor_grab_begin (MetaCompositor *compositor);
+void meta_compositor_grab_end (MetaCompositor *compositor);
+
 /*
  * This function takes a 64 bit time stamp from the monotonic clock, and clamps
  * it to the scope of the X server clock, without losing the granularity.
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index ee6be007b8..f33dacefcb 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -374,13 +374,13 @@ grab_devices (MetaModalOptions  options,
   return FALSE;
 }
 
-static void
+void
 meta_compositor_grab_begin (MetaCompositor *compositor)
 {
   META_COMPOSITOR_GET_CLASS (compositor)->grab_begin (compositor);
 }
 
-static void
+void
 meta_compositor_grab_end (MetaCompositor *compositor)
 {
   META_COMPOSITOR_GET_CLASS (compositor)->grab_end (compositor);
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 8efac0b492..6b7821412a 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -197,6 +197,7 @@ struct _MetaDisplay
 
   /* Opening the display */
   unsigned int display_opening : 1;
+  unsigned int grabbed_in_clutter : 1;
 
   /* Closing down the display */
   int closing;
diff --git a/src/core/events.c b/src/core/events.c
index 60fb91233c..cecb80bfa8 100644
--- a/src/core/events.c
+++ b/src/core/events.c
@@ -28,6 +28,7 @@
 #include "backends/meta-idle-manager.h"
 #include "backends/x11/meta-backend-x11.h"
 #include "backends/x11/meta-input-device-x11.h"
+#include "compositor/compositor-private.h"
 #include "compositor/meta-window-actor-private.h"
 #include "core/display-private.h"
 #include "core/window-private.h"
@@ -67,6 +68,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 +217,29 @@ meta_display_handle_event (MetaDisplay        *display,
   G_GNUC_UNUSED gboolean bypass_wayland = FALSE;
   MetaGestureTracker *gesture_tracker;
   ClutterEventSequence *sequence;
+  gboolean has_grab = stage_has_grab ();
+
+  if (display->grabbed_in_clutter != has_grab)
+    {
+      MetaCompositor *compositor = meta_display_get_compositor (display);
+
+#ifdef HAVE_WAYLAND
+      if (meta_is_wayland_compositor ())
+        meta_display_sync_wayland_input_focus (display);
+#endif
+
+      if (!display->grabbed_in_clutter && has_grab)
+        {
+          display->grabbed_in_clutter = TRUE;
+          meta_display_cancel_touch (display);
+          meta_compositor_grab_begin (compositor);
+        }
+      else if (display->grabbed_in_clutter && !has_grab)
+        {
+          display->grabbed_in_clutter = FALSE;
+          meta_compositor_grab_end (compositor);
+        }
+    }
 
   sequence = clutter_event_get_event_sequence (event);
 
@@ -394,6 +427,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
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index 62708f162f..ee88f9bfd0 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -269,9 +269,11 @@ 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_seat_is_unfocus_inhibited (clutter_seat))
+  if (clutter_stage_get_grab_actor (stage) != NULL ||
+      (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) &&
+       !clutter_seat_is_unfocus_inhibited (clutter_seat)))
     {
       meta_wayland_pointer_set_focus (pointer, NULL);
       return;
@@ -442,10 +444,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 4e24f8cbee..7d84271159 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -550,6 +550,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]