Add screen argument to IPC wallpaper random

* Add argument to specify on which screen to apply a random wallpaper
* if `all` is provided, the old behavior is kept: a random wallpaper is
applied to all screen.
This commit is contained in:
Florian Boulay
2026-02-05 13:22:08 +01:00
parent c6759fb9f4
commit 107ea5698a
4 changed files with 25 additions and 12 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ NIconButton {
PanelService.closeContextMenu(screen);
if (action === "random-wallpaper") {
WallpaperService.setRandomWallpaper();
WallpaperService.setRandomWallpaper(null);
}
}
}
@@ -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)
}
+5 -2
View File
@@ -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);
}
}
+18 -8
View File
@@ -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);
}
}