The screen previews the selected wallpaper with the real transition (TransitionStage, now shared with the desktop background) under a frosted sheet with a 16:9 thumbnail grid. Click or arrows preview, double-click or Enter applies and switches the picker's output directly, Space peeks, typing searches. Thumbnails mark outline wallpapers (wallfx status). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
282 lines
15 KiB
QML
282 lines
15 KiB
QML
pragma ComponentBehavior: Bound
|
||
import QtQuick
|
||
import QtQuick.Controls
|
||
import QtQuick.Effects
|
||
import QtQuick.Layouts
|
||
import Quickshell
|
||
import Quickshell.Wayland
|
||
import "../components"
|
||
import "../services"
|
||
import "../core"
|
||
import "../theme"
|
||
// qmllint disable uncreatable-type
|
||
// Full-screen wallpaper picker. The whole screen is a live preview: moving the
|
||
// selection plays the real change (TransitionStage) to that wallpaper, and the
|
||
// grid sits on a frosted sheet over it. Enter applies (the desktop under the
|
||
// preview switches directly, see WallpaperBackground), Esc leaves everything as
|
||
// it was, Space hides the sheet to look at the preview alone.
|
||
PanelWindow {
|
||
id:root
|
||
screen:ScreenService.current(ShellState.wallpaperScreen)
|
||
anchors {top:true;bottom:true;left:true;right:true}
|
||
readonly property string screenName:screen ? screen.name : ""
|
||
readonly property bool open:ShellState.wallpaperPickerOpen
|
||
visible:open || content.opacity>0
|
||
color:Theme.transparent
|
||
exclusionMode:ExclusionMode.Ignore
|
||
WlrLayershell.namespace:"glassMxrph-wallpaper-picker"
|
||
WlrLayershell.layer:WlrLayer.Overlay
|
||
WlrLayershell.keyboardFocus:open ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||
Component.onCompleted:ShellState.wallpaperWindow=root
|
||
Component.onDestruction:ShellState.wallpaperWindow=null
|
||
|
||
property string filter:"all"
|
||
readonly property var results:WallpaperService.images.filter(i=>(filter!=="history" || ConfigService.data.wallpaper.history.includes(i.path)) && (!search.text || i.name.toLowerCase().includes(search.text.toLowerCase())))
|
||
// The selection lives here, not in the view: a rescan or a new search
|
||
// replaces the model, and the view would fall back to the first tile.
|
||
property string selectedPath:""
|
||
readonly property var selected:results.find(i=>i.path===selectedPath) || null
|
||
property bool peek:false
|
||
property string applying:""
|
||
readonly property string desktopPath:ConfigService.ready ? (ConfigService.data.wallpaper.byMonitor[root.screenName] || WallpaperService.currentPath) : ""
|
||
|
||
function select(index) {
|
||
if(index<0 || index>=results.length)return;
|
||
view.currentIndex=index;
|
||
selectedPath=results[index].path;
|
||
}
|
||
function syncSelection() {
|
||
const index=results.findIndex(i=>i.path===selectedPath);
|
||
if(index>=0)view.currentIndex=index;
|
||
else if(results.length)select(0);
|
||
}
|
||
onResultsChanged:Qt.callLater(syncSelection)
|
||
// Previews follow the selection once it rests, so sweeping across the grid
|
||
// does not start a change per tile.
|
||
onSelectedPathChanged:previewDelay.restart()
|
||
Timer {id:previewDelay;interval:200;onTriggered:if(root.open && root.selectedPath)preview.path=root.selectedPath}
|
||
|
||
function applySelected() {
|
||
if(!selectedPath || applying)return;
|
||
// Enter before the preview caught up: show it directly, the desktop is about to.
|
||
if(preview.path!==selectedPath) {previewDelay.stop();preview.instantNext=true;preview.path=selectedPath;}
|
||
if(WallpaperService.apply(selectedPath,root.screenName)) {applying=selectedPath;applyGuard.restart();}
|
||
}
|
||
// Close once this output's desktop shows the applied wallpaper (a moment to
|
||
// decode it), or after a while regardless.
|
||
readonly property bool applied:applying!=="" && desktopPath===applying
|
||
onAppliedChanged:if(applied)closeDelay.restart()
|
||
Timer {id:closeDelay;interval:150;onTriggered:root.close()}
|
||
Timer {id:applyGuard;interval:1500;onTriggered:if(root.applying)root.close()}
|
||
function close() {applying="";ShellState.wallpaperPickerOpen=false;}
|
||
|
||
onOpenChanged:{
|
||
if(open) {
|
||
applying="";peek=false;
|
||
WallpaperService.refresh();WallpaperService.scan();
|
||
preview.instantNext=true;
|
||
preview.path=desktopPath;
|
||
selectedPath=desktopPath;
|
||
syncSelection();
|
||
view.positionViewAtIndex(Math.max(0,view.currentIndex),GridView.Center);
|
||
Qt.callLater(()=>view.forceActiveFocus());
|
||
}
|
||
}
|
||
|
||
Item {
|
||
id:content
|
||
objectName:"wallpaperPickerSurface"
|
||
anchors.fill:parent
|
||
opacity:root.open ? 1 : 0
|
||
Behavior on opacity {NumberAnimation {duration:Theme.duration*1.2;easing.type:Easing.OutCubic}}
|
||
// Release the preview's textures once fully closed.
|
||
onOpacityChanged:if(opacity===0 && !root.open)preview.path=""
|
||
|
||
TransitionStage {
|
||
id:preview
|
||
anchors.fill:parent
|
||
}
|
||
MouseArea {anchors.fill:parent;onClicked:root.peek=!root.peek}
|
||
|
||
// Name and transition of the selection, over the preview.
|
||
ColumnLayout {
|
||
id:info
|
||
x:56;y:48
|
||
spacing:6
|
||
opacity:root.selected ? 1 : 0
|
||
Behavior on opacity {NumberAnimation {duration:Theme.duration}}
|
||
layer.enabled:true
|
||
layer.effect:MultiEffect {shadowEnabled:true;shadowBlur:0.8;shadowOpacity:0.7;shadowColor:"black";autoPaddingEnabled:true}
|
||
Text {
|
||
text:root.selected ? root.selected.name.replace(/\.[^.]+$/,"") : ""
|
||
color:"white";font.pixelSize:34;font.weight:Font.DemiBold
|
||
}
|
||
Text {
|
||
readonly property string status:root.selected ? (WallpaperService.outlineStatus[root.selected.path] || "") : ""
|
||
text:(status==="outline" ? "✦ Outline transition" : status==="pending" ? "Preparing outline…" : "Colonies transition")
|
||
+" · "+(view.currentIndex+1)+" / "+root.results.length
|
||
+(root.selected && root.selected.path===root.desktopPath ? " · current" : "")
|
||
color:Qt.alpha("white",0.85);font.pixelSize:15
|
||
}
|
||
}
|
||
|
||
// Frosted sheet: a blurred copy of the preview behind it, so the glass
|
||
// shows the wallpaper being previewed (the compositor's blur would show
|
||
// what is under this window instead).
|
||
Item {
|
||
id:sheet
|
||
width:parent.width-96
|
||
height:Math.min(540,Math.round(parent.height*0.46))
|
||
x:48
|
||
y:root.peek || !root.open ? parent.height+16 : parent.height-height-36
|
||
Behavior on y {NumberAnimation {duration:Theme.duration*1.4;easing.type:Easing.OutCubic}}
|
||
ShaderEffectSource {
|
||
id:sheetBackdrop
|
||
sourceItem:preview
|
||
sourceRect:Qt.rect(sheet.x,sheet.y,sheet.width,sheet.height)
|
||
visible:false
|
||
}
|
||
Item {
|
||
id:sheetMask
|
||
anchors.fill:parent
|
||
visible:false
|
||
layer.enabled:true
|
||
Rectangle {anchors.fill:parent;radius:28}
|
||
}
|
||
MultiEffect {
|
||
anchors.fill:parent
|
||
source:sheetBackdrop
|
||
autoPaddingEnabled:false
|
||
blurEnabled:true;blur:1;blurMax:64
|
||
saturation:-0.1;brightness:-0.08
|
||
maskEnabled:true;maskSource:sheetMask
|
||
maskThresholdMin:0.5;maskSpreadAtMin:1
|
||
}
|
||
Rectangle {anchors.fill:parent;radius:28;color:Qt.alpha(Theme.tint,0.38);border.width:1;border.color:Theme.border}
|
||
MouseArea {anchors.fill:parent}
|
||
|
||
ColumnLayout {
|
||
anchors.fill:parent;anchors.margins:22;spacing:14
|
||
RowLayout {
|
||
Layout.fillWidth:true;spacing:10
|
||
Text {text:"Wallpapers";color:Theme.text;font.pixelSize:22}
|
||
GlassButton {text:"All";accented:root.filter==="all";onClicked:root.filter="all"}
|
||
GlassButton {text:"History";accented:root.filter==="history";onClicked:root.filter="history"}
|
||
GlassTextField {
|
||
id:search;objectName:"wallpaperSearch"
|
||
Layout.fillWidth:true;placeholderText:"Search wallpapers…"
|
||
Keys.onEscapePressed:root.close()
|
||
Keys.onDownPressed:view.forceActiveFocus()
|
||
Keys.onReturnPressed:view.forceActiveFocus()
|
||
}
|
||
GlassComboBox {
|
||
Layout.preferredWidth:150
|
||
model:["all","primary"].concat(Quickshell.screens.map(s=>s.name))
|
||
currentIndex:Math.max(0,model.indexOf(WallpaperService.selectedMonitor))
|
||
onActivated:WallpaperService.selectedMonitor=currentText
|
||
}
|
||
GlassIconButton {text:"↻";onClicked:WallpaperService.scan();Accessible.name:"Refresh wallpapers"}
|
||
GlassIconButton {text:"⚙";onClicked:ShellState.openSettings("wallpaper");Accessible.name:"Wallpaper settings"}
|
||
GlassIconButton {text:"×";onClicked:root.close();Accessible.name:"Close picker"}
|
||
}
|
||
GridView {
|
||
id:view
|
||
objectName:"wallpaperGrid"
|
||
Layout.fillWidth:true;Layout.fillHeight:true
|
||
readonly property int columns:Math.max(3,Math.floor(width/300))
|
||
cellWidth:Math.floor(width/columns)
|
||
cellHeight:Math.round((cellWidth-16)*9/16)+16
|
||
clip:true
|
||
model:root.results
|
||
boundsBehavior:Flickable.StopAtBounds
|
||
keyNavigationEnabled:true
|
||
ScrollBar.vertical:ScrollBar {}
|
||
onCurrentIndexChanged:if(root.results[currentIndex])root.selectedPath=root.results[currentIndex].path
|
||
Keys.onReturnPressed:root.applySelected()
|
||
Keys.onEnterPressed:root.applySelected()
|
||
Keys.onEscapePressed:root.close()
|
||
Keys.onSpacePressed:root.peek=!root.peek
|
||
// Typing goes to the search field.
|
||
Keys.onPressed:event=>{
|
||
if(event.text && event.text.trim() && !(event.modifiers&(Qt.ControlModifier|Qt.AltModifier|Qt.MetaModifier))) {
|
||
search.forceActiveFocus();search.text+=event.text;event.accepted=true;
|
||
}
|
||
}
|
||
// One rounded mask shared by every thumbnail (they are all the same size).
|
||
Item {
|
||
id:tileMask
|
||
width:view.cellWidth-16;height:view.cellHeight-16
|
||
visible:false
|
||
layer.enabled:true
|
||
Rectangle {anchors.fill:parent;radius:14}
|
||
}
|
||
delegate:Item {
|
||
id:cell
|
||
required property var modelData
|
||
required property int index
|
||
readonly property bool current:view.currentIndex===index
|
||
width:view.cellWidth;height:view.cellHeight
|
||
Item {
|
||
anchors.fill:parent;anchors.margins:8
|
||
scale:cell.current ? 1 : (tileArea.containsMouse ? 0.98 : 0.95)
|
||
Behavior on scale {NumberAnimation {duration:Theme.duration;easing.type:Easing.OutCubic}}
|
||
Image {
|
||
anchors.fill:parent
|
||
source:cell.modelData.url
|
||
sourceSize:Qt.size(480,270)
|
||
asynchronous:true
|
||
fillMode:Image.PreserveAspectCrop
|
||
opacity:status===Image.Ready ? (cell.current ? 1 : 0.82) : 0
|
||
Behavior on opacity {NumberAnimation {duration:Theme.duration}}
|
||
layer.enabled:true
|
||
layer.effect:MultiEffect {maskEnabled:true;maskSource:tileMask;maskThresholdMin:0.5;maskSpreadAtMin:1}
|
||
}
|
||
Rectangle {
|
||
anchors.fill:parent;radius:14;color:"transparent"
|
||
border.width:cell.current ? 3 : 1
|
||
border.color:cell.current ? Theme.accent : Qt.alpha("white",0.16)
|
||
}
|
||
Row {
|
||
anchors.top:parent.top;anchors.right:parent.right;anchors.margins:8;spacing:6
|
||
Repeater {
|
||
model:[WallpaperService.outlineStatus[cell.modelData.path]==="outline" ? "✦" : "",
|
||
cell.modelData.path===root.desktopPath ? "✓" : ""].filter(s=>s)
|
||
delegate:Rectangle {
|
||
required property string modelData
|
||
width:24;height:24;radius:12
|
||
color:Qt.alpha("black",0.55)
|
||
Text {anchors.centerIn:parent;text:parent.modelData;color:"white";font.pixelSize:13}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// Click previews, double-click applies.
|
||
MouseArea {
|
||
id:tileArea
|
||
anchors.fill:parent
|
||
hoverEnabled:true
|
||
onClicked:{root.select(cell.index);view.forceActiveFocus();}
|
||
onDoubleClicked:{root.select(cell.index);root.applySelected();}
|
||
}
|
||
}
|
||
}
|
||
Text {visible:!root.results.length;text:WallpaperService.scanning ? "Loading wallpapers…" : "No wallpapers here. Choose a folder in Wallpaper settings.";color:Theme.textSecondary;Layout.fillWidth:true;wrapMode:Text.Wrap}
|
||
Text {
|
||
text:WallpaperService.error || (root.applying ? "Applying wallpaper…" : "Click or arrows preview · Double-click or Enter apply · Space peek · type to search · Esc close")
|
||
color:WallpaperService.error ? Theme.urgent : Theme.textSecondary
|
||
Layout.fillWidth:true;elide:Text.ElideRight
|
||
}
|
||
}
|
||
}
|
||
// While peeking, a click or any key brings the sheet back.
|
||
Text {
|
||
anchors.bottom:parent.bottom;anchors.horizontalCenter:parent.horizontalCenter;anchors.bottomMargin:28
|
||
visible:root.peek && root.open
|
||
text:"Space to show wallpapers · Enter apply · Esc close"
|
||
color:"white";font.pixelSize:14
|
||
layer.enabled:true
|
||
layer.effect:MultiEffect {shadowEnabled:true;shadowBlur:0.6;shadowOpacity:0.8;shadowColor:"black"}
|
||
}
|
||
}
|
||
}
|