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

powermenu: support user-defined custom power buttons (#2916)

This commit is contained in:
FormalSnake
2026-08-06 01:46:42 +01:00
committed by GitHub
parent adcafbcc8e
commit e203e76ccc
3 changed files with 21 additions and 1 deletions
+1
View File
@@ -973,6 +973,7 @@ Singleton {
property string customPowerActionHibernate: ""
property string customPowerActionReboot: ""
property string customPowerActionPowerOff: ""
property var customPowerButtons: []
property bool updaterHideWidget: false
property bool updaterCheckOnStart: false
@@ -526,6 +526,7 @@ var SPEC = {
customPowerActionHibernate: { def: "" },
customPowerActionReboot: { def: "" },
customPowerActionPowerOff: { def: "" },
customPowerButtons: { def: [] },
updaterHideWidget: { def: false },
updaterCheckOnStart: { def: false },
+19 -1
View File
@@ -129,6 +129,13 @@ DankModal {
switchUserRequested();
return;
}
if (action.startsWith("custom:")) {
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
close();
if (button?.command)
Quickshell.execDetached(["sh", "-c", button.command]);
return;
}
close();
root.powerActionRequested(action, "", "");
}
@@ -172,13 +179,14 @@ DankModal {
function updateVisibleActions() {
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
const customButtons = SettingsData.customPowerButtons || [];
visibleActions = allActions.filter(action => {
if (action === "hibernate" && !SessionService.hibernateSupported)
return false;
if (action === "softreboot" && !SessionService.softRebootSupported)
return false;
return true;
});
}).concat(customButtons.map((button, i) => "custom:" + i));
if (!SettingsData.powerMenuGridLayout)
return;
@@ -218,6 +226,14 @@ DankModal {
}
function getActionData(action) {
if (action.startsWith("custom:")) {
const button = (SettingsData.customPowerButtons || [])[parseInt(action.slice(7), 10)];
return {
"icon": button?.icon || "terminal",
"label": button?.label || button?.command || "",
"key": ""
};
}
switch (action) {
case "reboot":
return {
@@ -688,6 +704,7 @@ DankModal {
height: 16
radius: 4
color: Theme.onSurface_12
visible: gridButtonRect.actionData.key !== ""
anchors.horizontalCenter: parent.horizontalCenter
StyledText {
@@ -820,6 +837,7 @@ DankModal {
height: 20
radius: 4
color: Theme.onSurface_12
visible: listButtonRect.actionData.key !== ""
anchors {
right: parent.right
rightMargin: Theme.spacingM