summaryrefslogtreecommitdiffstats
path: root/roles/hyprland/files/scripts
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2026-02-23 18:43:08 +0100
committerAhmed Abdelhalim <[email protected]>2026-02-23 18:43:08 +0100
commitd0ec647b2cdc8263e24ea3af588aa1c0add56e29 (patch)
tree3df9673c78f0541e2b889a8129b5ed2b63fb7081 /roles/hyprland/files/scripts
parent5c0639bfe6e06ae3ad58a1aa29d9070eb9df502e (diff)
Refactor power.sh to be the entry point for power control
Diffstat (limited to 'roles/hyprland/files/scripts')
-rwxr-xr-xroles/hyprland/files/scripts/power.sh87
1 files changed, 64 insertions, 23 deletions
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