This repository has been archived on 2026-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

306 lines
10 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Io
import "../Shared"
PanelWindow {
id: logoutWindow
property QtObject rootState
property int currentIndex: 2 // Default to Logout in the middle
// Destructive actions (Reboot/Shutdown) require a second confirmation
// before executing - selecting them the first time just arms them.
property int armedIndex: -1
property var actions: [
{ cmd: "loginctl lock-session", key: "L", label: "Lock", sub: "loginctl lock-session", destructive: false },
{ cmd: "loginctl terminate-user $USER", key: "E", label: "Logout", sub: "loginctl terminate-user", destructive: false },
{ cmd: "systemctl suspend", key: "U", label: "Suspend", sub: "systemctl suspend", destructive: false },
{ cmd: "systemctl reboot", key: "R", label: "Reboot", sub: "systemctl reboot", destructive: true },
{ cmd: "systemctl poweroff", key: "S", label: "Shutdown", sub: "systemctl poweroff", destructive: true }
]
visible: rootState.logoutMenuOpen
anchors {
top: true
bottom: true
left: true
right: true
}
exclusiveZone: 0
color: "transparent"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.namespace: "quickshell-logout"
WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
MouseArea {
anchors.fill: parent
onClicked: rootState.logoutMenuOpen = false
}
Rectangle {
anchors.fill: parent
color: Theme.colors.overlay // Full screen dim
Behavior on opacity { NumberAnimation { duration: Theme.animation.durationNormal } }
opacity: rootState.logoutMenuOpen ? 1 : 0
MouseArea {
anchors.fill: parent
onClicked: rootState.logoutMenuOpen = false
}
Surface {
id: container
width: modalColumn.width + Theme.geometry.padding * 2
height: modalColumn.height + Theme.geometry.padding * 2
anchors.centerIn: parent
tint: Theme.colors.primary
glow: true
Behavior on scale { NumberAnimation { duration: Theme.animation.durationFast; easing.type: Easing.OutCubic } }
MouseArea {
anchors.fill: parent
}
Column {
id: modalColumn
anchors.centerIn: parent
spacing: Theme.geometry.spacing
// Title strip
Item {
width: buttonRow.width
height: 24
Row {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.geometry.spacing / 2
Rectangle {
width: 10
height: 10
anchors.verticalCenter: parent.verticalCenter
color: Theme.colors.primary
border.width: Theme.geometry.borderWidth
border.color: Theme.colors.crust
}
Text {
text: "[SYSTEM // POWER MANAGEMENT]"
color: Theme.colors.text
font.family: Theme.font.family
font.bold: true
font.pixelSize: Theme.type.caption
}
}
Text {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: logoutWindow.armedIndex >= 0 ? "LATCH: ARMED" : "LATCH: IDLE"
color: logoutWindow.armedIndex >= 0 ? Theme.colors.alert : Theme.colors.textMuted
font.family: Theme.font.family
font.bold: true
font.pixelSize: Theme.type.caption
}
}
Row {
id: buttonRow
spacing: Theme.geometry.spacing * 2
Repeater {
model: logoutWindow.actions
delegate: LogoutButton {
action: modelData
index: model.index
isSelected: logoutWindow.currentIndex === model.index
isArmed: logoutWindow.armedIndex === model.index
onClicked: logoutWindow.select(model.index)
onHovered: logoutWindow.currentIndex = model.index
}
}
}
HintBar {
anchors.horizontalCenter: parent.horizontalCenter
hints: [
{ key: "L/E/U/R/S", label: "Select" },
{ key: "↵", label: "Confirm" },
{ key: "Esc", label: "Abort" }
]
}
}
}
}
// Key handling
Item {
anchors.fill: parent
focus: true
Keys.onEscapePressed: (event) => {
if (logoutWindow.armedIndex >= 0) {
logoutWindow.armedIndex = -1;
} else {
rootState.logoutMenuOpen = false;
}
event.accepted = true;
}
Keys.onLeftPressed: (event) => {
if (logoutWindow.currentIndex > 0) logoutWindow.currentIndex--;
logoutWindow.armedIndex = -1;
event.accepted = true;
}
Keys.onRightPressed: (event) => {
if (logoutWindow.currentIndex < logoutWindow.actions.length - 1) logoutWindow.currentIndex++;
logoutWindow.armedIndex = -1;
event.accepted = true;
}
Keys.onReturnPressed: (event) => {
logoutWindow.select(logoutWindow.currentIndex);
event.accepted = true;
}
Keys.onPressed: (event) => {
for (let i = 0; i < logoutWindow.actions.length; i++) {
if (event.text.toUpperCase() === logoutWindow.actions[i].key) {
logoutWindow.currentIndex = i;
logoutWindow.select(i);
event.accepted = true;
return;
}
}
}
}
Process {
id: actionProcess
running: false
}
// Non-destructive actions execute immediately. Destructive ones
// (Reboot/Shutdown) arm on first selection and only execute once armed
// and selected again - the "dual-stage confirmation / latch" from the
// power-menu design.
function select(index) {
let action = logoutWindow.actions[index];
if (action.destructive && logoutWindow.armedIndex !== index) {
logoutWindow.armedIndex = index;
return;
}
actionProcess.command = ["bash", "-c", action.cmd];
actionProcess.running = true;
logoutWindow.armedIndex = -1;
rootState.logoutMenuOpen = false;
}
onVisibleChanged: {
if (visible) {
container.scale = 1.0;
logoutWindow.currentIndex = 2; // Reset to center
logoutWindow.armedIndex = -1;
} else {
container.scale = 0.95;
}
}
// Inline component for the big power-action tiles.
component LogoutButton: Surface {
id: button
property var action
property int index: 0
property bool isSelected: false
property bool isArmed: false
signal clicked()
signal hovered()
readonly property color actionColor: isArmed ? Theme.colors.alert
: action.destructive ? Theme.colors.alert
: Theme.colors.primary
width: 128
height: 128
color: isSelected ? Theme.colors.surfaceHover : Theme.colors.surface
tint: isSelected || isArmed ? actionColor : Theme.colors.border
glow: isSelected || isArmed
pressed: hoverArea.pressed
Column {
anchors.centerIn: parent
spacing: Theme.geometry.spacing / 2
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: Theme.geometry.spacing / 2
Rectangle {
width: 16
height: 16
anchors.verticalCenter: parent.verticalCenter
color: button.isArmed ? Theme.colors.alert : "transparent"
border.width: Theme.geometry.borderWidth
border.color: Theme.colors.crust
Text {
anchors.centerIn: parent
text: button.action.key
font.family: Theme.font.family
font.bold: true
font.pixelSize: 10
color: button.isArmed ? Theme.colors.textOnAccent : Theme.colors.text
}
}
Text {
anchors.verticalCenter: parent.verticalCenter
text: button.isArmed ? "ARMED" : ("#0" + (button.index + 1))
font.family: Theme.font.family
font.bold: true
font.pixelSize: Theme.type.caption
color: button.isArmed ? Theme.colors.alert : Theme.colors.textMuted
}
}
Text {
text: button.action.label
font.family: Theme.font.headlineFamily
font.pixelSize: 16
font.bold: true
font.capitalization: Font.AllUppercase
color: Theme.colors.text
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: button.action.sub
font.family: Theme.font.family
font.pixelSize: 9
color: button.action.destructive ? Theme.colors.alert : Theme.colors.textMuted
width: button.width - Theme.geometry.spacing * 2
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
anchors.horizontalCenter: parent.horizontalCenter
}
}
MouseArea {
id: hoverArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: button.hovered()
onClicked: button.clicked()
}
}
}