Skip to content

Commit

Permalink
clutter/stage: Turn get_key_focus() into a proper getter
Browse files Browse the repository at this point in the history
The method currently returns the stage itself when the property
is NULL.

This has become particularly problematic as the method is detected
as getter by gobject introspection, and gjs now optimizes property
accesses by calling the getter method instead.

Address this by turning the method into a genuine getter without
falling back to the stage.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4256>
  • Loading branch information
fmuellner committed Feb 14, 2025
1 parent 1d69b1b commit e49edeb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
7 changes: 2 additions & 5 deletions clutter/clutter/clutter-stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ clutter_stage_set_key_focus (ClutterStage *stage,
*
* Retrieves the actor that is currently under key focus.
*
* Return value: (transfer none): the actor with key focus, or the stage
* Return value: (transfer none) (nullable): the actor with key focus
*/
ClutterActor *
clutter_stage_get_key_focus (ClutterStage *stage)
Expand All @@ -2181,10 +2181,7 @@ clutter_stage_get_key_focus (ClutterStage *stage)
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);

priv = clutter_stage_get_instance_private (stage);
if (priv->key_focused_actor)
return priv->key_focused_actor;

return CLUTTER_ACTOR (stage);
return priv->key_focused_actor;
}

/*** Perspective boxed type ******/
Expand Down
6 changes: 0 additions & 6 deletions src/backends/meta-stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ key_focus_actor_changed (ClutterStage *stage,
{
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;

clutter_stage_set_active (stage, key_focus != NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ stage_has_key_focus (MetaDisplay *display)
{
ClutterStage *stage = stage_from_display (display);

return clutter_stage_get_key_focus (stage) == CLUTTER_ACTOR (stage);
return clutter_stage_get_key_focus (stage) == NULL;
}

static gboolean
Expand Down
2 changes: 1 addition & 1 deletion src/x11/meta-x11-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ stage_has_focus_actor (MetaX11Display *x11_display)

key_focus = clutter_stage_get_key_focus (stage);

return key_focus != CLUTTER_ACTOR (stage);
return key_focus != NULL;
}

static void
Expand Down

0 comments on commit e49edeb

Please sign in to comment.