aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/appearance/TransitionPick.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-06 17:42:18 +0100
committerDanilo M. <danix@danix.xyz>2026-11-06 17:42:18 +0100
commit187682aa4bd212632204d23706c5cb317028b5d3 (patch)
treeab30ae7394eedbfa007a2f7e9a2fb3ed1a55266b /desktop/modules/appearance/TransitionPick.js
parent2ae4deaf7ac420ad5871e3957fb027a856ce7edf (diff)
downloadquickshell-187682aa4bd212632204d23706c5cb317028b5d3.tar.gz
quickshell-187682aa4bd212632204d23706c5cb317028b5d3.zip
wallpaper: choose a transition, by name or at random
A named pick plays as it is; random draws from the ticked pool and skips what played last while anything else is there. Saved values are checked here too, so a stale or hand-edited name lands on something playable. A JS library rather than QML, to test it under node as Shuffle.js is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/appearance/TransitionPick.js')
-rw-r--r--desktop/modules/appearance/TransitionPick.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/desktop/modules/appearance/TransitionPick.js b/desktop/modules/appearance/TransitionPick.js
new file mode 100644
index 0000000..3a8b11a
--- /dev/null
+++ b/desktop/modules/appearance/TransitionPick.js
@@ -0,0 +1,32 @@
+.pragma library
+
+// 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.
+
+// Which transition plays, tested by test_transitions.js under node.
+
+// The name for a run. `pick` is a name or "random"; `pool` is what random may
+// draw; `last` is what played last, skipped while there is anything else.
+function choose(pick, pool, last) {
+ if (pick !== "random") return pick;
+ const from = pool.length > 1 ? pool.filter(n => n !== last) : pool;
+ return from.length ? from[Math.floor(Math.random() * from.length)] : "burn";
+}
+
+// What was saved, made safe against `names`. Nothing saved ticks everything;
+// a pool is kept in the order of `names`, so two can be compared as strings.
+function clean(saved, names) {
+ const s = saved && typeof saved === "object" ? saved : {};
+ return {
+ pick: s.pick === "random" || names.indexOf(s.pick) >= 0 ? s.pick : "burn",
+ pool: Array.isArray(s.pool) ? names.filter(n => s.pool.indexOf(n) >= 0) : names,
+ };
+}