diff --git a/Modules/Bar/Widgets/WallpaperSelector.qml b/Modules/Bar/Widgets/WallpaperSelector.qml index a7d61d795..421b2f7bc 100644 --- a/Modules/Bar/Widgets/WallpaperSelector.qml +++ b/Modules/Bar/Widgets/WallpaperSelector.qml @@ -42,7 +42,7 @@ NIconButton { PanelService.closeContextMenu(screen); if (action === "random-wallpaper") { - WallpaperService.setRandomWallpaper(); + WallpaperService.setRandomWallpaper(null); } } } diff --git a/Modules/Panels/ControlCenter/Widgets/WallpaperSelector.qml b/Modules/Panels/ControlCenter/Widgets/WallpaperSelector.qml index 184d024e1..4d8bb9a3f 100644 --- a/Modules/Panels/ControlCenter/Widgets/WallpaperSelector.qml +++ b/Modules/Panels/ControlCenter/Widgets/WallpaperSelector.qml @@ -11,5 +11,5 @@ NIconButtonHot { icon: "wallpaper-selector" tooltipText: I18n.tr("wallpaper.panel.title") onClicked: PanelService.getPanel("wallpaperPanel", screen)?.toggle() - onRightClicked: WallpaperService.setRandomWallpaper() + onRightClicked: WallpaperService.setRandomWallpaper(null) } diff --git a/Services/Control/IPCService.qml b/Services/Control/IPCService.qml index 9153333f9..75fb6583f 100644 --- a/Services/Control/IPCService.qml +++ b/Services/Control/IPCService.qml @@ -405,9 +405,12 @@ Item { } } - function random() { + function random(screen: string) { if (Settings.data.wallpaper.enabled) { - WallpaperService.setRandomWallpaper(); + if (screen === "all" || screen.trim().length === 0) { + screen = undefined; + } + WallpaperService.setRandomWallpaper(screen); } } diff --git a/Services/UI/WallpaperService.qml b/Services/UI/WallpaperService.qml index ac6dec433..99b18ee16 100644 --- a/Services/UI/WallpaperService.qml +++ b/Services/UI/WallpaperService.qml @@ -376,19 +376,29 @@ Singleton { } // ------------------------------------------------------------------- - function setRandomWallpaper() { + function setRandomWallpaper(screen) { Logger.d("Wallpaper", "setRandomWallpaper"); if (Settings.data.wallpaper.enableMultiMonitorDirectories) { - // Pick a random wallpaper per screen - for (var i = 0; i < Quickshell.screens.length; i++) { - var screenName = Quickshell.screens[i].name; - var wallpaperList = getWallpapersList(screenName); + if (screen === undefined) { + // Pick a random wallpaper per screen + for (var i = 0; i < Quickshell.screens.length; i++) { + var screenName = Quickshell.screens[i].name; + var wallpaperList = getWallpapersList(screenName); + if (wallpaperList.length > 0) { + var randomIndex = Math.floor(Math.random() * wallpaperList.length); + var randomPath = wallpaperList[randomIndex]; + changeWallpaper(randomPath, screenName); + } + } + } else { + // Pick a random wallpaper for the screen argument + var wallpaperList = getWallpapersList(screen); if (wallpaperList.length > 0) { var randomIndex = Math.floor(Math.random() * wallpaperList.length); var randomPath = wallpaperList[randomIndex]; - changeWallpaper(randomPath, screenName); + changeWallpaper(randomPath, screen); } } } else { @@ -398,7 +408,7 @@ Singleton { if (wallpaperList.length > 0) { var randomIndex = Math.floor(Math.random() * wallpaperList.length); var randomPath = wallpaperList[randomIndex]; - changeWallpaper(randomPath, undefined); + changeWallpaper(randomPath, screen); } } } @@ -470,7 +480,7 @@ Singleton { if (mode === "alphabetical") { setAlphabeticalWallpaper(); } else { - setRandomWallpaper(); + setRandomWallpaper(null); } }