Lockscreen: improved background image support by using thw WallpaperCacheService

This commit is contained in:
Lemmy
2025-12-25 12:21:18 -05:00
parent 9a48e4eb89
commit 01a95d2b8d
2 changed files with 25 additions and 21 deletions
+15 -14
View File
@@ -115,7 +115,7 @@ Loader {
}
// Cached wallpaper path
property string cachedWallpaperPath: ""
property string resolvedWallpaperPath: ""
// Request preprocessed wallpaper when lock screen becomes active or dimensions change
Component.onCompleted: {
@@ -163,41 +163,42 @@ Loader {
if (!WallpaperCacheService || !WallpaperCacheService.initialized) {
// Fallback to original if services not ready
const wallpaperPath = WallpaperService.getWallpaper(screen.name);
cachedWallpaperPath = wallpaperPath || "";
resolvedWallpaperPath = WallpaperService.getWallpaper(screen.name) || "";
return;
}
const wallpaperPath = WallpaperService.getWallpaper(screen.name);
if (!wallpaperPath) {
cachedWallpaperPath = "";
resolvedWallpaperPath = WallpaperService.getWallpaper(screen.name) || "";
if (resolvedWallpaperPath === "") {
return;
}
const compositorScale = CompositorService.getDisplayScale(screen.name);
const targetWidth = Math.round(width * compositorScale);
const targetHeight = Math.round(height * compositorScale);
if (targetWidth <= 0 || targetHeight <= 0) {
cachedWallpaperPath = wallpaperPath;
return;
}
WallpaperCacheService.getPreprocessed(wallpaperPath, screen.name, targetWidth, targetHeight, function (cachedPath, success) {
WallpaperCacheService.getPreprocessed(resolvedWallpaperPath, screen.name, targetWidth, targetHeight, function (cachedPath, success) {
if (success) {
cachedWallpaperPath = cachedPath;
} else {
// Fallback to original
cachedWallpaperPath = wallpaperPath;
resolvedWallpaperPath = cachedPath;
}
});
}
// Black backgound, in case image fails to load or takes a while
Rectangle {
anchors.fill: parent
color: "#000000"
}
Image {
id: lockBgImage
visible: source !== ""
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
source: cachedWallpaperPath || (screen ? WallpaperService.getWallpaper(screen.name) : "")
source: resolvedWallpaperPath
cache: true
smooth: true
mipmap: false