Files
glassMxrph/quickshell/wallpaper/WallpaperBackground.qml
T
mxandClaude Opus 5.5 f6732dc3da Mask the incoming wallpaper with its own layer effect
A MultiEffect pointed at a hidden source drew nothing, so the reveal was
invisible and the wallpaper still cut over at the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 15:40:26 +02:00

85 lines
3.2 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Effects
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 target:ConfigService.ready && ConfigService.data.wallpaper.byMonitor[root.modelData.name] ? "file://"+encodeURI(ConfigService.data.wallpaper.byMonitor[root.modelData.name]).replace(/#/g,"%23").replace(/\?/g,"%3F") : ""
// 0..1 while a new wallpaper grows in from the centre over the old one.
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;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()
}
Item {
id:revealMask
anchors.fill:parent
visible:false
layer.enabled:root.transitioning
Rectangle {
readonly property real reach:Math.hypot(root.width,root.height)*1.15
anchors.centerIn:parent
width:reach*root.progress;height:width;radius:width/2
color:"black"
}
}
// The mask must be the image's own layer effect: a MultiEffect pointed at a
// hidden source renders nothing here.
Image {
id:incoming
anchors.fill:parent
visible:root.transitioning && root.progress>0
sourceSize:Qt.size(parent.width,parent.height)
asynchronous:true
fillMode:Image.PreserveAspectCrop
// Settles from a slight zoom while the circle widens, like swww/awww "grow".
scale:1.06-0.06*root.progress
onStatusChanged:if(status===Image.Ready && source.toString())reveal.restart()
layer.enabled:root.transitioning
layer.effect:MultiEffect {
maskEnabled:true
maskSource:revealMask
maskThresholdMin:0.5
maskSpreadAtMin:1
}
}
NumberAnimation {
id:reveal
target:root;property:"progress"
from:0;to:1
duration:1100
easing.type:Easing.InOutCubic
onFinished:{shown.source=incoming.source;Qt.callLater(root.settle);}
}
}