Skip to content

Commit

Permalink
WorkspaceManager: count windows on primary monitor only (#1789)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter authored Oct 30, 2023
1 parent 5181cc3 commit 82b60f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions data/gala.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ul>
<li>Changing the wallpaper or going to sleep respects the "Reduce Motion" option</li>
<li>Use appropriate drag-and-drop pointers when moving windows</li>
<li>Improve dynamic workspaces behaviour with multiple monitors</li>
<li>Updated translations</li>
</ul>
</description>
Expand Down
16 changes: 10 additions & 6 deletions lib/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ namespace Gala {
*
* @param workspace The workspace on which to count the windows
*/
public static uint get_n_windows (Meta.Workspace workspace) {
public static uint get_n_windows (Meta.Workspace workspace, bool on_primary = false) {
var n = 0;
foreach (weak Meta.Window window in workspace.list_windows ()) {
if (window.on_all_workspaces)
foreach (unowned var window in workspace.list_windows ()) {
if (window.on_all_workspaces) {
continue;
}

if (
window.window_type == Meta.WindowType.NORMAL ||
window.window_type == Meta.WindowType.DIALOG ||
window.window_type == Meta.WindowType.MODAL_DIALOG)
(window.window_type == Meta.WindowType.NORMAL
|| window.window_type == Meta.WindowType.DIALOG
|| window.window_type == Meta.WindowType.MODAL_DIALOG)
&& (!on_primary || (on_primary && window.is_on_primary_monitor ()))) {
n ++;
}
}

return n;
Expand Down
4 changes: 2 additions & 2 deletions src/WorkspaceManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ namespace Gala {
// or we are in modal-mode
if ((!is_active_workspace || wm.is_modal ())
&& remove_freeze_count < 1
&& Utils.get_n_windows (workspace) == 0
&& Utils.get_n_windows (workspace, true) == 0
&& workspace != last_workspace) {
remove_workspace (workspace);
}

// 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) == 0
&& Utils.get_n_windows (workspace, true) == 0
&& workspace.index () == last_workspace_index - 1) {
remove_workspace (last_workspace);
}
Expand Down

0 comments on commit 82b60f1

Please sign in to comment.