[gnome-shell-extensions/wip/fmuellner/fix-auto-move: 6/12] auto-move-windows: Do not copy checkWorkspaces() method



commit 3b6cd04a59bc9616f4873dabe52ec440bc2d17d8
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Dec 22 01:07:06 2017 +0100

    auto-move-windows: Do not copy checkWorkspaces() method
    
    When overriding an upstream method, copying the original method code
    should always be a last resort, as the two code bases tend to get
    out of sync and it often becomes hard to spot the modifications done
    by the override. Both those issues can be avoided when figuring out
    a way to split out the modifications and call the unmodified upstream
    method - we are in luck with our checkWorkspaces() override, as we
    can trick the upstream method into not removing workspaces we want
    to keep instead of copying the method altogether.
    
    https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/33

 extensions/auto-move-windows/extension.js | 65 ++++++-------------------------
 1 file changed, 11 insertions(+), 54 deletions(-)
---
diff --git a/extensions/auto-move-windows/extension.js b/extensions/auto-move-windows/extension.js
index ca9cd90..6bf4b39 100644
--- a/extensions/auto-move-windows/extension.js
+++ b/extensions/auto-move-windows/extension.js
@@ -4,7 +4,6 @@
 const Glib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const Mainloop = imports.mainloop;
-const Meta = imports.gi.Meta;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
 
@@ -85,62 +84,20 @@ function init() {
 }
 
 function myCheckWorkspaces() {
-    let i;
-    let emptyWorkspaces = new Array(this._workspaces.length);
-
-    if (!Meta.prefs_get_dynamic_workspaces()) {
-        this._checkWorkspacesId = 0;
-        return false;
-    }
-
-    for (i = 0; i < this._workspaces.length; i++) {
-        let lastRemoved = this._workspaces[i]._lastRemovedWindow;
-        if ((lastRemoved &&
-             (lastRemoved.get_window_type() == Meta.WindowType.SPLASHSCREEN ||
-              lastRemoved.get_window_type() == Meta.WindowType.DIALOG ||
-              lastRemoved.get_window_type() == Meta.WindowType.MODAL_DIALOG)) ||
-            this._workspaces[i]._keepAliveId)
-            emptyWorkspaces[i] = false;
-        else
-            emptyWorkspaces[i] = true;
-    }
-
-    let sequences = Shell.WindowTracker.get_default().get_startup_sequences();
-    for (i = 0; i < sequences.length; i++) {
-        let index = sequences[i].get_workspace();
-        if (index >= 0 && index <= global.screen.n_workspaces)
-            emptyWorkspaces[index] = false;
-    }
-
-    let windows = global.get_window_actors();
-    for (i = 0; i < windows.length; i++) {
-        let winActor = windows[i];
-        let win = winActor.meta_window;
-        if (win.is_on_all_workspaces())
-            continue;
-
-        let workspaceIndex = win.get_workspace().index();
-        emptyWorkspaces[workspaceIndex] = false;
-    }
-
-    // If we don't have an empty workspace at the end, add one
-    if (!emptyWorkspaces[emptyWorkspaces.length -1]) {
-        global.screen.append_new_workspace(false, global.get_current_time());
-        emptyWorkspaces.push(false);
+    let keepAliveWorkspaces = [];
+    let foundNonEmpty = false;
+    for (let i = this._workspaces.length - 1; i >= 0; i--) {
+        if (!foundNonEmpty)
+            foundNonEmpty = this._workspaces[i].list_windows().length > 0;
+        else if (!this._workspaces[i]._keepAliveId)
+            keepAliveWorkspaces.push(this._workspaces[i]);
     }
 
-    let activeWorkspaceIndex = global.screen.get_active_workspace_index();
-    emptyWorkspaces[activeWorkspaceIndex] = false;
-
-    // Delete other empty workspaces; do it from the end to avoid index changes
-    for (i = emptyWorkspaces.length - 2; i >= 0; i--) {
-        if (emptyWorkspaces[i])
-            global.screen.remove_workspace(this._workspaces[i], global.get_current_time());
-        else
-            break;
-    }
+    // make sure the original method only removes empty workspaces at the end
+    keepAliveWorkspaces.forEach(ws => { ws._keepAliveId = 1; });
+    prevCheckWorkspaces.call(this);
+    keepAliveWorkspaces.forEach(ws => { delete ws._keepAliveId; });
 
-    this._checkWorkspacesId = 0;
     return false;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]