power menu

This commit is contained in:
2026-03-02 19:36:42 +02:00
parent 505d28adca
commit aef27304e4

View File

@@ -37,6 +37,8 @@ Item {
property bool inBluetoothMenu: false property bool inBluetoothMenu: false
property bool inWallpaperMenu: false property bool inWallpaperMenu: false
property bool inNotificationsMenu: false property bool inNotificationsMenu: false
property bool inPowerMenu: false
property bool inPowerConfirm: false
property bool isSelected: false property bool isSelected: false
@@ -82,7 +84,7 @@ Item {
} }
function currentAction() { function currentAction() {
if (root.inBluetoothMenu || root.inWallpaperMenu || root.inNotificationsMenu) if (root.inBluetoothMenu || root.inWallpaperMenu || root.inNotificationsMenu || root.inPowerMenu)
return null; return null;
return menuLength() > 0 ? menuAt(activeSelection) : null; return menuLength() > 0 ? menuAt(activeSelection) : null;
} }
@@ -197,6 +199,9 @@ Item {
property int bluetoothActionIndex: 1 property int bluetoothActionIndex: 1
property int wallpaperActionIndex: 2 property int wallpaperActionIndex: 2
property int notificationsActionIndex: 3 property int notificationsActionIndex: 3
property int powerActionIndex: 4
property int pendingPowerActionIndex: 0
property var pendingPowerCommand: []
property var actions: [ property var actions: [
{ {
name: "Master Volume", name: "Master Volume",
@@ -252,6 +257,8 @@ Item {
root.inNotificationsMenu = true; root.inNotificationsMenu = true;
root.inBluetoothMenu = false; root.inBluetoothMenu = false;
root.inWallpaperMenu = false; root.inWallpaperMenu = false;
root.inPowerMenu = false;
root.inPowerConfirm = false;
root.isSelected = false; root.isSelected = false;
root.activeSelection = 0; root.activeSelection = 0;
root.clampSelection(); root.clampSelection();
@@ -259,6 +266,48 @@ Item {
getState: function () { getState: function () {
return ""; return "";
} }
},
{
name: "Power",
ent: function () {
root.inPowerMenu = true;
root.inPowerConfirm = false;
root.inBluetoothMenu = false;
root.inWallpaperMenu = false;
root.inNotificationsMenu = false;
root.isSelected = false;
root.activeSelection = 0;
root.pendingPowerActionIndex = 0;
root.pendingPowerCommand = [];
root.clampSelection();
},
getState: function () {
return "";
}
}
]
property var powerActions: [
{
name: "Shutdown",
command: ["systemctl", "poweroff"]
},
{
name: "Reboot",
command: ["systemctl", "reboot"]
},
{
name: "Logout",
command: ["hyprctl", "dispatch", "exit"]
}
]
property var powerConfirmActions: [
{
name: "Yes"
},
{
name: "No"
} }
] ]
@@ -277,7 +326,7 @@ Item {
} }
] ]
property var menuModel: root.inBluetoothMenu ? Bluetooth.devices : (root.inWallpaperMenu ? wallpaperFolderModel : (root.inNotificationsMenu ? notificationActions : actions)) property var menuModel: root.inBluetoothMenu ? Bluetooth.devices : (root.inWallpaperMenu ? wallpaperFolderModel : (root.inNotificationsMenu ? notificationActions : (root.inPowerMenu ? (root.inPowerConfirm ? powerConfirmActions : powerActions) : actions)))
FolderListModel { FolderListModel {
id: wallpaperFolderModel id: wallpaperFolderModel
@@ -308,6 +357,27 @@ Item {
id: wallpaperApplyProcess id: wallpaperApplyProcess
} }
Process {
id: powerCommandProcess
}
function executePowerCommand(command) {
if (!command || command.length === 0)
return;
powerCommandProcess.running = false;
powerCommandProcess.command = command;
powerCommandProcess.running = true;
if (manager && manager.closeShell)
manager.closeShell();
}
function pendingPowerActionName() {
if (pendingPowerActionIndex < 0 || pendingPowerActionIndex >= powerActions.length)
return "";
var action = powerActions[pendingPowerActionIndex];
return action && action.name ? String(action.name) : "";
}
Connections { Connections {
target: Bluetooth.devices target: Bluetooth.devices
ignoreUnknownSignals: true ignoreUnknownSignals: true
@@ -353,7 +423,7 @@ Item {
} }
Text { Text {
text: root.inBluetoothMenu ? "BLUETOOTH" : (root.inWallpaperMenu ? "WALLPAPER" : (root.inNotificationsMenu ? "NOTIFICATIONS" : "CONFIG")) text: root.inPowerConfirm ? "CONFIRM" : (root.inPowerMenu ? "POWER" : (root.inBluetoothMenu ? "BLUETOOTH" : (root.inWallpaperMenu ? "WALLPAPER" : (root.inNotificationsMenu ? "NOTIFICATIONS" : "CONFIG"))))
font.family: "8bitoperator JVE" font.family: "8bitoperator JVE"
font.pixelSize: 71 font.pixelSize: 71
renderType: Text.NativeRendering renderType: Text.NativeRendering
@@ -365,6 +435,20 @@ Item {
y: 32 y: 32
} }
Text {
visible: root.inPowerConfirm
text: root.pendingPowerActionName().toUpperCase() + "?"
font.family: "8bitoperator JVE"
font.pixelSize: 44
renderType: Text.NativeRendering
font.hintingPreference: Font.PreferNoHinting
smooth: false
antialiasing: false
anchors.horizontalCenter: parent.horizontalCenter
color: "#fefe00"
y: 102
}
Repeater { Repeater {
id: bluetoothRepeater id: bluetoothRepeater
model: root.menuModel model: root.menuModel
@@ -401,7 +485,7 @@ Item {
antialiasing: false antialiasing: false
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
elide: Text.ElideRight elide: Text.ElideRight
color: (root.activeSelection == index && (root.isSelected == true || root.inBluetoothMenu || root.inWallpaperMenu)) ? "#fefe00" : "#ffffff" color: (root.activeSelection == index && (root.isSelected == true || root.inBluetoothMenu || root.inWallpaperMenu || root.inPowerMenu)) ? "#fefe00" : "#ffffff"
} }
// Option state // Option state
@@ -417,7 +501,7 @@ Item {
font.hintingPreference: Font.PreferNoHinting font.hintingPreference: Font.PreferNoHinting
smooth: false smooth: false
antialiasing: false antialiasing: false
color: (root.activeSelection == index && (root.isSelected == true || root.inBluetoothMenu || root.inWallpaperMenu)) ? "#fefe00" : "#ffffff" color: (root.activeSelection == index && (root.isSelected == true || root.inBluetoothMenu || root.inWallpaperMenu || root.inPowerMenu)) ? "#fefe00" : "#ffffff"
} }
} }
} }
@@ -429,13 +513,13 @@ Item {
function handleKey(key) { function handleKey(key) {
switch (key) { switch (key) {
case Qt.Key_Up: case Qt.Key_Up:
if (root.inBluetoothMenu || root.inWallpaperMenu || root.isSelected === false) { if (root.inBluetoothMenu || root.inWallpaperMenu || root.inPowerMenu || root.isSelected === false) {
activeSelection = wrapIndex(activeSelection - 1); activeSelection = wrapIndex(activeSelection - 1);
root.ensureVisible(); root.ensureVisible();
} }
return true; return true;
case Qt.Key_Down: case Qt.Key_Down:
if (root.inBluetoothMenu || root.inWallpaperMenu || root.isSelected === false) { if (root.inBluetoothMenu || root.inWallpaperMenu || root.inPowerMenu || root.isSelected === false) {
activeSelection = wrapIndex(activeSelection + 1); activeSelection = wrapIndex(activeSelection + 1);
root.ensureVisible(); root.ensureVisible();
} }
@@ -477,6 +561,24 @@ Item {
const notificationAction = menuAt(activeSelection); const notificationAction = menuAt(activeSelection);
if (notificationAction && notificationAction.ent) if (notificationAction && notificationAction.ent)
notificationAction.ent(); notificationAction.ent();
} else if (root.inPowerConfirm) {
const confirmAction = menuAt(activeSelection);
if (confirmAction && confirmAction.name === "Yes") {
root.executePowerCommand(root.pendingPowerCommand);
} else {
root.inPowerConfirm = false;
root.activeSelection = root.pendingPowerActionIndex;
root.clampSelection();
}
} else if (root.inPowerMenu) {
const powerAction = menuAt(activeSelection);
if (powerAction && powerAction.command) {
root.pendingPowerActionIndex = activeSelection;
root.pendingPowerCommand = powerAction.command;
root.inPowerConfirm = true;
root.activeSelection = 0;
root.clampSelection();
}
} else { } else {
const a = currentAction(); const a = currentAction();
if (a && a.ent) { if (a && a.ent) {
@@ -496,6 +598,19 @@ Item {
root.scrollOffset = 0; root.scrollOffset = 0;
root.activeSelection = root.wallpaperActionIndex; root.activeSelection = root.wallpaperActionIndex;
root.clampSelection(); root.clampSelection();
} else if (root.inPowerConfirm) {
root.inPowerConfirm = false;
root.isSelected = false;
root.activeSelection = root.pendingPowerActionIndex;
root.clampSelection();
} else if (root.inPowerMenu) {
root.inPowerMenu = false;
root.inPowerConfirm = false;
root.isSelected = false;
root.pendingPowerActionIndex = 0;
root.pendingPowerCommand = [];
root.activeSelection = root.powerActionIndex;
root.clampSelection();
} else if (root.inNotificationsMenu) { } else if (root.inNotificationsMenu) {
root.inNotificationsMenu = false; root.inNotificationsMenu = false;
root.isSelected = false; root.isSelected = false;
@@ -524,6 +639,10 @@ Item {
root.inBluetoothMenu = false; root.inBluetoothMenu = false;
root.inWallpaperMenu = false; root.inWallpaperMenu = false;
root.inNotificationsMenu = false; root.inNotificationsMenu = false;
root.inPowerMenu = false;
root.inPowerConfirm = false;
root.pendingPowerActionIndex = 0;
root.pendingPowerCommand = [];
root.scrollOffset = 0; root.scrollOffset = 0;
root.refreshCurrentWallpaper(); root.refreshCurrentWallpaper();
ShellInputManager.registerHandler("quickSettings", handleKey); ShellInputManager.registerHandler("quickSettings", handleKey);