From 1816f21e216d9e8f8fdadddaaad23ae8b3a5a17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Sun, 6 Nov 2022 12:38:35 +0100 Subject: [PATCH] window: Avoid focusing during workspace changes We can land inside meta_window_focus() in the middle of changing the window workspace, because some signal handler of MetaWorkspace's "window-removed" signal triggers a focus. This can cause a crash in `g_assert (link)` when updating the MRU list because we still think we're on the old workspace when actually we are already removed from this workspaces MRU list. To avoid crashes like this, bail out of meta_window_focus() when we're in the middle of a workspace change. Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5368 Part-of: --- src/core/window-private.h | 2 ++ src/core/window.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/window-private.h b/src/core/window-private.h index 186369d53..d7c33f821 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -563,6 +563,8 @@ struct _MetaWindow /* if TRUE, the we have the new form of sync request counter which * also handles application frames */ guint extended_sync_request_counter : 1; + + guint in_workspace_change : 1; }; struct _MetaWindowClass diff --git a/src/core/window.c b/src/core/window.c index 12121b455..e0f42e942 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -4552,6 +4552,14 @@ meta_window_focus (MetaWindow *window, "Setting input focus to window %s, input: %d focusable: %d", window->desc, window->input, meta_window_is_focusable (window)); + if (window->in_workspace_change) + { + meta_topic (META_DEBUG_FOCUS, + "Window %s is currently changing workspaces, not focusing it after all", + window->desc); + return; + } + if (window->display->grab_window && window->display->grab_window != window && window->display->grab_window->all_keys_grabbed && @@ -4671,6 +4679,8 @@ set_workspace_state (MetaWindow *window, !window->constructing) return; + window->in_workspace_change = TRUE; + if (window->workspace) meta_workspace_remove_window (window->workspace, window); else if (window->on_all_workspaces) @@ -4698,6 +4708,8 @@ set_workspace_state (MetaWindow *window, } } + window->in_workspace_change = FALSE; + if (!window->constructing) meta_window_update_appears_focused (window);