From 6e368601b40e0c496f84f2837c80f71501afde89 Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Thu, 13 Nov 2025 12:00:15 -0500 Subject: [PATCH] Wallpaper: improved image switching to avoid main thread micro freeze. --- Modules/Background/Background.qml | 41 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Modules/Background/Background.qml b/Modules/Background/Background.qml index 8c01040df..d5023fab4 100644 --- a/Modules/Background/Background.qml +++ b/Modules/Background/Background.qml @@ -306,20 +306,37 @@ Variants { duration: transitionType == "stripes" ? Settings.data.wallpaper.transitionDuration * 1.6 : Settings.data.wallpaper.transitionDuration easing.type: Easing.InOutCubic onFinished: { - // Assign new image to current BEFORE clearing to prevent flicker + // Strategy: Keep transitionProgress at 1.0 (showing nextWallpaper) + // until currentWallpaper finishes loading asynchronously const tempSource = nextWallpaper.source - currentWallpaper.source = tempSource - transitionProgress = 0.0 + const tempSourceSize = nextWallpaper.sourceSize - // Now clear nextWallpaper after currentWallpaper has the new source - // Force complete cleanup to free texture memory (~18-25MB per monitor) - Qt.callLater(() => { - nextWallpaper.source = "" - nextWallpaper.sourceSize = undefined - Qt.callLater(() => { - currentWallpaper.asynchronous = true - }) - }) + // Enable async loading to prevent blocking + currentWallpaper.asynchronous = true + + // Create one-time connection to wait for async load to complete + const onCurrentLoaded = function () { + if (currentWallpaper.status === Image.Ready || currentWallpaper.status === Image.Error) { + // Disconnect this handler + currentWallpaper.statusChanged.disconnect(onCurrentLoaded) + + // Now it's safe to reset progress and cleanup + transitionProgress = 0.0 + + // Force complete cleanup to free texture memory (~18-25MB per monitor) + Qt.callLater(() => { + nextWallpaper.source = "" + nextWallpaper.sourceSize = undefined + }) + } + } + + // Connect the handler BEFORE changing source + currentWallpaper.statusChanged.connect(onCurrentLoaded) + + // Trigger async load (keeps nextWallpaper visible via progress=1.0) + currentWallpaper.sourceSize = tempSourceSize + currentWallpaper.source = tempSource } }