diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-16 11:02:00 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-16 11:02:00 +0100 |
| commit | acc837d722d6905b47f0b673b84b02345867fb6e (patch) | |
| tree | 21767eeb3f63a695cb0570ec23c1ddac31129b14 /desktop/modules/appearance/test_wallcolors.js | |
| parent | 42788ad568e5b600c2dfd11feb2bf7942cf6d584 (diff) | |
| download | quickshell-acc837d722d6905b47f0b673b84b02345867fb6e.tar.gz quickshell-acc837d722d6905b47f0b673b84b02345867fb6e.zip | |
feat(wallpapers): filter by colour, one folder open at a time
A row of colour circles under the mock screens filters the thumbnails
to the wallpapers a colour dominates; a second click clears it, and
folders left empty drop out. magick quantizes a 64 px copy of each
image to six colours, in parallel, and WallColors.js files every colour
under a hue bucket, or dark or light when it has little saturation.
Each image matches one bucket only: the largest colour bucket when it
covers a quarter of the image, else the larger of dark and light.
Matching any bucket over a fifth mixed a red sunset in with blue skies.
Saturation is HSV's, since HSL reads a pale lavender as strongly
coloured. The raw colours are cached by path in
~/.cache/keystone/wallcolors.tsv, so only new files are analysed; the
first run over 843 images took about 20 seconds.
The circles use fixed colours rather than the theme's: they name hue
buckets that do not move with the scheme, and the live scheme reused
one colour under several names, drawing three pairs of twin circles.
Opening a folder now folds whichever was open. A filter that empties
the open folder folds it for real and opens the first folder with
matches; merely hidden, it came back beside the next one opened once
the filter was cleared.
Run: node desktop/modules/appearance/test_wallcolors.js
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/appearance/test_wallcolors.js')
| -rw-r--r-- | desktop/modules/appearance/test_wallcolors.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/desktop/modules/appearance/test_wallcolors.js b/desktop/modules/appearance/test_wallcolors.js new file mode 100644 index 0000000..aa05b61 --- /dev/null +++ b/desktop/modules/appearance/test_wallcolors.js @@ -0,0 +1,47 @@ +// 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 desktop/modules/appearance/test_wallcolors.js +// WallColors.js is a QML library, so its .pragma line is stripped before node +// evaluates it. + +const fs = require("fs"); +const assert = require("assert"); + +const src = fs.readFileSync(__dirname + "/WallColors.js", "utf8").replace(/^\.pragma library$/m, ""); +const C = new Function(src + "\nreturn { bucket, parse, matches, dominant };")(); + +assert.strictEqual(C.bucket("#ed8796"), "red"); +assert.strictEqual(C.bucket("#f5a97f"), "peach"); +assert.strictEqual(C.bucket("#eed49f"), "yellow"); +assert.strictEqual(C.bucket("#a6da95"), "green"); +assert.strictEqual(C.bucket("#8bd5ca"), "teal"); +assert.strictEqual(C.bucket("#8aadf4"), "blue"); +assert.strictEqual(C.bucket("#2a3a6a"), "blue"); // navy, dark but coloured +assert.strictEqual(C.bucket("#c6a0f6"), "mauve"); +assert.strictEqual(C.bucket("#181926"), "dark"); +assert.strictEqual(C.bucket("#cad3f5"), "light"); +assert.strictEqual(C.bucket("#808080"), ""); // mid grey: no bucket + +const f = C.parse("#8aadf4:30,#181926:60,#808080:10"); +assert.ok(Math.abs(f.blue - 0.3) < 1e-9 && Math.abs(f.dark - 0.6) < 1e-9); +// One bucket per image: blue covers over a quarter, so it wins over the +// larger dark. +assert.ok(C.matches(f, "blue") && !C.matches(f, "dark")); +assert.ok(!C.matches(f, "red") && !C.matches(undefined, "blue")); +// Two colours: the larger wins, the smaller does not match. +const sunset = C.parse("#8aadf4:60,#ed8796:30,#181926:10"); +assert.ok(C.matches(sunset, "blue") && !C.matches(sunset, "red")); +// No colour covers a quarter: dark or light decides. +assert.strictEqual(C.dominant(C.parse("#ed8796:10,#181926:60,#cad3f5:30")), "dark"); +assert.strictEqual(C.dominant(C.parse("#808080:1")), ""); + +console.log("ok"); |
