diff --git a/lib/Utils.vala b/lib/Utils.vala index f651d622a..e66f014ac 100644 --- a/lib/Utils.vala +++ b/lib/Utils.vala @@ -266,14 +266,20 @@ namespace Gala { /** * Get the number of toplevel windows on a workspace excluding those that are - * on all workspaces + * on all workspaces. + * + * We need `exclude` here because on Meta.Workspace.window_removed + * the windows gets removed from workspace's internal window list but not display's window list + * which Meta.Workspace uses for Meta.Workspace.list_windows (). * * @param workspace The workspace on which to count the windows + * @param exclude a window to not count + * */ - public static uint get_n_windows (Meta.Workspace workspace, bool on_primary = false) { + public static uint get_n_windows (Meta.Workspace workspace, bool on_primary = false, Meta.Window? exclude = null) { var n = 0; foreach (unowned var window in workspace.list_windows ()) { - if (window.on_all_workspaces) { + if (window.on_all_workspaces || window == exclude) { continue; } diff --git a/src/WorkspaceManager.vala b/src/WorkspaceManager.vala index 9aa797a37..7d0eb4314 100644 --- a/src/WorkspaceManager.vala +++ b/src/WorkspaceManager.vala @@ -156,7 +156,7 @@ namespace Gala { // or we are in modal-mode if ((!is_active_workspace || wm.is_modal ()) && remove_freeze_count < 1 - && Utils.get_n_windows (workspace, true) == 0 + && Utils.get_n_windows (workspace, true, window) == 0 && workspace != last_workspace) { remove_workspace (workspace); } @@ -164,7 +164,7 @@ namespace Gala { // if window is the second last and empty, make it the last workspace if (is_active_workspace && remove_freeze_count < 1 - && Utils.get_n_windows (workspace, true) == 0 + && Utils.get_n_windows (workspace, true, window) == 0 && workspace.index () == last_workspace_index - 1) { remove_workspace (last_workspace); }