Wallpaper: real support for differents folders per monitor \o/

This commit is contained in:
LemmyCook 2025-08-29 14:09:05 -04:00
parent 812ddf2ebb
commit 9bbdf5f6f6
3 changed files with 88 additions and 69 deletions

View file

@ -67,32 +67,34 @@ ColumnLayout {
icon: "refresh" icon: "refresh"
tooltipText: "Refresh wallpaper list" tooltipText: "Refresh wallpaper list"
onClicked: { onClicked: {
WallpaperService.listWallpapers() WallpaperService.refreshWallpapersList()
} }
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
} }
} }
property list<string> wallpapersList: WallpaperService.getWallpapersList(screen.name)
NToggle { NToggle {
label: "Assign selection to all monitors" label: "Assign selection to all monitors"
description: "Set selected wallpaper on all monitors at once." description: "Set selected wallpaper on all monitors at once."
checked: Settings.data.wallpaper.setWallpaperOnAllMonitors checked: Settings.data.wallpaper.setWallpaperOnAllMonitors
onToggled: checked => Settings.data.wallpaper.setWallpaperOnAllMonitors = checked onToggled: checked => Settings.data.wallpaper.setWallpaperOnAllMonitors = checked
visible: (WallpaperService.wallpaperList.length > 0) visible: (wallpapersList.length > 0)
} }
// Wallpaper grid container // Wallpaper grid container
Item { Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: { Layout.preferredHeight: {
return Math.ceil(WallpaperService.wallpaperList.length / wallpaperGridView.columns) * wallpaperGridView.cellHeight return Math.ceil(wallpapersList.length / wallpaperGridView.columns) * wallpaperGridView.cellHeight
} }
GridView { GridView {
id: wallpaperGridView id: wallpaperGridView
anchors.fill: parent anchors.fill: parent
clip: true clip: true
model: WallpaperService.wallpaperList model: wallpapersList
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.AutoFlickDirection flickableDirection: Flickable.AutoFlickDirection
@ -187,8 +189,6 @@ ColumnLayout {
} }
} }
} }
} }
// Empty state // Empty state
@ -197,7 +197,7 @@ ColumnLayout {
radius: Style.radiusM * scaling radius: Style.radiusM * scaling
border.color: Color.mOutline border.color: Color.mOutline
border.width: Math.max(1, Style.borderS * scaling) border.width: Math.max(1, Style.borderS * scaling)
visible: WallpaperService.wallpaperList.length === 0 && !WallpaperService.scanning visible: wallpapersList.length === 0 && !WallpaperService.scanning
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 130 * scaling Layout.preferredHeight: 130 * scaling

View file

@ -56,7 +56,7 @@ ColumnLayout {
description: `Path to your wallpaper directory for "${(modelData.name || "Unknown")}" monitor` description: `Path to your wallpaper directory for "${(modelData.name || "Unknown")}" monitor`
text: WallpaperService.getMonitorDirectory(modelData.name) text: WallpaperService.getMonitorDirectory(modelData.name)
labelColor: Color.mSecondary labelColor: Color.mSecondary
onEditingFinished: WallpaperService.setMonitorWallpaperDirectory(modelData.name, text) onEditingFinished: WallpaperService.setMonitorDirectory(modelData.name, text)
Layout.maximumWidth: 420 * scaling Layout.maximumWidth: 420 * scaling
} }
} }

View file

@ -25,13 +25,13 @@ Singleton {
} }
} }
property var wallpaperList: [] property var wallpaperLists: ({})
property bool scanning: false property bool scanning: false
Connections { Connections {
target: Settings.data.wallpaper target: Settings.data.wallpaper
function onDirectoryChanged() { function onDirectoryChanged() {
root.listWallpapers() root.refreshWallpapersList()
} }
function onRandomEnabledChanged() { function onRandomEnabledChanged() {
root.toggleRandomWallpaper() root.toggleRandomWallpaper()
@ -110,15 +110,15 @@ Singleton {
} }
if (screenName === undefined) { if (screenName === undefined) {
Logger.warn("Wallpaper", "setCurrentWallpaper", "no screen specified") Logger.warn("Wallpaper", "setWallpaper", "no screen specified")
return return
} }
Logger.log("Wallpaper", "setCurrentWallpaper on", screenName, ": ", path) Logger.log("Wallpaper", "setWallpaper on", screenName, ": ", path)
var wallpaperChanged = false var wallpaperChanged = false
var monitor = geMonitorDefinition(screenName) var monitor = getMonitorConfig(screenName)
if (monitor !== undefined) { if (monitor !== undefined) {
wallpaperChanged = (monitor["wallpaper"] !== path) wallpaperChanged = (monitor["wallpaper"] !== path)
monitor["wallpaper"] = path monitor["wallpaper"] = path
@ -152,7 +152,7 @@ Singleton {
if (wallpaperList.length > 0) { if (wallpaperList.length > 0) {
var randomIndex = Math.floor(Math.random() * wallpaperList.length) var randomIndex = Math.floor(Math.random() * wallpaperList.length)
var randomPath = wallpaperList[randomIndex] var randomPath = wallpaperList[randomIndex]
setCurrentWallpaper(screenName, randomPath) setWallpaper(screenName, randomPath)
} }
} }
} }
@ -177,13 +177,21 @@ Singleton {
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function listWallpapers() { function getWallpapersList(screenName) {
if (screenName != undefined && wallpaperLists[screenName] != undefined) {
return wallpaperLists[screenName]
}
return []
}
// -------------------------------------------------------------------
function refreshWallpapersList() {
if (!Settings.isLoaded) { if (!Settings.isLoaded) {
return return
} }
// TODO // TODO
Logger.log("Wallpaper", "Listing wallpapers for all monitors") Logger.log("Wallpaper", "refreshWallpapersList")
scanning = true scanning = true
} }
@ -199,23 +207,34 @@ Singleton {
triggeredOnStart: false triggeredOnStart: false
} }
// FolderListModel { // Instantiator (not Repeater) to create FolderListModel for each monitor
// id: folderModel Instantiator {
// nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] model: Quickshell.screens
// showDirs: false
// sortField: FolderListModel.Name delegate: FolderListModel {
// onStatusChanged: { property string screenName: modelData.name
// if (status === FolderListModel.Ready) {
// var files = [] folder: "file://" + root.getMonitorDirectory(screenName)
// for (var i = 0; i < count; i++) { nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"]
// var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") showDirs: false
// var filepath = directory + "/" + get(i, "fileName") sortField: FolderListModel.Name
// files.push(filepath)
// } onStatusChanged: {
// wallpaperList = files if (status === FolderListModel.Ready) {
// scanning = false var files = []
// Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length) for (var i = 0; i < count; i++) {
// } var directory = root.getMonitorDirectory(screenName)
// } var filepath = directory + "/" + get(i, "fileName")
// } files.push(filepath)
}
var lists = root.wallpaperLists
lists[screenName] = files
root.wallpaperLists = lists
Logger.log("Wallpaper", "List refreshed for", screenName, "count:", files.length)
}
}
}
}
} }