From d0ec647b2cdc8263e24ea3af588aa1c0add56e29 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Mon, 23 Feb 2026 18:43:08 +0100 Subject: Refactor power.sh to be the entry point for power control --- roles/hyprland/files/scripts/power.sh | 87 ++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 23 deletions(-) (limited to 'roles/hyprland/files/scripts') diff --git a/roles/hyprland/files/scripts/power.sh b/roles/hyprland/files/scripts/power.sh index 60e4ea26..c2f566d6 100755 --- a/roles/hyprland/files/scripts/power.sh +++ b/roles/hyprland/files/scripts/power.sh @@ -1,7 +1,24 @@ #!/bin/bash -# Use the commented styling to get tofi fullscreen theme instead of -# using the hpyrland windowrule workaround to get the dimming effect +shutdown() { + hyprshutdown -t "Shutting down..." --post-cmd "systemctl poweroff" +} + +reboot() { + hyprshutdown -t "Restarting..." --post-cmd "systemctl reboot" +} + +hibernate() { + systemctl suspend +} + +lock_screen() { + loginctl lock-session +} + +interactive() { + # Use the commented styling to get tofi fullscreen theme instead of + # using the hpyrland windowrule workaround to get the dimming effect # --width 100% \ # --height 120% \ # --font-size 20 \ @@ -14,25 +31,49 @@ # --placeholder-text "" \ # --prompt-text "Power:" \ # --background-color "#000B" -ACTION=$(printf ' Shutdown\n󰑙 Reboot\n󰤄 Suspend' | tofi \ - --width 450 \ - --height 300 \ - --font-size 20 \ - --anchor center \ - --prompt-text "Power:" \ - --placeholder-text "" \ - --result-spacing 10 -) - - -case "$ACTION" in - *Shutdown*) - hyprshutdown -t "Shutting down..." --post-cmd "systemctl poweroff" - ;; - *Reboot*) - hyprshutdown -t "Restarting..." --post-cmd "systemctl reboot" - ;; - *Suspend*) - systemctl suspend - ;; + ACTION=$(printf ' Shutdown\n󰑙 Reboot\n󰤄 Suspend\n Lock Session' | tofi \ + --width 450 \ + --height 300 \ + --font-size 20 \ + --anchor center \ + --prompt-text "Power:" \ + --placeholder-text "" \ + --result-spacing 10 + ) + + + case "$ACTION" in + *Shutdown*) + shutdown + ;; + *Reboot*) + reboot + ;; + *Suspend*) + lock_screen + hibernate + ;; + *Lock*) + lock_screen + ;; + esac +} + +case "$1" in + "--shutdown") + shutdown + ;; + "--reboot") + reboot + ;; + "--hibernate") + lock_screen + hibernate + ;; + "--lock") + lock_screen + ;; + *) + interactive + ;; esac -- cgit v1.2.3