From db3ea7ed73c408ed6bc21e4ade337129f7e2c05c Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Fri, 29 Aug 2025 13:04:11 -0400 Subject: [PATCH] Wallpaper: cleanup --- .../Tabs/WallpaperSelectorTab.qml | 32 +++-- Modules/SettingsPanel/Tabs/WallpaperTab.qml | 2 +- Services/WallpaperService.qml | 132 ++++++++++-------- 3 files changed, 97 insertions(+), 69 deletions(-) diff --git a/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml b/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml index b49e580..be415ff 100644 --- a/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml +++ b/Modules/SettingsPanel/Tabs/WallpaperSelectorTab.qml @@ -78,6 +78,7 @@ ColumnLayout { description: "Set selected wallpaper on all monitors at once." checked: Settings.data.wallpaper.setWallpaperOnAllMonitors onToggled: checked => Settings.data.wallpaper.setWallpaperOnAllMonitors = checked + visible: (wallpaperService.wallpaperList.length > 0) } // Wallpaper grid container @@ -187,28 +188,37 @@ ColumnLayout { } } - // Empty state + + } + + // Empty state Rectangle { - anchors.fill: parent color: Color.mSurface radius: Style.radiusM * scaling border.color: Color.mOutline border.width: Math.max(1, Style.borderS * scaling) visible: WallpaperService.wallpaperList.length === 0 && !WallpaperService.scanning + Layout.fillWidth: true + Layout.preferredHeight: 130 * scaling ColumnLayout { - anchors.centerIn: parent - spacing: Style.marginM * scaling + id: fallbackColumn + anchors.fill: parent + anchors.margins: Style.marginL * Scaling + + Item { + Layout.fillHeight: true + } NIcon { text: "folder_open" - font.pointSize: Style.fontSizeL * scaling + font.pointSize: Style.fontSizeXL * scaling color: Color.mOnSurface Layout.alignment: Qt.AlignHCenter } NText { - text: "No wallpapers found" + text: "No wallpaper found." color: Color.mOnSurface font.weight: Style.fontWeightBold Layout.alignment: Qt.AlignHCenter @@ -216,14 +226,16 @@ ColumnLayout { NText { text: "Make sure your wallpaper directory is configured and contains image files." - color: Color.mOnSurface + color: Color.mOnSurfaceVariant wrapMode: Text.WordWrap - horizontalAlignment: Text.AlignHCenter - Layout.preferredWidth: Style.sliderWidth * 1.5 * scaling + Layout.alignment: Qt.AlignHCenter + } + + Item { + Layout.fillHeight: true } } } - } NDivider { Layout.fillWidth: true diff --git a/Modules/SettingsPanel/Tabs/WallpaperTab.qml b/Modules/SettingsPanel/Tabs/WallpaperTab.qml index fac62cb..f1e2b6f 100644 --- a/Modules/SettingsPanel/Tabs/WallpaperTab.qml +++ b/Modules/SettingsPanel/Tabs/WallpaperTab.qml @@ -54,7 +54,7 @@ ColumnLayout { NTextInput { label: (modelData.name || "Unknown") description: `Path to your wallpaper directory for "${(modelData.name || "Unknown")}" monitor` - text: WallpaperService.getMonitorWallpaperDirectory(modelData.name) + text: WallpaperService.getMonitorDirectory(modelData.name) labelColor: Color.mSecondary onEditingFinished: WallpaperService.setMonitorWallpaperDirectory(modelData.name, text) Layout.maximumWidth: 420 * scaling diff --git a/Services/WallpaperService.qml b/Services/WallpaperService.qml index 4ddb792..dd44f86 100644 --- a/Services/WallpaperService.qml +++ b/Services/WallpaperService.qml @@ -13,6 +13,7 @@ Singleton { Logger.log("Wallpaper", "Service started") } + // All available wallpaper transitions readonly property ListModel transitionsModel: ListModel { ListElement { key: "none" @@ -29,13 +30,20 @@ Singleton { Connections { target: Settings.data.wallpaper - function onDirectoryChanged() { console.log("ondirchanged") ; root.listWallpapers() } - function onRandomEnabledChanged() { root.toggleRandomWallpaper() } - function onRandomIntervalSecChanged() { root.restartRandomWallpaperTimer() } + function onDirectoryChanged() { + root.listWallpapers() + } + function onRandomEnabledChanged() { + root.toggleRandomWallpaper() + } + function onRandomIntervalSecChanged() { + root.restartRandomWallpaperTimer() + } } // ------------------------------------------------------------------- - function geMonitorDefinition(screenName) { + // Get specific monitor wallpaper data + function getMonitorConfig(screenName) { var monitors = Settings.data.wallpaper.monitors if (monitors !== undefined) { for (var i = 0; i < monitors.length; i++) { @@ -47,42 +55,36 @@ Singleton { } // ------------------------------------------------------------------- - function getMonitorWallpaperDirectory(screenName) { - var monitor = geMonitorDefinition(screenName) - if (monitor !== undefined) { + // Get specific monitor directory + function getMonitorDirectory(screenName) { + var monitor = getMonitorConfig(screenName) + if (monitor !== undefined && monitor.directory !== undefined) { return monitor.directory } + + // Fall back to the main/single directory return Settings.data.wallpaper.directory } // ------------------------------------------------------------------- - function setMonitorWallpaperDirectory(screenName, directory) { - var monitor = geMonitorDefinition(screenName) + // Set specific monitor directory + function setMonitorDirectory(screenName, directory) { + var monitor = getMonitorConfig(screenName) if (monitor !== undefined) { monitor.directory = directory - return + } else { + Settings.data.wallpaper.monitors.push({ + "name": screenName, + "directory": directory, + "wallpaper": "" + }) } - - Settings.data.wallpaper.monitors.push({ - "name": screenName, - "directory": directory, - "wallpaper": "" - }) - } - - // ------------------------------------------------------------------- - function listWallpapers() { - Logger.log("Wallpaper", "Listing wallpapers") - scanning = true - wallpaperList = [] - // Set the folder directly to avoid model reset issues - folderModel.folder = "file://" + (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") } // ------------------------------------------------------------------- + // Get specific monitor wallpaper function getWallpaper(screenName) { - // Logger.log("Wallpaper", "getWallpaper on", screenName) - var monitor = geMonitorDefinition(screenName) + var monitor = getMonitorConfig(screenName) if ((monitor !== undefined) && (monitor["wallpaper"] !== undefined)) { return monitor["wallpaper"] } @@ -91,22 +93,22 @@ Singleton { // ------------------------------------------------------------------- function changeWallpaper(screenName, path) { - Logger.log("Changing wallpaper") if (screenName !== undefined) { - setCurrentWallpaper(screenName, path) + setWallpaper(screenName, path) } else { + // If no screenName specified change for all screens for (var i = 0; i < Quickshell.screens.length; i++) { - setCurrentWallpaper(Quickshell.screens[i].name, path, false) + setWallpaper(Quickshell.screens[i].name, path) } } } // ------------------------------------------------------------------- - function setCurrentWallpaper(screenName, path) { + function setWallpaper(screenName, path) { if (path === "" || path === undefined) { return } - + if (screenName === undefined) { Logger.warn("Wallpaper", "setCurrentWallpaper", "no screen specified") return @@ -124,9 +126,9 @@ Singleton { wallpaperChanged = true Settings.data.wallpaper.monitors.push({ "name": screenName, - "directory": Settings.data.wallpaper.directory, + "directory": getMonitorDirectory(screenName), "wallpaper": path - }) + }) } // Restart the random wallpaper timer @@ -142,13 +144,16 @@ Singleton { // ------------------------------------------------------------------- function setRandomWallpaper() { - Logger.log("Wallpaper", "setRandomWallpaper"); + Logger.log("Wallpaper", "setRandomWallpaper") for (var i = 0; i < Quickshell.screens.length; i++) { var screenName = Quickshell.screens[i].name - // TODO one list per monitor - var randomIndex = Math.floor(Math.random() * wallpaperList.length) - var randomPath = wallpaperList[randomIndex] - setCurrentWallpaper(screenName, randomPath) + var wallpaperList = getWallpaperList(screenName) + + if (wallpaperList.length > 0) { + var randomIndex = Math.floor(Math.random() * wallpaperList.length) + var randomPath = wallpaperList[randomIndex] + setCurrentWallpaper(screenName, randomPath) + } } } @@ -171,6 +176,17 @@ Singleton { } } + // ------------------------------------------------------------------- + function listWallpapers() { + if (!Settings.isLoaded) { + return + } + + // TODO + Logger.log("Wallpaper", "Listing wallpapers for all monitors") + scanning = true + } + // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- @@ -183,23 +199,23 @@ Singleton { triggeredOnStart: false } - FolderListModel { - id: folderModel - nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] - showDirs: false - sortField: FolderListModel.Name - onStatusChanged: { - if (status === FolderListModel.Ready) { - var files = [] - for (var i = 0; i < count; i++) { - var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") - var filepath = directory + "/" + get(i, "fileName") - files.push(filepath) - } - wallpaperList = files - scanning = false - Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length) - } - } - } + // FolderListModel { + // id: folderModel + // nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] + // showDirs: false + // sortField: FolderListModel.Name + // onStatusChanged: { + // if (status === FolderListModel.Ready) { + // var files = [] + // for (var i = 0; i < count; i++) { + // var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") + // var filepath = directory + "/" + get(i, "fileName") + // files.push(filepath) + // } + // wallpaperList = files + // scanning = false + // Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length) + // } + // } + // } }