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 PanelWindow { id:root screen:ScreenService.current(ShellState.wallpaperScreen) // Hangs from the middle of the bar as a drawer; the layer starts at the // screen top so the bar join is inside its box. anchors {top:true} readonly property real screenWidth:screen ? screen.width : 1920 readonly property real screenHeight:screen ? screen.height : 1080 implicitWidth:Math.round(surface.width) // Notch mode: no bar to hang from, so it drops from the screen's top edge // in the notch's shape, colour and speeds. readonly property bool notch:ShellState.notchMode readonly property real top:notch ? 0 : BarDrawers.bottom implicitHeight:Math.round(top+surface.contentHeight) visible:ShellState.wallpaperPickerOpen || surface.shown color:Theme.transparent exclusionMode:ExclusionMode.Ignore WlrLayershell.namespace:"glassMxrph-wallpaper-picker" WlrLayershell.layer:WlrLayer.Overlay WlrLayershell.keyboardFocus:ShellState.wallpaperPickerOpen ? 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()))) // Justified rows, as in a photo gallery: every thumbnail keeps its own // aspect ratio (from the scan's header sizes) and each row is scaled so it // fills the width exactly. The last row keeps the target height. readonly property real rowTarget:170 readonly property real gap:10 readonly property var rows:layoutRows(results,view.width) function aspectOf(image) { const a=image.width>0 && image.height>0 ? image.width/image.height : 16/9; return Math.max(0.5,Math.min(3,a)); // keep panoramas and slivers usable } function layoutRows(images,width) { const out=[]; if(width<=0)return out; let row=[],sum=0; const close=height=>{ let x=0; out.push({height:height,tiles:row.map(t=>{const w=t.aspect*height;const tile={index:t.index,x:x,width:w};x+=w+root.gap;return tile;})}); row=[];sum=0; }; images.forEach((image,index)=>{ const aspect=aspectOf(image); row.push({index:index,aspect:aspect});sum+=aspect; if(sum*rowTarget+gap*(row.length-1)>=width)close((width-gap*(row.length-1))/sum); }); if(row.length)close(rowTarget); return out; } // Where each result sits: its row, and its horizontal centre for up/down. readonly property var places:{ const p=[]; rows.forEach((row,r)=>row.tiles.forEach(t=>p[t.index]={row:r,center:t.x+t.width/2})); return p; } property int current:0 onResultsChanged:if(current>=results.length)current=Math.max(0,results.length-1) function select(index) { if(index<0 || index>=results.length)return; current=index; if(places[index])view.positionViewAtIndex(places[index].row,ListView.Contain); } // Up/down: the tile in the next row whose centre is closest. function vertical(direction) { const here=places[current]; if(!here)return select(0); const row=rows[here.row+direction]; if(!row)return; let best=row.tiles[0]; for(const t of row.tiles)if(Math.abs(t.x+t.width/2-here.center)i.path===WallpaperService.currentPath); if(at>=0)root.select(at); Qt.callLater(()=>view.forceActiveFocus()); } } } OutsideClick { window: root active: ShellState.wallpaperPickerOpen onOutside: ShellState.wallpaperPickerOpen = false } // Fallback outside-click catcher (see ControlCenter). MouseArea {x:-20000;y:-20000;width:40000;height:40000;onPressed:ShellState.wallpaperPickerOpen=false} BarDrawer { id:surface objectName:"wallpaperPickerSurface" y:root.top open:ShellState.wallpaperPickerOpen contentWidth:Math.min(1240,root.screenWidth-2*(BarDrawers.margin+BarDrawers.radius+ear)) contentHeight:Math.min(640,root.screenHeight-root.top-40) fillColor:root.notch ? Theme.notchOpenFill : Qt.alpha(Theme.surface,Theme.glassOpacity) openDuration:root.notch ? Theme.notchOpenDuration*2 : Theme.duration*1.8 closeDuration:root.notch ? Theme.notchCloseDuration*1.3 : Theme.duration // The notch-shaped picker keeps the notch's own motion. liquid:false drawerId:"wallpaper" screenName:root.screen ? root.screen.name : "" screenX:(root.screenWidth-width)/2 MouseArea {anchors.fill:parent} ColumnLayout { anchors.fill:parent;anchors.margins:22;spacing:16 RowLayout { Layout.fillWidth:true Text {text:"Wallpapers";color:Theme.text;font.pixelSize:24;Layout.fillWidth:true} GlassComboBox { Layout.preferredWidth:160 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:ShellState.openSettings("wallpaper");Accessible.name:"Wallpaper settings"} GlassIconButton {text:"×";onClicked:ShellState.wallpaperPickerOpen=false;Accessible.name:"Close picker"} } RowLayout { 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…";onTextChanged:root.select(0);Keys.onEscapePressed:ShellState.wallpaperPickerOpen=false;Keys.onDownPressed:view.forceActiveFocus()} GlassIconButton {text:"↻";onClicked:WallpaperService.scan();Accessible.name:"Refresh wallpapers"} } ListView { id:view objectName:"wallpaperGallery" Layout.fillWidth:true;Layout.fillHeight:true spacing:root.gap clip:true model:root.rows boundsBehavior:Flickable.StopAtBounds ScrollBar.vertical:ScrollBar {} Keys.onLeftPressed:root.select(root.current-1) Keys.onRightPressed:root.select(root.current+1) Keys.onUpPressed:root.vertical(-1) Keys.onDownPressed:root.vertical(1) Keys.onReturnPressed:root.applyCurrent() Keys.onEnterPressed:root.applyCurrent() Keys.onEscapePressed:ShellState.wallpaperPickerOpen=false delegate:Item { id:rowItem required property var modelData width:view.width height:modelData.height function tileAt(index) { for(let i=0;is) : [] delegate:Rectangle { required property string modelData width:22;height:22;radius:11 color:Qt.alpha("black",0.55) Text {anchors.centerIn:parent;text:parent.modelData;color:"white";font.pixelSize:12} } } } } MouseArea { id:hover anchors.fill:parent hoverEnabled:true onClicked:{root.current=tile.modelData.index;view.forceActiveFocus();root.applyCurrent();} } } } } } 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 || (WallpaperService.busy?"Applying wallpaper…":"Click or arrows and Enter to apply · ✦ outline transition · Esc Close");color:WallpaperService.error?Theme.urgent:Theme.textSecondary;Layout.fillWidth:true;wrapMode:Text.Wrap} } } }