Background: support for dynamic resolution changes

This commit is contained in:
ItsLemmy
2025-10-04 19:09:27 -04:00
parent dbabb7bb69
commit 3ae6cdc3f0
+41 -12
View File
@@ -44,6 +44,19 @@ Variants {
property real fillMode: WallpaperService.getFillModeUniform()
property vector4d fillColor: Qt.vector4d(Settings.data.wallpaper.fillColor.r, Settings.data.wallpaper.fillColor.g, Settings.data.wallpaper.fillColor.b, 1.0)
property int monitoredWidth: modelData.width
property int monitoredHeight: modelData.height
onMonitoredWidthChanged: {
Logger.log("Background", "Screen width changed to:", monitoredWidth, "for", modelData.name)
recalculateImageSizes()
}
onMonitoredHeightChanged: {
Logger.log("Background", "Screen height changed to:", monitoredHeight, "for", modelData.name)
recalculateImageSizes()
}
Component.onCompleted: setWallpaperInitial()
Component.onDestruction: {
@@ -109,25 +122,26 @@ Variants {
cache: false
asynchronous: true
// Don't set sourceSize initially - will be set after we know aspect ratio
onStatusChanged: {
if (status === Image.Error) {
Logger.warn("Current wallpaper failed to load:", source)
} else if (status === Image.Ready && !dimensionsCalculated) {
// First load: get original dimensions
const aspectRatio = implicitWidth / implicitHeight
dimensionsCalculated = true
// Now set sourceSize to screen width and calculated height
const w = Math.min(modelData.width, implicitWidth)
sourceSize = Qt.size(w, w / aspectRatio)
calculateSourceSize()
}
}
onSourceChanged: {
// Reset for new image
dimensionsCalculated = false
sourceSize = undefined // Clear sourceSize for initial load
sourceSize = undefined
}
function calculateSourceSize() {
if (implicitWidth > 0 && implicitHeight > 0) {
const aspectRatio = implicitWidth / implicitHeight
const w = Math.min(modelData.width, implicitWidth)
sourceSize = Qt.size(w, w / aspectRatio)
}
}
}
@@ -147,10 +161,8 @@ Variants {
if (status === Image.Error) {
Logger.warn("Next wallpaper failed to load:", source)
} else if (status === Image.Ready && !dimensionsCalculated) {
const aspectRatio = implicitWidth / implicitHeight
dimensionsCalculated = true
const w = Math.min(modelData.width, implicitWidth)
sourceSize = Qt.size(w, w / aspectRatio)
calculateSourceSize()
}
}
@@ -158,6 +170,14 @@ Variants {
dimensionsCalculated = false
sourceSize = undefined
}
function calculateSourceSize() {
if (implicitWidth > 0 && implicitHeight > 0) {
const aspectRatio = implicitWidth / implicitHeight
const w = Math.min(modelData.width, implicitWidth)
sourceSize = Qt.size(w, w / aspectRatio)
}
}
}
// Dynamic shader loader - only loads the active transition shader
@@ -314,6 +334,15 @@ Variants {
}
}
function recalculateImageSizes() {
if (currentWallpaper.status === Image.Ready) {
currentWallpaper.calculateSourceSize()
}
if (nextWallpaper.status === Image.Ready) {
nextWallpaper.calculateSourceSize()
}
}
function setWallpaperInitial() {
// On startup, defer assigning wallpaper until the service cache is ready, retries every tick
if (!WallpaperService || !WallpaperService.isInitialized) {