WorkspaceManager: Exclude a window that's about to be removed from count (#2160)

Co-authored-by: Leo <lenemter@gmail.com>
This commit is contained in:
Leonhard 2024-12-18 20:54:33 +01:00 committed by GitHub
parent c8800bb73d
commit 8069298347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -266,14 +266,20 @@ namespace Gala {
/** /**
* Get the number of toplevel windows on a workspace excluding those that are * 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 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; var n = 0;
foreach (unowned var window in workspace.list_windows ()) { foreach (unowned var window in workspace.list_windows ()) {
if (window.on_all_workspaces) { if (window.on_all_workspaces || window == exclude) {
continue; continue;
} }

View File

@ -156,7 +156,7 @@ namespace Gala {
// or we are in modal-mode // or we are in modal-mode
if ((!is_active_workspace || wm.is_modal ()) if ((!is_active_workspace || wm.is_modal ())
&& remove_freeze_count < 1 && remove_freeze_count < 1
&& Utils.get_n_windows (workspace, true) == 0 && Utils.get_n_windows (workspace, true, window) == 0
&& workspace != last_workspace) { && workspace != last_workspace) {
remove_workspace (workspace); remove_workspace (workspace);
} }
@ -164,7 +164,7 @@ namespace Gala {
// if window is the second last and empty, make it the last workspace // if window is the second last and empty, make it the last workspace
if (is_active_workspace if (is_active_workspace
&& remove_freeze_count < 1 && 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) { && workspace.index () == last_workspace_index - 1) {
remove_workspace (last_workspace); remove_workspace (last_workspace);
} }