From e74573e1650eaa7cfa1894ed9b7a19376af14ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 23 Feb 2023 19:57:43 +0100 Subject: [PATCH] window: Add raise_and_make_recent() method After !2489, the active workspace's MRU list is now used to pick the next focus window instead of the stack order. This list is currently only updated on focus, which can lead to surprising behavior when closing a window after activating its ShellApp in the shell. That is because raising a window (as part of shell_app_activate()) will only change the stacking order, so when closing the active app window, the focus will switch to whatever had focus before the app was activated, not the app's next window. In order to allow gnome-shell to address this, add a new raise_and_make_recent() method that also adjust the MRU order. https://gitlab.gnome.org/GNOME/mutter/-/issues/2540 Part-of: --- src/core/window.c | 45 +++++++++++++++++++++++++++++---------------- src/meta/window.h | 3 +++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/core/window.c b/src/core/window.c index 2ec62c22c..3c99fe18f 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -4571,6 +4571,25 @@ meta_window_transient_can_focus (MetaWindow *window) return TRUE; } +static void +meta_window_make_most_recent (MetaWindow *window) { + MetaWorkspaceManager *workspace_manager = window->display->workspace_manager; + GList *l; + + for (l = workspace_manager->workspaces; l != NULL; l = l->next) + { + MetaWorkspace *workspace = l->data; + GList *link; + + link = g_list_find (workspace->mru_list, window); + if (!link) + continue; + + workspace->mru_list = g_list_delete_link (workspace->mru_list, link); + workspace->mru_list = g_list_prepend (workspace->mru_list, window); + } +} + /* XXX META_EFFECT_FOCUS */ void meta_window_focus (MetaWindow *window, @@ -4651,22 +4670,7 @@ meta_window_focus (MetaWindow *window, if (workspace_manager->active_workspace && meta_window_located_on_workspace (window, workspace_manager->active_workspace)) - { - GList *l; - - for (l = workspace_manager->workspaces; l != NULL; l = l->next) - { - MetaWorkspace *workspace = l->data; - GList *link; - - link = g_list_find (workspace->mru_list, window); - if (!link) - continue; - - workspace->mru_list = g_list_delete_link (workspace->mru_list, link); - workspace->mru_list = g_list_prepend (workspace->mru_list, window); - } - } + meta_window_make_most_recent (window); backend = backend_from_window (window); stage = CLUTTER_STAGE (meta_backend_get_stage (backend)); @@ -5013,6 +5017,15 @@ meta_window_raise (MetaWindow *window) g_signal_emit (window, window_signals[RAISED], 0); } +void +meta_window_raise_and_make_recent (MetaWindow *window) +{ + g_return_if_fail (META_IS_WINDOW (window)); + + meta_window_raise (window); + meta_window_make_most_recent (window); +} + void meta_window_lower (MetaWindow *window) { diff --git a/src/meta/window.h b/src/meta/window.h index 7da886ab2..2380d5912 100644 --- a/src/meta/window.h +++ b/src/meta/window.h @@ -315,6 +315,9 @@ META_EXPORT void meta_window_lower_with_transients (MetaWindow *window, uint32_t timestamp); +META_EXPORT +void meta_window_raise_and_make_recent (MetaWindow *window); + META_EXPORT const char *meta_window_get_title (MetaWindow *window);