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/WallpaperTab.qml | |
| 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/WallpaperTab.qml')
| -rw-r--r-- | desktop/modules/appearance/WallpaperTab.qml | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/desktop/modules/appearance/WallpaperTab.qml b/desktop/modules/appearance/WallpaperTab.qml index 136b24d..cf41a4d 100644 --- a/desktop/modules/appearance/WallpaperTab.qml +++ b/desktop/modules/appearance/WallpaperTab.qml @@ -205,9 +205,59 @@ Column { } } + // The colour filter: a click shows only the wallpapers that carry the + // colour (Wallpapers.colors), a second click shows them all again. + Row { + id: colorRow + spacing: 8 + Text { + anchors.verticalCenter: parent.verticalCenter + text: "Colour" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } + color: Theme.subtext + } + Repeater { + // Fixed colours, not the theme's: they name WallColors.js's hue + // buckets, which do not move with the scheme, and a scheme can + // reuse one colour under several names (one had peach = yellow, + // blue = lavender, mauve = pink, three pairs of twin circles). + model: [ + { key: "red", color: "#ed8796" }, { key: "peach", color: "#f5a97f" }, + { key: "yellow", color: "#eed49f" }, { key: "green", color: "#a6da95" }, + { key: "teal", color: "#8bd5ca" }, { key: "blue", color: "#8aadf4" }, + { key: "mauve", color: "#c6a0f6" }, { key: "dark", color: "#181926" }, + { key: "light", color: "#cad3f5" }, + ] + delegate: Rectangle { + required property var modelData + readonly property bool on: Wallpapers.colorFilter === modelData.key + anchors.verticalCenter: parent.verticalCenter + width: 22 + height: 22 + radius: width / 2 + color: modelData.color + border.width: on ? 3 : swatchHover.hovered ? 2 : 1 + border.color: on ? Theme.accent : Qt.alpha(Theme.text, swatchHover.hovered ? 0.6 : 0.2) + HoverHandler { id: swatchHover } + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: Wallpapers.colorFilter = parent.on ? "" : modelData.key + } + } + } + Text { + anchors.verticalCenter: parent.verticalCenter + visible: Wallpapers.analysing + text: "analysing colours…" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.overlay + } + } + Column { width: parent.width - height: parent.height - mockPane.height - parent.spacing + height: parent.height - mockPane.height - colorRow.height - parent.spacing * 2 spacing: 12 Row { @@ -232,6 +282,8 @@ Column { anchors.verticalCenter: parent.verticalCenter text: Wallpapers.scanning ? "scanning…" : Wallpapers.applying ? "applying…" + : Wallpapers.colorFilter !== "" + ? Wallpapers.groups.reduce((n, g) => n + g.files.length, 0) + " of " + Wallpapers.files.length + " wallpapers" : Wallpapers.files.length + " wallpapers" font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } color: Theme.overlay @@ -268,18 +320,50 @@ Column { return out; } function rebuild() { + // An open folder the colour filter hid is folded for real, + // not just hidden, and unless another is open the first + // folder left opens in its place. Left open, it came back + // beside the next one opened once the filter was cleared. + // Not while the list is empty, before the first scan. + const keys = Wallpapers.groups.map(g => g.key); + const hidden = Object.keys(Wallpapers.expanded) + .filter(k => Wallpapers.expanded[k] && keys.indexOf(k) < 0); + if (keys.length > 0 && hidden.length > 0) { + hidden.forEach(k => Wallpapers.toggle(k)); + if (!keys.some(k => Wallpapers.expanded[k])) Wallpapers.toggle(keys[0]); + } rows.clear(); for (const g of Wallpapers.groups) { rows.append({ key: g.key, start: -1 }); if (Wallpapers.expanded[g.key]) rows.append(rowsOf(g)); } } + // One folder open at a time: opening one first folds any other, + // from the bottom up so the indexes above stay put, then scrolls + // to the new one's header, which a fold above it would move. function toggle(index) { const g = group(rows.get(index).key); const body = rowsOf(g); - if (Wallpapers.expanded[g.key]) rows.remove(index + 1, body.length); - else body.forEach((r, i) => rows.insert(index + 1 + i, r)); + if (Wallpapers.expanded[g.key]) { + rows.remove(index + 1, body.length); + Wallpapers.toggle(g.key); + return; + } + let folded = false; + for (let i = rows.count - 1; i >= 0; i--) { + const r = rows.get(i); + if (r.start >= 0 || r.key === g.key || !Wallpapers.expanded[r.key]) continue; + rows.remove(i + 1, rowsOf(group(r.key)).length); + Wallpapers.toggle(r.key); + if (i < index) folded = true; + } + if (folded) { + index = 0; + while (rows.get(index).key !== g.key) index++; + } + body.forEach((r, i) => rows.insert(index + 1 + i, r)); Wallpapers.toggle(g.key); + if (folded) positionViewAtIndex(index, ListView.Beginning); } // The width settles after creation, and a new column count |
