aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/appearance/Wallpapers.qml
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-16 11:02:00 +0100
committerDanilo M. <danix@danix.xyz>2026-11-16 11:02:00 +0100
commitacc837d722d6905b47f0b673b84b02345867fb6e (patch)
tree21767eeb3f63a695cb0570ec23c1ddac31129b14 /desktop/modules/appearance/Wallpapers.qml
parent42788ad568e5b600c2dfd11feb2bf7942cf6d584 (diff)
downloadquickshell-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/Wallpapers.qml')
-rw-r--r--desktop/modules/appearance/Wallpapers.qml71
1 files changed, 70 insertions, 1 deletions
diff --git a/desktop/modules/appearance/Wallpapers.qml b/desktop/modules/appearance/Wallpapers.qml
index 2b8faf7..f24aca4 100644
--- a/desktop/modules/appearance/Wallpapers.qml
+++ b/desktop/modules/appearance/Wallpapers.qml
@@ -15,6 +15,7 @@ import Quickshell
import Quickshell.Io
import QtQuick
import "../.."
+import "WallColors.js" as WallColors
// The wallpaper side. Setting one is `wallp`'s job: it knows about the two
// outputs, the saved state and the accent run, and none of that is worth
@@ -93,6 +94,70 @@ Singleton {
sizeProc.running = false;
sizeProc.command = ["sh", "-c", 'printf "%s\\0" "$@" | xargs -0 -r file -N -0', "sh"].concat(root.files);
sizeProc.running = true;
+ root.analyse();
+ }
+ }
+ }
+
+ // Each image's six main colours, for the page's colour filter
+ // (WallColors.js), as fractions by bucket. magick quantizes a 64 px copy,
+ // decoded small with jpeg:size, in parallel; each child prints its line
+ // in one write, so lines do not interleave on the pipe. The raw lines are
+ // cached by path in colorCache: only new files are analysed. An upscale
+ // rewrites a file in place but keeps its colours, so the path is the key.
+ property var colors: ({})
+ property var colorLines: ({})
+ property string colorFilter: ""
+ readonly property bool analysing: colorProc.running
+ readonly property string colorCache:
+ (Quickshell.env("XDG_CACHE_HOME") || home + "/.cache") + "/keystone/wallcolors.tsv"
+
+ function analyse() {
+ if (!colorViewReady) return; // the cache read calls again
+ const missing = files.filter(f => !(f in colorLines));
+ if (missing.length === 0 || colorProc.running) return;
+ colorProc.command = ["sh", "-c",
+ `printf '%s\\0' "$@" | xargs -0 -r -P"$(nproc)" -n1 sh -c '` +
+ `c=$(magick -define jpeg:size=256x256 "$1[0]" -alpha off -resize 64x64 -colors 6 ` +
+ `-format %c histogram:info: 2>/dev/null | sort -rn | ` +
+ `awk "{sub(\\":\\",\\"\\",\\$1); printf \\"%s%s:%s\\", s, substr(\\$3,1,7), \\$1; s=\\",\\"}"); ` +
+ `printf "%s\\t%s\\n" "$1" "$c"' sh`, "sh"].concat(missing);
+ colorProc.running = true;
+ }
+
+ // Raw cache lines to colorLines and colors, reassigned whole so bindings
+ // see the change.
+ function takeColors(text) {
+ const lines = Object.assign({}, colorLines), cols = Object.assign({}, colors);
+ for (const line of text.split("\n")) {
+ const t = line.indexOf("\t");
+ if (t < 0) continue;
+ const p = line.slice(0, t), c = line.slice(t + 1);
+ lines[p] = c;
+ cols[p] = WallColors.parse(c);
+ }
+ colorLines = lines;
+ colors = cols;
+ }
+
+ FileView {
+ id: colorView
+ path: root.colorCache
+ printErrors: false // absent until the first analysis
+ onLoaded: { root.takeColors(text()); root.colorViewReady = true; root.analyse(); }
+ onLoadFailed: { root.colorViewReady = true; root.analyse(); }
+ }
+ property bool colorViewReady: false
+
+ Process {
+ id: colorProc
+ stdout: StdioCollector {
+ onStreamFinished: {
+ root.takeColors(text);
+ let out = "";
+ for (const p in root.colorLines) out += `${p}\t${root.colorLines[p]}\n`;
+ // Never empty: analyse ran only with files to add.
+ colorView.setText(out);
}
}
}
@@ -249,7 +314,11 @@ Singleton {
// `expanded` is indexed by, so a local folder named "system" stays apart.
readonly property var groups: {
const local = {}, system = [], plasma = {};
- for (const f of files) {
+ // With a colour picked, only the images it dominates; one not yet
+ // analysed is left out until it is.
+ const shownFiles = colorFilter === "" ? files
+ : files.filter(f => WallColors.matches(colors[f], colorFilter));
+ for (const f of shownFiles) {
if (f.startsWith(dir + "/")) {
const rel = f.slice(dir.length + 1);
const key = rel.includes("/") ? rel.slice(0, rel.indexOf("/")) : "";