1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-06 21:48:30 -04:00

feat(wallpaper): support random cycling order (#2936)

This commit is contained in:
Huỳnh Thiện Lộc
2026-08-05 08:21:52 +07:00
committed by GitHub
parent 158c0c12d8
commit 99b0dc596d
5 changed files with 114 additions and 4 deletions
+38
View File
@@ -148,6 +148,7 @@ Singleton {
property var includedTransitions: availableWallpaperTransitions.filter(t => t !== "none") property var includedTransitions: availableWallpaperTransitions.filter(t => t !== "none")
property bool wallpaperCyclingEnabled: false property bool wallpaperCyclingEnabled: false
property bool wallpaperCyclingRandom: false
property string wallpaperCyclingMode: "interval" property string wallpaperCyclingMode: "interval"
property int wallpaperCyclingInterval: 300 property int wallpaperCyclingInterval: 300
property string wallpaperCyclingTime: "06:00" property string wallpaperCyclingTime: "06:00"
@@ -646,6 +647,11 @@ Singleton {
saveSettings(); saveSettings();
} }
function setWallpaperCyclingRandom(random) {
wallpaperCyclingRandom = random;
saveSettings();
}
function setWallpaperCyclingMode(mode) { function setWallpaperCyclingMode(mode) {
wallpaperCyclingMode = mode; wallpaperCyclingMode = mode;
saveSettings(); saveSettings();
@@ -692,6 +698,37 @@ Singleton {
saveSettings(); saveSettings();
} }
function setMonitorCyclingRandom(screenName, random) {
var screen = null;
var screens = Quickshell.screens;
for (var i = 0; i < screens.length; i++) {
if (screens[i].name === screenName) {
screen = screens[i];
break;
}
}
if (!screen) {
log.warn("Screen not found");
return;
}
var identifier = typeof SettingsData !== "undefined" ? SettingsData.getScreenDisplayName(screen) : screen.name;
var newSettings = {};
for (var key in monitorCyclingSettings) {
var isThisScreen = key === screen.name || (screen.model && key === screen.model);
if (!isThisScreen) {
newSettings[key] = monitorCyclingSettings[key];
}
}
newSettings[identifier] = getMonitorCyclingSettings(screenName);
newSettings[identifier].random = random;
monitorCyclingSettings = newSettings;
saveSettings();
}
function setMonitorCyclingMode(screenName, mode) { function setMonitorCyclingMode(screenName, mode) {
var screen = null; var screen = null;
var screens = Quickshell.screens; var screens = Quickshell.screens;
@@ -1322,6 +1359,7 @@ Singleton {
function getMonitorCyclingSettings(screenName) { function getMonitorCyclingSettings(screenName) {
var defaults = { var defaults = {
"enabled": false, "enabled": false,
"random": false,
"mode": "interval", "mode": "interval",
"interval": 300, "interval": 300,
"time": "06:00" "time": "06:00"
@@ -19,6 +19,7 @@ var SPEC = {
includedTransitions: { def: ["fade", "wipe", "disc", "stripes", "iris bloom", "pixelate", "portal"] }, includedTransitions: { def: ["fade", "wipe", "disc", "stripes", "iris bloom", "pixelate", "portal"] },
wallpaperCyclingEnabled: { def: false }, wallpaperCyclingEnabled: { def: false },
wallpaperCyclingRandom: { def: false },
wallpaperCyclingMode: { def: "interval" }, wallpaperCyclingMode: { def: "interval" },
wallpaperCyclingInterval: { def: 300 }, wallpaperCyclingInterval: { def: 300 },
wallpaperCyclingTime: { def: "06:00" }, wallpaperCyclingTime: { def: "06:00" },
@@ -977,6 +977,33 @@ Item {
} }
} }
SettingsToggleRow {
id: randomToggle
tab: "wallpaper"
tags: ["cycling", "automatic", "random", "shuffle"]
settingKey: "wallpaperCyclingRandom"
width: parent.width - Theme.spacingM * 2
text: I18n.tr("Random Order")
description: I18n.tr("Select a random wallpaper instead of cycling in alphabetical order")
checked: SessionData.perMonitorWallpaper ? SessionData.getMonitorCyclingSettings(selectedMonitorName).random : SessionData.wallpaperCyclingRandom
onToggled: toggled => {
if (SessionData.perMonitorWallpaper) {
SessionData.setMonitorCyclingRandom(selectedMonitorName, toggled);
} else {
SessionData.setWallpaperCyclingRandom(toggled);
}
}
Connections {
target: root
function onSelectedMonitorNameChanged() {
randomToggle.checked = Qt.binding(() => {
return SessionData.perMonitorWallpaper ? SessionData.getMonitorCyclingSettings(selectedMonitorName).random : SessionData.wallpaperCyclingRandom;
});
}
}
}
SettingsDropdownRow { SettingsDropdownRow {
id: intervalDropdown id: intervalDropdown
property var intervalOptions: [I18n.tr("5 seconds", "wallpaper interval"), I18n.tr("10 seconds", "wallpaper interval"), I18n.tr("15 seconds", "wallpaper interval"), I18n.tr("20 seconds", "wallpaper interval"), I18n.tr("25 seconds", "wallpaper interval"), I18n.tr("30 seconds", "wallpaper interval"), I18n.tr("35 seconds", "wallpaper interval"), I18n.tr("40 seconds", "wallpaper interval"), I18n.tr("45 seconds", "wallpaper interval"), I18n.tr("50 seconds", "wallpaper interval"), I18n.tr("55 seconds", "wallpaper interval"), I18n.tr("1 minute", "wallpaper interval"), I18n.tr("5 minutes", "wallpaper interval"), I18n.tr("15 minutes", "wallpaper interval"), I18n.tr("30 minutes", "wallpaper interval"), I18n.tr("1 hour", "wallpaper interval"), I18n.tr("1 hour 30 minutes", "wallpaper interval"), I18n.tr("2 hours", "wallpaper interval"), I18n.tr("3 hours", "wallpaper interval"), I18n.tr("4 hours", "wallpaper interval"), I18n.tr("6 hours", "wallpaper interval"), I18n.tr("8 hours", "wallpaper interval"), I18n.tr("12 hours", "wallpaper interval")] property var intervalOptions: [I18n.tr("5 seconds", "wallpaper interval"), I18n.tr("10 seconds", "wallpaper interval"), I18n.tr("15 seconds", "wallpaper interval"), I18n.tr("20 seconds", "wallpaper interval"), I18n.tr("25 seconds", "wallpaper interval"), I18n.tr("30 seconds", "wallpaper interval"), I18n.tr("35 seconds", "wallpaper interval"), I18n.tr("40 seconds", "wallpaper interval"), I18n.tr("45 seconds", "wallpaper interval"), I18n.tr("50 seconds", "wallpaper interval"), I18n.tr("55 seconds", "wallpaper interval"), I18n.tr("1 minute", "wallpaper interval"), I18n.tr("5 minutes", "wallpaper interval"), I18n.tr("15 minutes", "wallpaper interval"), I18n.tr("30 minutes", "wallpaper interval"), I18n.tr("1 hour", "wallpaper interval"), I18n.tr("1 hour 30 minutes", "wallpaper interval"), I18n.tr("2 hours", "wallpaper interval"), I18n.tr("3 hours", "wallpaper interval"), I18n.tr("4 hours", "wallpaper interval"), I18n.tr("6 hours", "wallpaper interval"), I18n.tr("8 hours", "wallpaper interval"), I18n.tr("12 hours", "wallpaper interval")]
@@ -231,11 +231,28 @@ Singleton {
if (currentIndex === -1) if (currentIndex === -1)
currentIndex = 0; currentIndex = 0;
let targetIndex; let isRandom = false;
if (goToPrevious) { if (targetScreenName) {
targetIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1; isRandom = !!SessionData.getMonitorCyclingSettings(targetScreenName).random;
} else { } else {
targetIndex = (currentIndex + 1) % wallpaperList.length; isRandom = !!SessionData.wallpaperCyclingRandom;
}
let targetIndex;
if (isRandom) {
if (wallpaperList.length > 1) {
do {
targetIndex = Math.floor(Math.random() * wallpaperList.length);
} while (targetIndex === currentIndex);
} else {
targetIndex = 0;
}
} else {
if (goToPrevious) {
targetIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1;
} else {
targetIndex = (currentIndex + 1) % wallpaperList.length;
}
} }
const targetWallpaper = wallpaperList[targetIndex]; const targetWallpaper = wallpaperList[targetIndex];
if (!targetWallpaper || targetWallpaper === currentPath) if (!targetWallpaper || targetWallpaper === currentPath)
@@ -338,6 +338,33 @@
], ],
"icon": "palette" "icon": "palette"
}, },
{
"section": "wallpaperCyclingRandom",
"label": "Random Order",
"tabIndex": 0,
"category": "Personalization",
"keywords": [
"alphabetical",
"appearance",
"automatic",
"background",
"bg",
"custom",
"customize",
"cycling",
"desktop",
"image",
"order",
"personal",
"personalization",
"picture",
"random",
"select",
"shuffle",
"wallpaper"
],
"description": "Select a random wallpaper instead of cycling in alphabetical order"
},
{ {
"section": "wallpaperTransition", "section": "wallpaperTransition",
"label": "Transition Effect", "label": "Transition Effect",