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>
153 lines
6.5 KiB
QML
153 lines
6.5 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import "../services"
|
|
import "../theme"
|
|
// qmllint disable uncreatable-type
|
|
PanelWindow {
|
|
id:root
|
|
required property var modelData
|
|
screen:modelData
|
|
anchors {top:true;bottom:true;left:true;right:true}
|
|
color:Theme.surface
|
|
exclusionMode:ExclusionMode.Ignore
|
|
WlrLayershell.layer:WlrLayer.Background
|
|
WlrLayershell.namespace:"glassMxrph-wallpaper"
|
|
mask:Region {}
|
|
readonly property string targetPath:ConfigService.ready ? (ConfigService.data.wallpaper.byMonitor[root.modelData.name] || "") : ""
|
|
readonly property string target:targetPath ? "file://"+encodeURI(targetPath).replace(/#/g,"%23").replace(/\?/g,"%3F") : ""
|
|
// 0..1 while the new wallpaper takes over (shaders/transition.frag).
|
|
property real progress:0
|
|
readonly property bool transitioning:incoming.source.toString()!==""
|
|
// The first wallpaper (and reduced motion) appears directly; later changes
|
|
// load into `incoming` and are revealed once decoded.
|
|
onTargetChanged:{
|
|
if(!shown.source.toString() || Theme.duration===0) {reveal.stop();incoming.source="";shown.source=target;}
|
|
else if(target===shown.source.toString()) {reveal.stop();incoming.source="";}
|
|
else {
|
|
reveal.stop();progress=0;reported=false;
|
|
WallpaperService.revealLoading(modelData.name);
|
|
WallpaperService.prepareTransition(targetPath,true);
|
|
incomingPath=targetPath;incoming.source=target;
|
|
}
|
|
}
|
|
Component.onCompleted:shown.source=target
|
|
function settle() {
|
|
if(!reveal.running && shown.status===Image.Ready && shown.source.toString()===incoming.source.toString())incoming.source="";
|
|
}
|
|
Image {
|
|
id:shown
|
|
anchors.fill:parent
|
|
sourceSize:Qt.size(parent.width,parent.height)
|
|
asynchronous:true
|
|
retainWhileLoading:true
|
|
fillMode:Image.PreserveAspectCrop
|
|
// Drop the overlay only once the base layer shows the new image.
|
|
onStatusChanged:root.settle()
|
|
}
|
|
// The incoming image and the outline maps are only textures: the shader
|
|
// draws the change over `shown`.
|
|
Image {
|
|
id:incoming
|
|
visible:false
|
|
sourceSize:Qt.size(root.width,root.height)
|
|
asynchronous:true
|
|
fillMode:Image.PreserveAspectCrop
|
|
onStatusChanged:{
|
|
if(status===Image.Error)incoming.source="";
|
|
else root.reportIfReady();
|
|
}
|
|
}
|
|
// The outline plan for the incoming wallpaper (WallpaperService), once known.
|
|
property string incomingPath:""
|
|
readonly property var plan:root.transitioning ? WallpaperService.transitions[root.incomingPath] : undefined
|
|
readonly property bool wantsOutline:!!root.plan && root.plan.kind==="outline"
|
|
readonly property bool outlineReady:root.wantsOutline && fieldMap.status===Image.Ready && lineMap.status===Image.Ready
|
|
// Settled: colonies, outline maps loaded, or maps that failed (colonies then).
|
|
readonly property bool planSettled:root.plan!==undefined && (!root.wantsOutline || root.outlineReady
|
|
|| fieldMap.status===Image.Error || lineMap.status===Image.Error)
|
|
onPlanSettledChanged:reportIfReady()
|
|
property bool reported:false
|
|
// Ready once the image is decoded and the plan settled. The service's
|
|
// fallback starts the change anyway if this takes too long; it then uses
|
|
// colonies unless the maps happen to be in.
|
|
function reportIfReady() {
|
|
if(reported || incoming.status!==Image.Ready || !incoming.source.toString() || !planSettled)return;
|
|
reported=true;
|
|
WallpaperService.revealReady(root.modelData.name);
|
|
}
|
|
// Maps hold numbers, not colours, at their own size; the shader interpolates.
|
|
Image {
|
|
id:fieldMap
|
|
visible:false
|
|
asynchronous:true
|
|
cache:false
|
|
source:root.wantsOutline ? "file://"+root.plan.field : ""
|
|
}
|
|
Image {
|
|
id:lineMap
|
|
visible:false
|
|
asynchronous:true
|
|
cache:false
|
|
source:root.wantsOutline ? "file://"+root.plan.line : ""
|
|
}
|
|
// PreserveAspectCrop decodes to cover the output, so the texture can be
|
|
// larger than the item on one axis: sample its centred window.
|
|
function crop(img) {
|
|
const iw=Math.max(img.implicitWidth,1),ih=Math.max(img.implicitHeight,1);
|
|
const s=Math.max(root.width/iw,root.height/ih);
|
|
const w=root.width/(iw*s),h=root.height/(ih*s);
|
|
return Qt.vector4d((1-w)/2,(1-h)/2,w,h);
|
|
}
|
|
ShaderEffect {
|
|
anchors.fill:parent
|
|
visible:root.transitioning && incoming.status===Image.Ready && root.progress>0
|
|
property var oldTex:shown
|
|
property var newTex:incoming
|
|
property real t:root.progress
|
|
property real sw:width
|
|
property real sh:height
|
|
property real cell:4
|
|
property real glow:0.9
|
|
property real seed:root.seed
|
|
property vector4d cropOld:root.crop(shown)
|
|
property vector4d cropNew:root.crop(incoming)
|
|
property color ember:root.ember
|
|
property color ink:Theme.text
|
|
property real mode:root.mode
|
|
// Unused in colonies mode, but every sampler needs a texture.
|
|
property var fieldTex:root.outlineReady ? fieldMap : incoming
|
|
property var lineTex:root.outlineReady ? lineMap : incoming
|
|
property real fw:Math.max(fieldMap.implicitWidth,1)
|
|
property real fh:Math.max(fieldMap.implicitHeight,1)
|
|
property real lineW:1.5
|
|
property real sdRange:16
|
|
fragmentShader:Qt.resolvedUrl("shaders/transition.frag.qsb")
|
|
}
|
|
// Captured when a change starts, so the burn keeps its colour even if the
|
|
// palette regenerates from the new wallpaper halfway through.
|
|
property real seed:0
|
|
property color ember:Theme.accentVivid
|
|
property real mode:0
|
|
Connections {
|
|
target:WallpaperService
|
|
function onRevealSerialChanged() {
|
|
if(incoming.status===Image.Ready && incoming.source.toString() && !reveal.running && root.progress===0) {
|
|
root.seed=Math.random()*100;root.ember=Theme.accentVivid;
|
|
root.mode=root.outlineReady ? 1 : 0;
|
|
reveal.duration=root.mode ? 2000 : 1800;
|
|
reveal.restart();
|
|
}
|
|
}
|
|
}
|
|
NumberAnimation {
|
|
id:reveal
|
|
target:root;property:"progress"
|
|
from:0;to:1
|
|
// Linear time: the shader eases its own phases. Set per change.
|
|
easing.type:Easing.Linear
|
|
onFinished:{shown.source=incoming.source;Qt.callLater(root.settle);}
|
|
}
|
|
}
|