]> Freerunner's - simpledwindle.git/commitdiff
add: uw-monitor-mode, default kb: meta+shift+R
authorAndre Ramnitz <andre.ramnitz@mail.de>
Tue, 20 Oct 2026 18:11:26 +0000 (20:11 +0200)
committerAndre Ramnitz <andre.ramnitz@mail.de>
Tue, 20 Oct 2026 18:11:26 +0000 (20:11 +0200)
contents/code/main.js

index d07e96cf042df549b234b87bbdc3d56a4e46992c..946f2c6125106554e53bca2f18b0d7dfdcaa1abd 100644 (file)
@@ -2,7 +2,7 @@
 
 // SimpleDwindle
 // KWin 6.8 - Minimal chronological Dwindle
-const VERSION = "0.4.0";
+const VERSION = "0.5.0";
 
 // ------------------------------------------------------------
 // Configuration
@@ -132,7 +132,8 @@ function layoutFor(w) {
             output: w.output,
             desktop: desktop,
             root: null,
-            last: null
+            last: null,
+            rootWide: false
         };
 
         layouts.push(layout);
@@ -266,12 +267,12 @@ function removeNode(layout, w) {
     return true;
 }
 
+// Keep alternating split directions after promoting a sibling.
 function normalizeSplits(node, depth = 0) {
     if (!node || node.window)
         return;
 
     node.vertical = (depth % 2 === 0);
-
     normalizeSplits(node.first, depth + 1);
     normalizeSplits(node.second, depth + 1);
 }
@@ -280,13 +281,24 @@ function normalizeSplits(node, depth = 0) {
 // Geometry
 // ------------------------------------------------------------
 
-function applyNode(node, rect) {
+function applyNode(node, rect, rootWide = false, isRoot = true) {
     if (!node)
         return;
 
     if (node.window) {
         const w = node.window;
 
+        // One tiled window: centered at two thirds of the work area.
+        if (isRoot) {
+            const width = rect.width * (2 / 3);
+            rect = {
+                x: rect.x + (rect.width - width) / 2,
+                y: rect.y,
+                width: width,
+                height: rect.height
+            };
+        }
+
         // Fullscreen windows retain their tree position,
         // but KWin controls their geometry.
         if (w.fullScreen || w.minimized)
@@ -317,21 +329,21 @@ function applyNode(node, rect) {
     }
 
     if (node.vertical) {
-        const half = rect.width / 2;
+        const half = rect.width * (isRoot && rootWide ? 2 / 3 : 1 / 2);
 
         applyNode(node.first, {
             x: rect.x,
             y: rect.y,
             width: half,
             height: rect.height
-        });
+        }, rootWide, false);
 
         applyNode(node.second, {
             x: rect.x + half,
             y: rect.y,
             width: rect.width - half,
             height: rect.height
-        });
+        }, rootWide, false);
     } else {
         const half = rect.height / 2;
 
@@ -340,14 +352,14 @@ function applyNode(node, rect) {
             y: rect.y,
             width: rect.width,
             height: half
-        });
+        }, rootWide, false);
 
         applyNode(node.second, {
             x: rect.x,
             y: rect.y + half,
             width: rect.width,
             height: rect.height - half
-        });
+        }, rootWide, false);
     }
 }
 
@@ -361,7 +373,7 @@ function arrange(layout) {
         layout.desktop
     );
 
-    applyNode(layout.root, area);
+    applyNode(layout.root, area, layout.rootWide);
 }
 
 // ------------------------------------------------------------
@@ -369,7 +381,7 @@ function arrange(layout) {
 // ------------------------------------------------------------
 
 // Use tree-assigned rectangles, not asynchronous frameGeometry updates.
-function collectLeaves(node, rect, result) {
+function collectLeaves(node, rect, result, rootWide = false, isRoot = true) {
     if (!node)
         return;
 
@@ -379,25 +391,25 @@ function collectLeaves(node, rect, result) {
     }
 
     if (node.vertical) {
-        const half = rect.width / 2;
+        const half = rect.width * (isRoot && rootWide ? 2 / 3 : 1 / 2);
         collectLeaves(node.first, {
             x: rect.x, y: rect.y,
             width: half, height: rect.height
-        }, result);
+        }, result, rootWide, false);
         collectLeaves(node.second, {
             x: rect.x + half, y: rect.y,
             width: rect.width - half, height: rect.height
-        }, result);
+        }, result, rootWide, false);
     } else {
         const half = rect.height / 2;
         collectLeaves(node.first, {
             x: rect.x, y: rect.y,
             width: rect.width, height: half
-        }, result);
+        }, result, rootWide, false);
         collectLeaves(node.second, {
             x: rect.x, y: rect.y + half,
             width: rect.width, height: rect.height - half
-        }, result);
+        }, result, rootWide, false);
     }
 }
 
@@ -410,7 +422,7 @@ function findSwapNeighbor(w, direction) {
         KWin.MaximizeArea, layout.output, layout.desktop
     );
     const leaves = [];
-    collectLeaves(layout.root, area, leaves);
+    collectLeaves(layout.root, area, leaves, layout.rootWide);
 
     const source = leaves.find(item => item.node.window === w);
     if (!source)
@@ -703,6 +715,22 @@ registerShortcut(
     toggleFloating
 );
 
+registerShortcut(
+    "SimpleDwindleToggleRootRatio",
+    "SimpleDwindle: Toggle Root Split Ratio",
+    "Meta+Shift+R",
+    function () {
+        const w = workspace.activeWindow;
+        const layout = w ? findWindowLayout(w) : null;
+        if (!layout)
+            return;
+
+        layout.rootWide = !layout.rootWide;
+        arrange(layout);
+        log("ROOT RATIO: " + (layout.rootWide ? "66.7:33.3" : "50:50"));
+    }
+);
+
 registerShortcut("SimpleDwindleSwapLeft", "SimpleDwindle: Swap Left", "Meta+Shift+H", function() { swapDirection("left"); });
 registerShortcut("SimpleDwindleSwapDown", "SimpleDwindle: Swap Down", "Meta+Shift+J", function() { swapDirection("down"); });
 registerShortcut("SimpleDwindleSwapUp", "SimpleDwindle: Swap Up", "Meta+Shift+K", function() { swapDirection("up"); });