Draw a wallpaper's subject outline first when changing to it

helpers/wallfx.py finds the subject with BiRefNet (onnxruntime, CPU),
bakes outline maps per wallpaper and caches them; scans warm the cache in
the background. The transition shader gains an outline mode: the line is
drawn, the subject fills in, then the rest grows out of it. Uncached or
subject-less wallpapers keep the colonies. wallpaper.outlineExclude opts
wallpapers out. The Nix package provides the interpreter and the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-11-08 22:37:33 +01:00
1 parent ad740ef631
commit b6d0da4679
10 files changed
+491 -28

No files matched your search

+1
View File
@@ -96,6 +96,7 @@ function validate(c) {
if(!Number.isInteger(c.metrics.interval) || c.metrics.interval<1 || c.metrics.interval>30)throw Error("Invalid metrics geometry or interval");
if(!Array.isArray(c.metrics.storagePaths) || c.metrics.storagePaths.length>8 || c.metrics.storagePaths.some(p=>typeof p!=="string" || !p.startsWith("/") || p.includes("\u0000")) || new Set(c.metrics.storagePaths).size!==c.metrics.storagePaths.length || typeof c.metrics.networkInterface!=="string" || !c.metrics.networkInterface || typeof c.metrics.gpu!=="string" || !c.metrics.gpu)throw Error("Invalid metrics sources");
if(!Array.isArray(c.wallpaper.history) || c.wallpaper.history.length>50 || c.wallpaper.history.some(p=>typeof p!=="string"))throw Error("Invalid wallpaper history");
if(!Array.isArray(c.wallpaper.outlineExclude) || c.wallpaper.outlineExclude.some(p=>typeof p!=="string"))throw Error("Invalid wallpaper outline exclusions");
if(typeof c.hyprglass.enabled!=="boolean" || typeof c.hyprglass.layers!=="boolean" || typeof c.hyprglass.effectEnabled!=="boolean")throw Error("Invalid glass toggle");
for(const [key,min,max] of [["blur_strength",0,5],["blur_iterations",1,5],["refraction_strength",0,8],["chromatic_aberration",0,1],["fresnel_strength",0,1],["specular_strength",0,1],["edge_thickness",0,.15],["lens_distortion",0,1],["brightness",.2,2],["contrast",.2,2],["saturation",0,2],["vibrancy",0,1],["adaptive_dim",0,1]])if(!Number.isFinite(c.hyprglass.values[key]) || c.hyprglass.values[key]<min || c.hyprglass.values[key]>max)throw Error("Invalid glass "+key);
if(!Number.isInteger(c.hyprglass.values.blur_iterations))throw Error("Invalid blur passes");
+72
View File
@@ -53,6 +53,7 @@ Singleton {
if (!ConfigService.ready || !ConfigService.writable || !outputs.length || !outputs[0] || busy)
return false;
error = "";
prepareTransition(path);
// Native rendering needs no provider round trip: decode once, then switch
// every output in one write so their transitions start together.
if (backend === "native" && ["native", "auto"].includes(ConfigService.data.wallpaper.backend)) {
@@ -106,6 +107,7 @@ Singleton {
onFinished: (request, result) => {
if (result.ok) {
root.images = result.images;
root.warmOutlines(result.images.map(image => image.path));
root.notice = (result.notice || "") + (result.limited ? " Showing the first 1,000 images." : "");
} else
root.error = result.error;
@@ -144,6 +146,76 @@ Singleton {
ConfigService.setValue("wallpaper.history",[result.path].concat(ConfigService.data.wallpaper.history.filter(p=>p!==result.path)).slice(0,50));
Qt.callLater(root.applyNext);
}
// Which change a wallpaper gets (wallpaper/shaders/transition.frag): its
// subject's outline when helpers/wallfx.py has cached maps for it, colonies
// otherwise. Nothing waits for a cut-out: an unprocessed wallpaper gets
// colonies now and is processed in the background for next time. The
// package sets GLASSMXRPH_WALLFX_PYTHON (numpy, opencv, onnxruntime) and
// GLASSMXRPH_WALLFX_MODEL; without them every change is colonies.
readonly property string wallfxPython: Quickshell.env("GLASSMXRPH_WALLFX_PYTHON") || ""
readonly property bool outlinesAvailable: wallfxPython !== "" && (Quickshell.env("GLASSMXRPH_WALLFX_MODEL") || "") !== ""
property var transitions: ({}) // path -> {kind, field, line}
property var choosing: []
function setTransition(path, plan) {
const next = Object.assign({}, transitions);
next[path] = plan;
transitions = next;
}
// `ifUnknown`: keep an answer already given in this change (the picker asks
// at apply time, every output's background asks again when it switches).
function prepareTransition(path, ifUnknown) {
if (!path || choosing.includes(path) || (ifUnknown && path in transitions))
return;
const excluded = ConfigService.ready && ConfigService.data.wallpaper.outlineExclude.includes(path);
if (!outlinesAvailable || excluded)
return setTransition(path, {kind: "colonies"});
const next = Object.assign({}, transitions);
delete next[path];
transitions = next;
choosing = choosing.concat([path]);
chooseNext();
}
function chooseNext() {
if (chooseJob.running || !choosing.length)
return;
chooseJob.path = choosing[0];
chooseJob.command = [wallfxPython, Quickshell.shellPath("helpers/wallfx.py"), "choose", choosing[0]];
chooseJob.running = true;
}
function warmOutlines(paths) {
if (!outlinesAvailable || warmJob.running || !paths.length)
return;
warmJob.command = ["nice", "-n", "15", wallfxPython, Quickshell.shellPath("helpers/wallfx.py"), "warm"].concat(paths);
warmJob.running = true;
}
// Session libraries on LD_LIBRARY_PATH (JACK, SANE) can be built against
// another glibc than the helper's interpreter: keep them out.
Process {
id: chooseJob
property string path: ""
environment: ({LD_LIBRARY_PATH: null})
stdout: StdioCollector {
id: chooseOutput
}
onExited: {
let plan = {kind: "colonies"};
try {
plan = JSON.parse(chooseOutput.text);
} catch (error) {}
const path = chooseJob.path;
root.choosing = root.choosing.filter(p => p !== path);
root.setTransition(path, plan);
if (plan.pending)
root.warmOutlines([path]);
Qt.callLater(root.chooseNext);
}
}
// Processes uncached wallpapers at low priority (~5 s each on the CPU);
// one pass at a time, and the helper skips what is already cached.
Process {
id: warmJob
environment: ({LD_LIBRARY_PATH: null})
}
// Native backgrounds report when their new image has decoded; the reveal
// starts on every output together once all of them are ready.
property var revealWaiting: ({})