[mutter] stage: Mark stage as active on wayland when it has key-focus



commit 84396baafb516f56da5ff0fd91f078098ba1fc8f
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Tue Mar 8 14:23:47 2022 +0100

    stage: Mark stage as active on wayland when it has key-focus
    
    The "activate" and "deactivate" signals on ClutterStage are used by
    Cally to track the key-focus when the user is interacting with shell UI.
    key-focus only gets tracked while the stage is activated.
    
    Wayland has no concept of the stage receiving focus or not, so right now
    the activation state is bound to whether there's a focus_window in
    meta_display_sync_wayland_input_focus(). Since display->focus_window is
    set pretty much all the time, this effectively binds activation state to
    whether the stage holds a grab or not. This is almost good enough, but
    it misses cases where key-focus is on the stage without a grab, for
    example when keyboard-navigating the panel after using Ctrl+Alt+Tab.
    
    It seems to make more sense to bind the activation state to whether
    key-focus is set to an actor or to NULL, so let's do that instead.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2329>

 src/backends/meta-stage.c | 23 +++++++++++++++++++++++
 src/core/display.c        |  1 -
 2 files changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/src/backends/meta-stage.c b/src/backends/meta-stage.c
index 107265fa63..f43f4d06e7 100644
--- a/src/backends/meta-stage.c
+++ b/src/backends/meta-stage.c
@@ -331,6 +331,22 @@ meta_stage_class_init (MetaStageClass *klass)
                                           G_TYPE_NONE, 0);
 }
 
+static void
+key_focus_actor_changed (ClutterStage *stage,
+                         GParamSpec   *param,
+                         gpointer      user_data)
+{
+  ClutterActor *key_focus = clutter_stage_get_key_focus (stage);
+
+  /* If there's no explicit key focus, clutter_stage_get_key_focus()
+   * returns the stage.
+   */
+  if (key_focus == CLUTTER_ACTOR (stage))
+    key_focus = NULL;
+
+  meta_stage_set_active (META_STAGE (stage), key_focus != NULL);
+}
+
 static void
 meta_stage_init (MetaStage *stage)
 {
@@ -338,6 +354,13 @@ meta_stage_init (MetaStage *stage)
 
   for (i = 0; i < N_WATCH_MODES; i++)
     stage->watchers[i] = g_ptr_array_new_with_free_func (g_free);
+
+  if (meta_is_wayland_compositor ())
+    {
+      g_signal_connect (stage,
+                        "notify::key-focus",
+                        G_CALLBACK (key_focus_actor_changed), NULL);
+    }
 }
 
 ClutterActor *
diff --git a/src/core/display.c b/src/core/display.c
index 5bb34a65ab..fb92244164 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -1443,7 +1443,6 @@ meta_display_sync_wayland_input_focus (MetaDisplay *display)
   else
     meta_topic (META_DEBUG_FOCUS, "Focus change has no effect, because there is no matching wayland 
surface");
 
-  meta_stage_set_active (stage, focus_window == NULL);
   meta_wayland_compositor_set_input_focus (compositor, focus_window);
 
   clutter_stage_repick_device (CLUTTER_STAGE (stage),


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