1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-06 05:28:29 -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 customPowerActionHibernate: ""
property string customPowerActionReboot: "" property string customPowerActionReboot: ""
property string customPowerActionPowerOff: "" property string customPowerActionPowerOff: ""
property var customPowerButtons: []
property bool updaterHideWidget: false property bool updaterHideWidget: false
property bool updaterCheckOnStart: false property bool updaterCheckOnStart: false
@@ -526,6 +526,7 @@ var SPEC = {
customPowerActionHibernate: { def: "" }, customPowerActionHibernate: { def: "" },
customPowerActionReboot: { def: "" }, customPowerActionReboot: { def: "" },
customPowerActionPowerOff: { def: "" }, customPowerActionPowerOff: { def: "" },
customPowerButtons: { def: [] },
updaterHideWidget: { def: false }, updaterHideWidget: { def: false },
updaterCheckOnStart: { def: false }, updaterCheckOnStart: { def: false },
+19 -1
View File
@@ -129,6 +129,13 @@ DankModal {
switchUserRequested(); switchUserRequested();
return; 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(); close();
root.powerActionRequested(action, "", ""); root.powerActionRequested(action, "", "");
} }
@@ -172,13 +179,14 @@ DankModal {
function updateVisibleActions() { function updateVisibleActions() {
const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"]; const allActions = SettingsData.powerMenuActions || ["reboot", "logout", "poweroff", "lock", "suspend", "restart"];
const customButtons = SettingsData.customPowerButtons || [];
visibleActions = allActions.filter(action => { visibleActions = allActions.filter(action => {
if (action === "hibernate" && !SessionService.hibernateSupported) if (action === "hibernate" && !SessionService.hibernateSupported)
return false; return false;
if (action === "softreboot" && !SessionService.softRebootSupported) if (action === "softreboot" && !SessionService.softRebootSupported)
return false; return false;
return true; return true;
}); }).concat(customButtons.map((button, i) => "custom:" + i));
if (!SettingsData.powerMenuGridLayout) if (!SettingsData.powerMenuGridLayout)
return; return;
@@ -218,6 +226,14 @@ DankModal {
} }
function getActionData(action) { 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) { switch (action) {
case "reboot": case "reboot":
return { return {
@@ -688,6 +704,7 @@ DankModal {
height: 16 height: 16
radius: 4 radius: 4
color: Theme.onSurface_12 color: Theme.onSurface_12
visible: gridButtonRect.actionData.key !== ""
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
StyledText { StyledText {
@@ -820,6 +837,7 @@ DankModal {
height: 20 height: 20
radius: 4 radius: 4
color: Theme.onSurface_12 color: Theme.onSurface_12
visible: listButtonRect.actionData.key !== ""
anchors { anchors {
right: parent.right right: parent.right
rightMargin: Theme.spacingM rightMargin: Theme.spacingM