From 26fc6098dc457988f421c2e3bafc1b794a491d98 Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Fri, 29 Aug 2025 21:19:17 -0400 Subject: [PATCH] Wallpaper: added random transition + fixed "none" transition --- Commons/Settings.qml | 2 +- Modules/Background/Background.qml | 80 +++++++++++++++++-------------- Modules/Background/Overview.qml | 2 +- Services/WallpaperService.qml | 10 ++++ 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index b2759fb..73236cd 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -169,7 +169,7 @@ Singleton { property bool randomEnabled: false property int randomIntervalSec: 300 // 5 min property int transitionDuration: 1500 // 1500 ms - property string transitionType: "fade" + property string transitionType: "random" property list monitors: [] } diff --git a/Modules/Background/Background.qml b/Modules/Background/Background.qml index 9d8a5f9..198c94c 100644 --- a/Modules/Background/Background.qml +++ b/Modules/Background/Background.qml @@ -19,8 +19,10 @@ Variants { // Internal state management property bool firstWallpaper: true + property string transitionType: 'fade' property bool transitioning: false property real transitionProgress: 0.0 + readonly property var allTransitions: WallpaperService.allTransitions // Wipe direction: 0=left, 1=right, 2=up, 3=down property real wipeDirection: 0 @@ -38,29 +40,44 @@ Variants { return } - switch (Settings.data.wallpaper.transitionType) { - case "none": - setWallpaperImmediate(servicedWallpaper) - break - case "wipe_left": - wipeDirection = 0 - setWallpaperWithTransition(servicedWallpaper) - break - case "wipe_right": - wipeDirection = 1 - setWallpaperWithTransition(servicedWallpaper) - break - case "wipe_up": - wipeDirection = 2 - setWallpaperWithTransition(servicedWallpaper) - break - case "wipe_down": - wipeDirection = 3 - setWallpaperWithTransition(servicedWallpaper) - break - default: - setWallpaperWithTransition(servicedWallpaper) - break + // Get the transitionType from the settings + transitionType = Settings.data.wallpaper.transitionType + + if (transitionType == 'random') { + var index = Math.floor(Math.random() * allTransitions.length) + transitionType = allTransitions[index] + } + + // Ensure the transition type really exists + if (transitionType !== "none" && !allTransitions.includes(transitionType)) { + transitionType = 'fade' + } + + Logger.log("Background", "Using transition:", transitionType) + + switch (transitionType) { + case "none": + setWallpaperImmediate(servicedWallpaper) + break + case "wipe_left": + wipeDirection = 0 + setWallpaperWithTransition(servicedWallpaper) + break + case "wipe_right": + wipeDirection = 1 + setWallpaperWithTransition(servicedWallpaper) + break + case "wipe_up": + wipeDirection = 2 + setWallpaperWithTransition(servicedWallpaper) + break + case "wipe_down": + wipeDirection = 3 + setWallpaperWithTransition(servicedWallpaper) + break + default: + setWallpaperWithTransition(servicedWallpaper) + break } } } @@ -83,10 +100,10 @@ Variants { anchors.fill: parent fillMode: Image.PreserveAspectCrop source: "" - cache: true smooth: true mipmap: false visible: false + cache: false } Image { @@ -94,17 +111,17 @@ Variants { anchors.fill: parent fillMode: Image.PreserveAspectCrop source: "" - cache: true smooth: true mipmap: false visible: false + cache: false } // Fade transition shader ShaderEffect { id: fadeShader anchors.fill: parent - visible: Settings.data.wallpaper.transitionType === 'fade' + visible: transitionType === 'fade' || transitionType === 'none' property variant source1: currentWallpaper property variant source2: nextWallpaper @@ -116,7 +133,7 @@ Variants { ShaderEffect { id: wipeShader anchors.fill: parent - visible: Settings.data.wallpaper.transitionType.startsWith('wipe_') + visible: transitionType.startsWith('wipe_') property variant source1: currentWallpaper property variant source2: nextWallpaper @@ -134,14 +151,7 @@ Variants { from: 0.0 to: 1.0 duration: Settings.data.wallpaper.transitionDuration ?? 1000 - easing.type: { - const transitionType = Settings.data.wallpaper.transitionType ?? 'fade' - if (transitionType.startsWith('wipe_')) { - return Easing.InOutCubic - } - return Easing.InOutCubic - } - + easing.type: transitionType.startsWith('wipe_') ? Easing.InOutCubic : Easing.InOutCubic onFinished: { // Swap images after transition completes currentWallpaper.source = nextWallpaper.source diff --git a/Modules/Background/Overview.qml b/Modules/Background/Overview.qml index 32237d1..f976efe 100644 --- a/Modules/Background/Overview.qml +++ b/Modules/Background/Overview.qml @@ -37,9 +37,9 @@ Variants { anchors.fill: parent fillMode: Image.PreserveAspectCrop source: WallpaperService.getWallpaper(modelData.name) - cache: true smooth: true mipmap: false + cache: false } MultiEffect { diff --git a/Services/WallpaperService.qml b/Services/WallpaperService.qml index 15742c3..83c2a60 100644 --- a/Services/WallpaperService.qml +++ b/Services/WallpaperService.qml @@ -19,6 +19,10 @@ Singleton { key: "none" name: "None" } + ListElement { + key: "random" + name: "Random" + } ListElement { key: "fade" name: "Fade" @@ -41,6 +45,12 @@ Singleton { } } + // All transition keys but filter out "random" + readonly property var allTransitions: Array.from({ + "length": transitionsModel.count + }, (_, i) => transitionsModel.get(i).key).filter( + key => key !== "random" && key != "none") + property var wallpaperLists: ({}) property int scanningCount: 0 readonly property bool scanning: (scanningCount > 0)