feat: add power menu & clipboard
This commit is contained in:
1 parent
6d583b4616
commit
9ca3b15764
6 files changed
+536
-88
No files matched your search
@@ -0,0 +1,212 @@
|
||||
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
|
||||
property var actions: [
|
||||
{ cmd: "loginctl lock-session" },
|
||||
{ cmd: "systemctl suspend" },
|
||||
{ cmd: "loginctl terminate-user $USER" },
|
||||
{ cmd: "systemctl reboot" },
|
||||
{ cmd: "systemctl poweroff" }
|
||||
]
|
||||
|
||||
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.background // Full screen dim/blur
|
||||
|
||||
Behavior on opacity { NumberAnimation { duration: Theme.animation.durationNormal } }
|
||||
opacity: rootState.logoutMenuOpen ? 1 : 0
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: rootState.logoutMenuOpen = false
|
||||
}
|
||||
|
||||
Item {
|
||||
id: container
|
||||
width: buttonRow.width
|
||||
height: buttonRow.height
|
||||
anchors.centerIn: parent
|
||||
|
||||
Behavior on scale { SpringAnimation { spring: 3; damping: 0.2 } }
|
||||
|
||||
Row {
|
||||
id: buttonRow
|
||||
spacing: Theme.geometry.spacing * 3
|
||||
|
||||
// Lock
|
||||
LogoutButton {
|
||||
icon: "🔒"
|
||||
label: "Lock"
|
||||
isSelected: logoutWindow.currentIndex === 0
|
||||
onClicked: executeAction(logoutWindow.actions[0].cmd)
|
||||
onHovered: logoutWindow.currentIndex = 0
|
||||
}
|
||||
|
||||
// Suspend
|
||||
LogoutButton {
|
||||
icon: "🌙"
|
||||
label: "Suspend"
|
||||
isSelected: logoutWindow.currentIndex === 1
|
||||
onClicked: executeAction(logoutWindow.actions[1].cmd)
|
||||
onHovered: logoutWindow.currentIndex = 1
|
||||
}
|
||||
|
||||
// Logout
|
||||
LogoutButton {
|
||||
icon: "🚪"
|
||||
label: "Logout"
|
||||
isSelected: logoutWindow.currentIndex === 2
|
||||
onClicked: executeAction(logoutWindow.actions[2].cmd)
|
||||
onHovered: logoutWindow.currentIndex = 2
|
||||
}
|
||||
|
||||
// Reboot
|
||||
LogoutButton {
|
||||
icon: "🔄"
|
||||
label: "Reboot"
|
||||
isSelected: logoutWindow.currentIndex === 3
|
||||
onClicked: executeAction(logoutWindow.actions[3].cmd)
|
||||
onHovered: logoutWindow.currentIndex = 3
|
||||
}
|
||||
|
||||
// Poweroff
|
||||
LogoutButton {
|
||||
icon: "⏻"
|
||||
label: "Shutdown"
|
||||
isDestructive: true
|
||||
isSelected: logoutWindow.currentIndex === 4
|
||||
onClicked: executeAction(logoutWindow.actions[4].cmd)
|
||||
onHovered: logoutWindow.currentIndex = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Key handling
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
|
||||
Keys.onEscapePressed: (event) => {
|
||||
rootState.logoutMenuOpen = false;
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
Keys.onLeftPressed: (event) => {
|
||||
if (logoutWindow.currentIndex > 0) {
|
||||
logoutWindow.currentIndex--;
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
Keys.onRightPressed: (event) => {
|
||||
if (logoutWindow.currentIndex < 4) {
|
||||
logoutWindow.currentIndex++;
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
Keys.onReturnPressed: (event) => {
|
||||
executeAction(logoutWindow.actions[logoutWindow.currentIndex].cmd);
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: actionProcess
|
||||
running: false
|
||||
}
|
||||
|
||||
function executeAction(cmd) {
|
||||
actionProcess.command = ["bash", "-c", cmd];
|
||||
actionProcess.running = true;
|
||||
rootState.logoutMenuOpen = false;
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
container.scale = 1.0;
|
||||
logoutWindow.currentIndex = 2; // Reset to center
|
||||
} else {
|
||||
container.scale = 0.95;
|
||||
}
|
||||
}
|
||||
|
||||
// Inline component for the big buttons
|
||||
component LogoutButton: Rectangle {
|
||||
property string icon: ""
|
||||
property string label: ""
|
||||
property bool isDestructive: false
|
||||
property bool isSelected: false
|
||||
signal clicked()
|
||||
signal hovered()
|
||||
|
||||
width: 120
|
||||
height: 120
|
||||
radius: Theme.geometry.radius
|
||||
color: Theme.colors.surface
|
||||
border.color: isSelected ? (isDestructive ? Theme.colors.alert : Theme.colors.primary) : Theme.colors.border
|
||||
border.width: isSelected ? 2 : 1
|
||||
|
||||
Behavior on scale { SpringAnimation { spring: 4; damping: 0.3 } }
|
||||
scale: isSelected ? 1.05 : 1.0
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.geometry.spacing
|
||||
|
||||
Text {
|
||||
text: parent.parent.icon
|
||||
font.pixelSize: 36
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: Theme.colors.text
|
||||
}
|
||||
|
||||
Text {
|
||||
text: parent.parent.label
|
||||
font.family: Theme.font.family
|
||||
font.pixelSize: 16
|
||||
font.bold: true
|
||||
color: Theme.colors.text
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: hoverArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: parent.hovered()
|
||||
onClicked: parent.clicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user