[mutter/wip/carlosg/grabs-pt1: 9/16] clutter: Notify grab changes on the key focus




commit 532c400842ad56bfc6f88be7b445428a11da8336
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 27 18:00:25 2021 +0200

    clutter: Notify grab changes on the key focus
    
    Dissociate clutter_stage_set_key_focus() from the actors focused
    state, so that it obeys stage grabs. The key focus actor state may
    also change due to grab changes, add the code to notify about this.

 clutter/clutter/clutter-stage.c | 48 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 8224179073..d5b483d672 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -2033,13 +2033,22 @@ clutter_stage_set_key_focus (ClutterStage *stage,
    * intended. The order of events would be:
    *   1st focus-out, 2nd focus-out (on stage), 2nd focus-in, 1st focus-in
    */
-  if (actor != NULL)
+  priv->key_focused_actor = actor;
+
+  /* If the key focused actor is allowed to receive key events according
+   * to the given grab (or there is none) set key focus on it, otherwise
+   * key focus is delayed until there are grabbing conditions that allow
+   * it to get key focus.
+   */
+  if (!priv->grabs ||
+      priv->grabs->actor == actor ||
+      clutter_actor_contains (priv->grabs->actor, actor))
     {
-      priv->key_focused_actor = actor;
-      _clutter_actor_set_has_key_focus (actor, TRUE);
+      if (actor != NULL)
+        _clutter_actor_set_has_key_focus (actor, TRUE);
+      else
+        _clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), TRUE);
     }
-  else
-    _clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), TRUE);
 
   g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_KEY_FOCUS]);
 }
@@ -3644,6 +3653,33 @@ clutter_stage_notify_grab_on_entry (ClutterStage       *stage,
     }
 }
 
+static void
+clutter_stage_notify_grab_on_key_focus (ClutterStage *stage,
+                                        ClutterActor *grab_actor,
+                                        ClutterActor *old_grab_actor)
+{
+  ClutterStagePrivate *priv = stage->priv;
+  ClutterActor *key_focus;
+  gboolean focus_in_grab, focus_in_old_grab;
+
+  key_focus = priv->key_focused_actor ?
+    priv->key_focused_actor : CLUTTER_ACTOR (stage);
+
+  focus_in_grab =
+    !grab_actor ||
+    grab_actor == key_focus ||
+    clutter_actor_contains (grab_actor, key_focus);
+  focus_in_old_grab =
+    !old_grab_actor ||
+    old_grab_actor == key_focus ||
+    clutter_actor_contains (old_grab_actor, key_focus);
+
+  if (focus_in_grab && !focus_in_old_grab)
+    _clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), TRUE);
+  else if (!focus_in_grab && focus_in_old_grab)
+    _clutter_actor_set_has_key_focus (CLUTTER_ACTOR (stage), FALSE);
+}
+
 static void
 clutter_stage_notify_grab (ClutterStage *stage,
                            ClutterGrab  *cur,
@@ -3682,6 +3718,8 @@ clutter_stage_notify_grab (ClutterStage *stage,
                                           cur_actor,
                                           old_actor);
     }
+
+  clutter_stage_notify_grab_on_key_focus (stage, cur_actor, old_actor);
 }
 
 ClutterGrab *


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