]> Freerunner's - simpledwindle.git/commitdiff
bugfix: reorder the tree, if a window is moved to another workspace manually
authorAndre Ramnitz <andre.ramnitz@mail.de>
Tue, 20 Oct 2026 18:14:18 +0000 (20:14 +0200)
committerAndre Ramnitz <andre.ramnitz@mail.de>
Tue, 20 Oct 2026 18:14:18 +0000 (20:14 +0200)
contents/code/main.js

index 946f2c6125106554e53bca2f18b0d7dfdcaa1abd..bb1e30bb70c9a3ac43a8dccffb5ed28432331132 100644 (file)
@@ -2,7 +2,7 @@
 
 // SimpleDwindle
 // KWin 6.8 - Minimal chronological Dwindle
-const VERSION = "0.5.0";
+const VERSION = "0.5.1";
 
 // ------------------------------------------------------------
 // Configuration
@@ -655,6 +655,14 @@ function watchWindow(w) {
     w.minimizedChanged.connect(function() {
         handleMinimized(w);
     });
+
+    w.desktopsChanged.connect(function() {
+        handleWindowLocationChanged(w);
+    });
+
+    w.outputChanged.connect(function() {
+        handleWindowLocationChanged(w);
+    });
 }
 
 function handleWindowAdded(w) {
@@ -684,6 +692,50 @@ function handleWindowAdded(w) {
     tileWindow(w);
 }
 
+// Reconcile a tiled window after KWin moves it to another desktop/output.
+// The old tree is identified by membership, not by the window's new desktop.
+function handleWindowLocationChanged(w) {
+    if (!contains(managed, w))
+        return;
+
+    const oldLayout = findWindowLayout(w);
+    if (!oldLayout)
+        return;
+
+    const desktop = w.desktops.length
+        ? w.desktops[0]
+        : workspace.currentDesktop;
+
+    if (oldLayout.desktop === desktop && oldLayout.output === w.output)
+        return;
+
+    removeNode(oldLayout, w);
+    normalizeSplits(oldLayout.root);
+    arrange(oldLayout);
+
+    // Only join a destination that already has a tiled tree.
+    const target = layouts.find(l =>
+        l.desktop === desktop &&
+        l.output === w.output &&
+        l.root !== null
+    );
+
+    if (target) {
+        insertWindow(target, w);
+        normalizeSplits(target.root);
+        arrange(target);
+        log("MOVED/TILED: " + w.caption);
+    } else {
+        removeFromList(managed, w);
+        removeFromList(suspended, w);
+        if (!contains(floating, w))
+            floating.push(w);
+
+        w.keepBelow = false;
+        log("MOVED/FLOATING: " + w.caption);
+    }
+}
+
 function handleWindowRemoved(w) {
     detachWindow(w);