From 0a20e8e3179a8155d425084aa020448a9044f63d Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Wed, 11 Dec 2024 21:11:01 +0100 Subject: [PATCH 1/2] WorkspaceManager: Exclude a window that's about to be removed from count --- lib/Utils.vala | 5 +++-- src/WorkspaceManager.vala | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Utils.vala b/lib/Utils.vala index f651d622a..5dfbe2c53 100644 --- a/lib/Utils.vala +++ b/lib/Utils.vala @@ -269,11 +269,12 @@ namespace Gala { * on all workspaces * * @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); } From 4ede6129e3e3a8e2d3a8cc1b566e97f0e89d3a50 Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 18 Dec 2024 22:53:09 +0300 Subject: [PATCH 2/2] Add comment on exclude --- lib/Utils.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Utils.vala b/lib/Utils.vala index 5dfbe2c53..e66f014ac 100644 --- a/lib/Utils.vala +++ b/lib/Utils.vala @@ -266,10 +266,15 @@ 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, Meta.Window? exclude = null) { var n = 0;