Wallpaper: cleanup

This commit is contained in:
LemmyCook 2025-08-29 13:04:11 -04:00
parent c37ef867a1
commit db3ea7ed73
3 changed files with 97 additions and 69 deletions

View file

@ -78,6 +78,7 @@ ColumnLayout {
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)
} }
// Wallpaper grid container // Wallpaper grid container
@ -187,28 +188,37 @@ ColumnLayout {
} }
} }
}
// Empty state // Empty state
Rectangle { Rectangle {
anchors.fill: parent
color: Color.mSurface color: Color.mSurface
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: WallpaperService.wallpaperList.length === 0 && !WallpaperService.scanning
Layout.fillWidth: true
Layout.preferredHeight: 130 * scaling
ColumnLayout { ColumnLayout {
anchors.centerIn: parent id: fallbackColumn
spacing: Style.marginM * scaling anchors.fill: parent
anchors.margins: Style.marginL * Scaling
Item {
Layout.fillHeight: true
}
NIcon { NIcon {
text: "folder_open" text: "folder_open"
font.pointSize: Style.fontSizeL * scaling font.pointSize: Style.fontSizeXL * scaling
color: Color.mOnSurface color: Color.mOnSurface
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
} }
NText { NText {
text: "No wallpapers found" text: "No wallpaper found."
color: Color.mOnSurface color: Color.mOnSurface
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -216,11 +226,13 @@ ColumnLayout {
NText { NText {
text: "Make sure your wallpaper directory is configured and contains image files." text: "Make sure your wallpaper directory is configured and contains image files."
color: Color.mOnSurface color: Color.mOnSurfaceVariant
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: Style.sliderWidth * 1.5 * scaling
} }
Item {
Layout.fillHeight: true
} }
} }
} }

View file

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

View file

@ -13,6 +13,7 @@ Singleton {
Logger.log("Wallpaper", "Service started") Logger.log("Wallpaper", "Service started")
} }
// All available wallpaper transitions
readonly property ListModel transitionsModel: ListModel { readonly property ListModel transitionsModel: ListModel {
ListElement { ListElement {
key: "none" key: "none"
@ -29,13 +30,20 @@ Singleton {
Connections { Connections {
target: Settings.data.wallpaper target: Settings.data.wallpaper
function onDirectoryChanged() { console.log("ondirchanged") ; root.listWallpapers() } function onDirectoryChanged() {
function onRandomEnabledChanged() { root.toggleRandomWallpaper() } root.listWallpapers()
function onRandomIntervalSecChanged() { root.restartRandomWallpaperTimer() } }
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 var monitors = Settings.data.wallpaper.monitors
if (monitors !== undefined) { if (monitors !== undefined) {
for (var i = 0; i < monitors.length; i++) { for (var i = 0; i < monitors.length; i++) {
@ -47,42 +55,36 @@ Singleton {
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function getMonitorWallpaperDirectory(screenName) { // Get specific monitor directory
var monitor = geMonitorDefinition(screenName) function getMonitorDirectory(screenName) {
if (monitor !== undefined) { var monitor = getMonitorConfig(screenName)
if (monitor !== undefined && monitor.directory !== undefined) {
return monitor.directory return monitor.directory
} }
// Fall back to the main/single directory
return Settings.data.wallpaper.directory return Settings.data.wallpaper.directory
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function setMonitorWallpaperDirectory(screenName, directory) { // Set specific monitor directory
var monitor = geMonitorDefinition(screenName) function setMonitorDirectory(screenName, directory) {
var monitor = getMonitorConfig(screenName)
if (monitor !== undefined) { if (monitor !== undefined) {
monitor.directory = directory monitor.directory = directory
return } else {
}
Settings.data.wallpaper.monitors.push({ Settings.data.wallpaper.monitors.push({
"name": screenName, "name": screenName,
"directory": directory, "directory": directory,
"wallpaper": "" "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) { function getWallpaper(screenName) {
// Logger.log("Wallpaper", "getWallpaper on", screenName) var monitor = getMonitorConfig(screenName)
var monitor = geMonitorDefinition(screenName)
if ((monitor !== undefined) && (monitor["wallpaper"] !== undefined)) { if ((monitor !== undefined) && (monitor["wallpaper"] !== undefined)) {
return monitor["wallpaper"] return monitor["wallpaper"]
} }
@ -91,18 +93,18 @@ Singleton {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function changeWallpaper(screenName, path) { function changeWallpaper(screenName, path) {
Logger.log("Changing wallpaper")
if (screenName !== undefined) { if (screenName !== undefined) {
setCurrentWallpaper(screenName, path) setWallpaper(screenName, path)
} else { } else {
// If no screenName specified change for all screens
for (var i = 0; i < Quickshell.screens.length; i++) { 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) { if (path === "" || path === undefined) {
return return
} }
@ -124,7 +126,7 @@ Singleton {
wallpaperChanged = true wallpaperChanged = true
Settings.data.wallpaper.monitors.push({ Settings.data.wallpaper.monitors.push({
"name": screenName, "name": screenName,
"directory": Settings.data.wallpaper.directory, "directory": getMonitorDirectory(screenName),
"wallpaper": path "wallpaper": path
}) })
} }
@ -142,15 +144,18 @@ Singleton {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function setRandomWallpaper() { function setRandomWallpaper() {
Logger.log("Wallpaper", "setRandomWallpaper"); Logger.log("Wallpaper", "setRandomWallpaper")
for (var i = 0; i < Quickshell.screens.length; i++) { for (var i = 0; i < Quickshell.screens.length; i++) {
var screenName = Quickshell.screens[i].name var screenName = Quickshell.screens[i].name
// TODO one list per monitor var wallpaperList = getWallpaperList(screenName)
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) setCurrentWallpaper(screenName, randomPath)
} }
} }
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function toggleRandomWallpaper() { function toggleRandomWallpaper() {
@ -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 triggeredOnStart: false
} }
FolderListModel { // FolderListModel {
id: folderModel // id: folderModel
nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"] // nameFilters: ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.pnm", "*.bmp"]
showDirs: false // showDirs: false
sortField: FolderListModel.Name // sortField: FolderListModel.Name
onStatusChanged: { // onStatusChanged: {
if (status === FolderListModel.Ready) { // if (status === FolderListModel.Ready) {
var files = [] // var files = []
for (var i = 0; i < count; i++) { // for (var i = 0; i < count; i++) {
var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "") // var directory = (Settings.data.wallpaper.directory !== undefined ? Settings.data.wallpaper.directory : "")
var filepath = directory + "/" + get(i, "fileName") // var filepath = directory + "/" + get(i, "fileName")
files.push(filepath) // files.push(filepath)
} // }
wallpaperList = files // wallpaperList = files
scanning = false // scanning = false
Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length) // Logger.log("Wallpaper", "List refreshed, count:", wallpaperList.length)
} // }
} // }
} // }
} }