summaryrefslogtreecommitdiff
path: root/scripts/rofi-powermenu
blob: 67f717034530af91ebb6ec63a8fb7593852108e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash

power_args=$(printf '%b' ' Lock\nLogout\n Restart\n󰒲 Suspend\n󰋊 Hibernate\n󰚦 Shutdown' |
  rofi -dmenu -p "󰐥" -i -theme-str 'window {width: 12em; padding: 2px; height: 16em;}')

_have_cmd() {
  command -v "$1" &>/dev/null
}

case "$power_args" in
*Lock)
  if [[ -n "$NIRI_SOCKET" ]]; then
    niri msg action power-off-monitors
    _have_cmd swaylock && swaylock
  elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then
    hyprlock
  fi
  ;;
*Logout)
  if [[ -n "$NIRI_SOCKET" ]]; then
    niri msg action quit
  elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then
    hyprctl dispatch exit
  fi
  ;;
*Restart)
  systemctl reboot
  ;;
*Suspend)
  systemctl suspend
  ;;
*Hibernate)
  systemctl hibernate
  ;;
*Shutdown)
  if [[ -n "$NIRI_SOCKET" ]]; then
    systemctl poweroff
  elif [[ "$XDG_CURRENT_DESKTOP" == "Hyprland" ]]; then
    hyprctl dispatch killactive && sleep 0.1 && hyprctl dispatch killactive && sleep 0.1 && systemctl poweroff
    # hyprctl clients -j | jq -r '.[].pid' | xargs -r kill -9; systemctl poweroff
  fi
  ;;
esac