From: Andre Ramnitz Date: Tue, 20 Oct 2026 18:14:18 +0000 (+0200) Subject: bugfix: reorder the tree, if a window is moved to another workspace manually X-Git-Url: https://git.ramnitz.eu/?a=commitdiff_plain;h=74112b2171a3e971d88c68021b8a35d63d67db98;p=simpledwindle.git bugfix: reorder the tree, if a window is moved to another workspace manually --- diff --git a/contents/code/main.js b/contents/code/main.js index 946f2c6..bb1e30b 100644 --- a/contents/code/main.js +++ b/contents/code/main.js @@ -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);