Fix: auto move windows and mutliple monitors increasing workspaces number (patch)
Hello.
Auto-Move windows does not work well when you have multiple monitors (at least 2) : in some cases, the number of workspaces just keep growing.
Environment
- Gnome 3.38 on fedora 33
- 2 monitors
Configuration
- auto-move windows enabled
- dynamic workspaces enabled
- workspaces_only_on_primary enabled
Use case
- With auto-move windows extension, define an aplication A to open on workspace 3.
- Open application B and put the window on secondary monitor.
- Open Application A.
- The window of application A goes to workspace 3 on primary monitor. => OK
- There is now 4 workspaces. => OK
- Close application A and come back to workspace 1.
- There is still 4 workspaces. => KO
As i understand the source code, when workspaces are defined only on primary monitor and there is application windows on a secondary monitor, workspaces are not considered empty even if they are empty on the primary monitor.
Patch
Here is the fix I apply to get it work correctly :
diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js
index d99244c..973f956 100644
--- a/extensions/auto-move-windows/extension.js
+++ b/extensions/auto-move-windows/extension.js
@@ -2,7 +2,7 @@
// Start apps on custom workspaces
/* exported init enable disable */
-const { Shell } = imports.gi;
+const { Meta, Shell } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Main = imports.ui.main;
@@ -113,13 +113,20 @@ function init() {
}
function myCheckWorkspaces() {
- let keepAliveWorkspaces = [];
+ const onlyOnPrimary = Meta.prefs_get_workspaces_only_on_primary();
+ const keepAliveWorkspaces = [];
let foundNonEmpty = false;
for (let i = this._workspaces.length - 1; i >= 0; i--) {
- if (!foundNonEmpty)
+ if (!foundNonEmpty) {
+ // Not enough with multiple monitors
foundNonEmpty = this._workspaces[i].list_windows().length > 0;
- else if (!this._workspaces[i]._keepAliveId)
+ // Check if all windows are in primary monitor
+ if (foundNonEmpty && onlyOnPrimary) {
+ foundNonEmpty = this._workspaces[i].list_windows().some(window => window.is_on_primary_monitor());
+ }
+ } else if (!this._workspaces[i]._keepAliveId) {
keepAliveWorkspaces.push(this._workspaces[i]);
+ }
}
// make sure the original method only removes empty workspaces at the end
fix-autom-move-windows-multiple-monitors.diff
I don't know if it is the best way to do that.
Edited by Rui Nibau