rofi-powermenu (1155B)
1 #!/usr/bin/env bash 2 3 power_args=$(printf '%b' ' Lock\nLogout\n Restart\n Suspend\n Hibernate\n Shutdown' | 4 rofi -dmenu -p "" -i -theme-str 'window {width: 16%; padding: 2px; height: 30%;}') 5 6 _have_cmd() { 7 command -v "$1" &>/dev/null 8 } 9 10 case "$power_args" in 11 *Lock) 12 if [[ -n "$NIRI_SOCKET" ]]; then 13 _have_cmd swaylock && swaylock --daemonize && niri msg action power-off-monitors 14 elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then 15 hyprlock 16 fi 17 ;; 18 *Logout) 19 if [[ -n "$NIRI_SOCKET" ]]; then 20 niri msg action quit 21 elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then 22 hyprctl dispatch exit 23 fi 24 ;; 25 *Restart) 26 systemctl reboot 27 ;; 28 *Suspend) 29 _have_cmd swaylock && swaylock --daemonize && sleep 0.5 && niri msg action power-off-monitors && systemctl suspend 30 ;; 31 *Hibernate) 32 systemctl hibernate 33 ;; 34 *Shutdown) 35 if [[ -n "$NIRI_SOCKET" ]]; then 36 systemctl poweroff 37 elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then 38 hyprctl dispatch killactive && sleep 0.1 && hyprctl dispatch killactive && sleep 0.1 && systemctl poweroff 39 # hyprctl clients -j | jq -r '.[].pid' | xargs -r kill -9; systemctl poweroff 40 fi 41 ;; 42 esac