Skip to content

Commit 8069298

Browse files
WorkspaceManager: Exclude a window that's about to be removed from count (#2160)
Co-authored-by: Leo <[email protected]>
1 parent c8800bb commit 8069298

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/Utils.vala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,20 @@ namespace Gala {
266266

267267
/**
268268
* Get the number of toplevel windows on a workspace excluding those that are
269-
* on all workspaces
269+
* on all workspaces.
270+
*
271+
* We need `exclude` here because on Meta.Workspace.window_removed
272+
* the windows gets removed from workspace's internal window list but not display's window list
273+
* which Meta.Workspace uses for Meta.Workspace.list_windows ().
270274
*
271275
* @param workspace The workspace on which to count the windows
276+
* @param exclude a window to not count
277+
*
272278
*/
273-
public static uint get_n_windows (Meta.Workspace workspace, bool on_primary = false) {
279+
public static uint get_n_windows (Meta.Workspace workspace, bool on_primary = false, Meta.Window? exclude = null) {
274280
var n = 0;
275281
foreach (unowned var window in workspace.list_windows ()) {
276-
if (window.on_all_workspaces) {
282+
if (window.on_all_workspaces || window == exclude) {
277283
continue;
278284
}
279285

src/WorkspaceManager.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ namespace Gala {
156156
// or we are in modal-mode
157157
if ((!is_active_workspace || wm.is_modal ())
158158
&& remove_freeze_count < 1
159-
&& Utils.get_n_windows (workspace, true) == 0
159+
&& Utils.get_n_windows (workspace, true, window) == 0
160160
&& workspace != last_workspace) {
161161
remove_workspace (workspace);
162162
}
163163

164164
// if window is the second last and empty, make it the last workspace
165165
if (is_active_workspace
166166
&& remove_freeze_count < 1
167-
&& Utils.get_n_windows (workspace, true) == 0
167+
&& Utils.get_n_windows (workspace, true, window) == 0
168168
&& workspace.index () == last_workspace_index - 1) {
169169
remove_workspace (last_workspace);
170170
}

0 commit comments

Comments
 (0)