summaryrefslogtreecommitdiffstats
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
parent5c0639bfe6e06ae3ad58a1aa29d9070eb9df502e (diff)
Refactor power.sh to be the entry point for power control
-rwxr-xr-xroles/hyprland/files/scripts/power.sh87
-rw-r--r--roles/hyprland/templates/hypridle.conf.j26
-rw-r--r--roles/hyprland/templates/hyprlock.conf.j26
3 files changed, 70 insertions, 29 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
diff --git a/roles/hyprland/templates/hypridle.conf.j2 b/roles/hyprland/templates/hypridle.conf.j2
index 2c060988..e99b93be 100644
--- a/roles/hyprland/templates/hypridle.conf.j2
+++ b/roles/hyprland/templates/hypridle.conf.j2
@@ -2,14 +2,14 @@
general {
lock_cmd = pidof hyprlock || hyprlock
- before_sleep_cmd = loginctl lock-session # lock before suspend
+ before_sleep_cmd = /etc/hypr/scripts/power.sh --lock
after_sleep_cmd = hyprctl dispatch dpms on
}
# Lock the screen (after 5 minutes)
listener {
timeout = 300
- on-timeout = loginctl lock-session
+ on-timeout = /etc/hypr/scripts/power.sh --lock
}
# Turn off screen (after 10 minutes)
@@ -22,5 +22,5 @@ listener {
# Suspend the system (after 15 minutes)
listener {
timeout = 900
- on-timeout = systemctl suspend
+ on-timeout = /etc/hypr/scripts/power.sh --hibernate
}
diff --git a/roles/hyprland/templates/hyprlock.conf.j2 b/roles/hyprland/templates/hyprlock.conf.j2
index 22fb5f20..0a2e2d0f 100644
--- a/roles/hyprland/templates/hyprlock.conf.j2
+++ b/roles/hyprland/templates/hyprlock.conf.j2
@@ -112,7 +112,7 @@ label {
font_family = $font
color = $font_color
- onclick = hyprctl dispatch exec hyprshutdown --no-fork -t "Restarting..." --post-cmd "systemctl reboot"
+ onclick = /etc/hypr/scripts/power.sh --reboot
halign = center
valign = center
@@ -127,7 +127,7 @@ label {
font_family = $font
color = $font_color
- onclick = hyprctl dispatch exec hyprshutdown --no-fork -t "Shutting down..." --post-cmd "systemctl poweroff"
+ onclick = /etc/hypr/scripts/power.sh --shutdown
halign = center
valign = center
@@ -142,7 +142,7 @@ label {
font_family = $font
color = $font_color
- onclick = loginctl lock-session && systemctl suspend
+ onclick = /etc/hypr/scripts/power.sh --hibernate
halign = center
valign = center