From 8504f8ddd2b5d3ba92d8e65a27327eb3d15d036f Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Mon, 18 Aug 2025 23:41:59 -0400 Subject: [PATCH] power menu!!! --- modules/Shell.qml | 2 + modules/Shortcuts.qml | 7 ++ modules/powermenu/PowerMenu.qml | 128 ++++++++++++++++++++++++++++++++ services/Visibility.qml | 1 + widgets/StyledText.qml | 8 +- 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 modules/powermenu/PowerMenu.qml diff --git a/modules/Shell.qml b/modules/Shell.qml index 4d3403c..8e92771 100644 --- a/modules/Shell.qml +++ b/modules/Shell.qml @@ -1,4 +1,5 @@ import "bar" +import "powermenu" import Quickshell import Quickshell.Wayland import Quickshell.Hyprland @@ -14,5 +15,6 @@ Variants { required property ShellScreen modelData Bar {} + PowerMenu {} } } diff --git a/modules/Shortcuts.qml b/modules/Shortcuts.qml index d965bec..b0dcb10 100644 --- a/modules/Shortcuts.qml +++ b/modules/Shortcuts.qml @@ -1,3 +1,4 @@ +import qs.services import qs.widgets import Quickshell @@ -11,4 +12,10 @@ Scope { console.log("Launcher shortcut pressed"); } } + + LuxShortcut { + name: 'power-menu' + description: 'Open the Power Menu' + onPressed: Visibility.powermenu = !Visibility.powermenu + } } diff --git a/modules/powermenu/PowerMenu.qml b/modules/powermenu/PowerMenu.qml new file mode 100644 index 0000000..ab131e3 --- /dev/null +++ b/modules/powermenu/PowerMenu.qml @@ -0,0 +1,128 @@ +pragma ComponentBehavior: Bound + +import qs.config +import qs.services +import qs.widgets +import Quickshell.Hyprland +import Quickshell.Io +import Quickshell.Wayland +import Quickshell.Widgets +import QtQuick +import QtQuick.Layouts + +StyledWindow { + id: root + name: "powermenu" + + visible: Visibility.powermenu + implicitWidth: rect.width + implicitHeight: rect.height + + WlrLayershell.layer: WlrLayer.Top + WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None + + Process { + id: process + } + + WrapperRectangle { + id: rect + + color: Theme.palette.base300 + margin: 14 + radius: 8 + + HyprlandFocusGrab { + active: Visibility.powermenu + windows: [root] + onCleared: { + Visibility.powermenu = false; + } + } + + StyledListView { + id: list + + Layout.fillWidth: true + + focus: Visibility.powermenu + Keys.onEscapePressed: event => { + event.accepted = true; + Visibility.powermenu = false; + } + Keys.onReturnPressed: event => { + event.accepted = true; + process.startDetached(); + } + Keys.onSpacePressed: event => { + event.accepted = true; + process.startDetached(); + } + Keys.onUpPressed: event => { + event.accepted = true; + list.decrementCurrentIndex(); + } + Keys.onDownPressed: event => { + event.accepted = true; + list.incrementCurrentIndex(); + } + + model: [ + { + text: "󰍃 Logout", + command: "hyprctl dispatch exit" + }, + { + text: "󰜉 Reboot", + command: "systemctl reboot" + }, + { + text: " Shutdown", + command: "systemctl poweroff" + } + ] + + spacing: 8 + + implicitWidth: 220 + implicitHeight: 185 + + highlightMoveDuration: 1000 + highlightResizeDuration: 0 + highlight: Rectangle { + radius: 8 + color: Theme.palette.primary + } + + onCurrentItemChanged: { + process.command = ["sh", "-c", list.currentItem.modelData.command]; + } + + delegate: StyledText { + id: button + required property var modelData + required property int index + + anchors.left: parent.left + anchors.right: parent.right + + MouseArea { + hoverEnabled: true + anchors.fill: button + onEntered: { + list.currentIndex = button.index; + } + onClicked: { + process.startDetached(); + } + } + + padding: 16 + color: list.currentIndex == index ? Theme.palette.primarycontent : Theme.palette.basecontent + text: modelData.text + font.pixelSize: 18 + font.bold: true + } + } + } +} diff --git a/services/Visibility.qml b/services/Visibility.qml index 3015f7a..1e93a77 100644 --- a/services/Visibility.qml +++ b/services/Visibility.qml @@ -4,6 +4,7 @@ import qs.widgets import Quickshell Singleton { + property bool powermenu property StyledPopupWindow activePopup function togglePopup(popup: StyledPopupWindow) { diff --git a/widgets/StyledText.qml b/widgets/StyledText.qml index a11a4ea..eca51b9 100644 --- a/widgets/StyledText.qml +++ b/widgets/StyledText.qml @@ -2,6 +2,12 @@ import qs.config import QtQuick Text { - color: Theme.palette.basecontent font.family: Theme.fontFamily + color: Theme.palette.basecontent + Behavior on color { + ColorAnimation { + duration: 200 + easing.type: Easing.InOutQuad + } + } }