aboutsummaryrefslogtreecommitdiffstats
path: root/window-switcher/test_expose.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-15 10:24:27 +0200
committerDanilo M. <danix@danix.xyz>2026-10-15 10:24:27 +0200
commitfcd5d1c48e5993c9b452bfe824900d9a80df78c3 (patch)
treebe89d9de38b796e9a78c77699aa2510452dd32f2 /window-switcher/test_expose.js
parent875bda45d04004815bb89e3e9f735af439e7fefd (diff)
downloadquickshell-fcd5d1c48e5993c9b452bfe824900d9a80df78c3.tar.gz
quickshell-fcd5d1c48e5993c9b452bfe824900d9a80df78c3.zip
feat(window-switcher): the expose scatter layout
layout() seeds windows on a golden-angle spiral, most recent at the centre, pushes overlapping pairs apart along the axis that costs less screen, and fits the result with one scale so sizes stay relative. The spec's first seed, the windows' real positions, was prototyped and dropped: every window on this desk fills its monitor, so they started in one pile, and pushing a pile apart made a line that still overlapped after 300 passes and filled 8 to 15% of the screen. The spiral converged in 1 to 55 passes. Comparing overlaps in raw pixels stacked wide windows into a column, which is why the axis choice divides by the screen's width and height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'window-switcher/test_expose.js')
-rw-r--r--window-switcher/test_expose.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/window-switcher/test_expose.js b/window-switcher/test_expose.js
new file mode 100644
index 0000000..d394253
--- /dev/null
+++ b/window-switcher/test_expose.js
@@ -0,0 +1,59 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Run: node window-switcher/test_expose.js
+// Expose.js is a QML library, so its .pragma line is stripped before node
+// evaluates it, as test_perf.js does for Perf.js.
+
+const fs = require("fs");
+const assert = require("assert");
+
+const src = fs.readFileSync(__dirname + "/Expose.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const { layout } = new Function(src + "\nreturn { layout };")();
+
+const W = 2560, H = 1080;
+const wide = { w: 2556, h: 1076 }, tall = { w: 1076, h: 1916 };
+
+function apart(a, b) {
+ return a.x + a.w <= b.x || b.x + b.w <= a.x || a.y + a.h <= b.y || b.y + b.h <= a.y;
+}
+function check(out) {
+ for (const o of out) {
+ assert.ok(o.x >= 0 && o.y >= 0 && o.x + o.w <= W + 1e-6 && o.y + o.h <= H + 1e-6, "inside the screen");
+ }
+ for (let i = 0; i < out.length; i++)
+ for (let j = i + 1; j < out.length; j++)
+ assert.ok(apart(out[i], out[j]), `windows ${i} and ${j} overlap`);
+}
+
+assert.deepStrictEqual(layout([], W, H), []);
+
+// Seven identical full-screen windows, the normal case here: no overlap.
+const seven = Array(7).fill(wide);
+check(layout(seven, W, H));
+
+// A busy mixed desk still separates within the pass limit.
+check(layout(Array.from({ length: 14 }, (_, i) => i % 3 ? wide : tall), W, H));
+
+// Deterministic: the same input gives the same scatter.
+assert.deepStrictEqual(layout(seven, W, H), layout(seven, W, H));
+
+// A lone window is capped at half size.
+const one = layout([wide], W, H)[0];
+assert.ok(Math.abs(one.w - wide.w * 0.5) < 1e-6);
+
+// One scale for all: sizes stay relative.
+const [a, b] = layout([wide, tall], W, H);
+assert.ok(Math.abs(a.w / b.w - wide.w / tall.w) < 1e-9);
+assert.ok(Math.abs(a.h / b.h - wide.h / tall.h) < 1e-9);
+
+console.log("test_expose: ok");