From 54e4d1df794e04980237060fa4902a4b98809992 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 19 Dec 2023 13:52:28 +0100 Subject: [PATCH] x11: Defer ClutterStage focus actor change until window is focused If we happen to be changing focus to a window *while* taking focus away from Clutter widgetry, we would unintendedly trigger reentrance in a way that the old focused window remained in focus, by asking to focus the default focus window in an untimely manner. To handle this reentrancy, delay dropping the Clutter key focus until the window focus changed, so that the focus change will look up the default focused window in the workspace, and find the up to date one. Fixes: ae102ee3011 ("x11: Refactor ClutterStage key focus management") Part-of: --- src/x11/meta-x11-display.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 9f42c385f..3c3a65061 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -2104,11 +2104,8 @@ meta_x11_display_set_input_focus (MetaX11Display *x11_display, xwindow = window->frame->xwindow; else xwindow = meta_window_x11_get_xwindow (window); - -#ifdef HAVE_X11 - if (!meta_is_wayland_compositor ()) - clutter_stage_set_key_focus (stage, NULL); } +#ifdef HAVE_X11 else if (!meta_is_wayland_compositor () && stage_has_focus_actor (x11_display)) { @@ -2117,8 +2114,6 @@ meta_x11_display_set_input_focus (MetaX11Display *x11_display, */ xwindow = meta_x11_get_stage_window (stage); } -#else - } #endif meta_topic (META_DEBUG_FOCUS, "Setting X11 input focus for window %s to 0x%lx", @@ -2129,6 +2124,11 @@ meta_x11_display_set_input_focus (MetaX11Display *x11_display, serial = XNextRequest (x11_display->xdisplay); meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); mtk_x11_error_trap_pop (x11_display->xdisplay); + +#ifdef HAVE_X11 + if (window && !meta_is_wayland_compositor ()) + clutter_stage_set_key_focus (stage, NULL); +#endif } static MetaX11DisplayLogicalMonitorData *