From 3b1eb02159fdb36dfc8982e7ad934d581d165c6d Mon Sep 17 00:00:00 2001 From: nico Date: Mon, 27 Jul 2026 19:15:49 +0200 Subject: [PATCH] Add Quickshell power button with reboot/shutdown/logout dropdown Replaces the removed Waybar custom/power module with a Quickshell-rendered button anchored to the same spot in the bar, opening a proper anchored dropdown (Neustart/Herunterfahren/Abmelden, localized via $LANG) instead of a screen-centered rofi menu. Waybar keeps a blank spacer module reserving the space. Styled to match the rice's blue accent and the bar's pill look. --- hypr/hyprland.conf | 1 + quickshell/default/MenuEntry.qml | 40 ++++++++++ quickshell/default/PowerMenu.qml | 130 +++++++++++++++++++++++++++++++ quickshell/default/shell.qml | 44 +---------- waybar/config.jsonc | 8 +- waybar/style.css | 9 ++- 6 files changed, 189 insertions(+), 43 deletions(-) create mode 100644 quickshell/default/MenuEntry.qml create mode 100644 quickshell/default/PowerMenu.qml diff --git a/hypr/hyprland.conf b/hypr/hyprland.conf index db5b17c..8c46647 100644 --- a/hypr/hyprland.conf +++ b/hypr/hyprland.conf @@ -58,6 +58,7 @@ $mainMod = SUPER # ---------------------------------------------------------- exec-once = waybar +exec-once = quickshell -c default exec-once = dunst exec-once = nm-applet --indicator exec-once = swaybg -i ~/Pictures/wallpapers/wallpaper.png -m fill diff --git a/quickshell/default/MenuEntry.qml b/quickshell/default/MenuEntry.qml new file mode 100644 index 0000000..563d7fb --- /dev/null +++ b/quickshell/default/MenuEntry.qml @@ -0,0 +1,40 @@ +import QtQuick +import QtQuick.Layouts + +Rectangle { + id: root + required property string label + required property string icon + signal triggered() + + Layout.fillWidth: true + implicitHeight: 32 + radius: 8 + color: ma.containsMouse ? "#1793d1" : "transparent" + + Row { + anchors.centerIn: parent + spacing: 8 + + Text { + text: root.icon + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 14 + color: ma.containsMouse ? "#0f111a" : "#7aa2f7" + } + + Text { + text: root.label + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + color: ma.containsMouse ? "#0f111a" : "#c0caf5" + } + } + + MouseArea { + id: ma + anchors.fill: parent + hoverEnabled: true + onClicked: root.triggered() + } +} diff --git a/quickshell/default/PowerMenu.qml b/quickshell/default/PowerMenu.qml new file mode 100644 index 0000000..5017a91 --- /dev/null +++ b/quickshell/default/PowerMenu.qml @@ -0,0 +1,130 @@ +import QtQuick +import QtQuick.Layouts +import Quickshell +import Quickshell.Io +import Quickshell.Wayland +import Quickshell.Hyprland + +Variants { + id: root + model: Quickshell.screens + + readonly property bool isGerman: Qt.locale().name.startsWith("de") + readonly property string logoutLabel: isGerman ? "Abmelden" : "Logout" + readonly property string restartLabel: isGerman ? "Neustart" : "Restart" + readonly property string shutdownLabel: isGerman ? "Herunterfahren" : "Shutdown" + + PanelWindow { + id: panel + required property var modelData + screen: modelData + + anchors { top: true; right: true } + implicitWidth: 40 + implicitHeight: 34 + margins.right: 8 + exclusionMode: ExclusionMode.Ignore + color: "transparent" + WlrLayershell.namespace: "power-button" + + property bool menuOpen: false + + Process { id: logoutProc; command: ["hyprctl", "dispatch", "exit"] } + Process { id: rebootProc; command: ["systemctl", "reboot"] } + Process { id: shutdownProc; command: ["systemctl", "poweroff"] } + + // Matches window#waybar's own backdrop tint so the button blends into the bar + // instead of floating over the wallpaper on its own transparent surface. + Rectangle { + anchors.fill: parent + color: Qt.rgba(0.071, 0.075, 0.106, 0.18) + } + + Rectangle { + anchors.fill: parent + anchors.margins: 4 + radius: 10 + color: btnArea.containsMouse ? "#1793d1" : Qt.rgba(0.102, 0.106, 0.149, 0.85) + + Text { + anchors.centerIn: parent + text: "" + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 15 + color: btnArea.containsMouse ? "#0f111a" : "#1793d1" + } + + MouseArea { + id: btnArea + anchors.fill: parent + hoverEnabled: true + onClicked: panel.menuOpen = !panel.menuOpen + } + } + + LazyLoader { + active: panel.menuOpen + + PanelWindow { + id: menu + screen: panel.modelData + + anchors { top: true; right: true } + margins { top: 34; right: 8 } + + implicitWidth: 170 + implicitHeight: col.implicitHeight + 16 + color: "transparent" + WlrLayershell.namespace: "power-menu" + + HyprlandFocusGrab { + windows: [ menu ] + active: true + onCleared: panel.menuOpen = false + } + + Rectangle { + anchors.fill: parent + radius: 10 + color: "#e61a1b26" + border.width: 1 + border.color: Qt.rgba(0.478, 0.635, 0.969, 0.35) + + ColumnLayout { + id: col + anchors.fill: parent + anchors.margins: 8 + spacing: 4 + + MenuEntry { + label: root.logoutLabel + icon: "" + onTriggered: { + panel.menuOpen = false + logoutProc.startDetached() + } + } + + MenuEntry { + label: root.restartLabel + icon: "" + onTriggered: { + panel.menuOpen = false + rebootProc.startDetached() + } + } + + MenuEntry { + label: root.shutdownLabel + icon: "" + onTriggered: { + panel.menuOpen = false + shutdownProc.startDetached() + } + } + } + } + } + } + } +} diff --git a/quickshell/default/shell.qml b/quickshell/default/shell.qml index bd00ab8..db562f0 100644 --- a/quickshell/default/shell.qml +++ b/quickshell/default/shell.qml @@ -1,44 +1,6 @@ -import Quickshell import QtQuick -import Quickshell.Wayland +import Quickshell -PanelWindow { - color: "transparent" - anchors { - top: true - left: true - right: true - } - implicitHeight: 40 - - Rectangle { - anchors.fill: parent - - // KORREKTUR: Qt.rgba nutzt Werte von 0.0 bis 1.0 statt 0-255 - // 30/255 ≈ 0.11, 46/255 ≈ 0.18, Transparenz 0.85 - color: Qt.rgba(0.11, 0.11, 0.18, 0.25) - - // KORREKTUR: Auch hier das ältere Format für den Rahmen nutzen - border.color: Qt.rgba(1.0, 1.0, 1.0, 0.1) - border.width: 1 - - Text { - id: clockText - anchors.centerIn: parent - color: "#cdd6f4" // Hex-Codes funktionieren weiterhin einwandfrei - font.pixelSize: 15 - font.bold: true - - text: Qt.formatDateTime(new Date(), "hh:mm:ss") - } - - Timer { - interval: 1000 - running: true - repeat: true - onTriggered: { - clockText.text = Qt.formatDateTime(new Date(), "hh:mm:ss") - } - } - } +ShellRoot { + PowerMenu {} } diff --git a/waybar/config.jsonc b/waybar/config.jsonc index c95e207..e481c7b 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -19,7 +19,8 @@ "custom/gpu", "network", "pulseaudio", - "clock" + "clock", + "custom/power-spacer" ], "custom/arch": { "format": "", @@ -104,5 +105,10 @@ "interval": 3, "return-type": "text", "tooltip": true + }, + "custom/power-spacer": { + "format": " ", + "tooltip": false, + "interval": "once" } } \ No newline at end of file diff --git a/waybar/style.css b/waybar/style.css index 724ea66..4daa0a6 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -82,5 +82,12 @@ window#waybar { #clock { color: @bright_white; - margin-right: 8px; +} + +/* Reserved blank space where the Quickshell power button/menu renders on top. */ +#custom-power-spacer { + min-width: 48px; + padding: 0; + margin: 0; + background: transparent; }