mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Background: support for dynamic resolution changes
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user