summaryrefslogtreecommitdiff
path: root/scripts/rofi-powermenu
blob: 57d3fe8041f4354a06968f34433fe350e70a7af0 (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
#!/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;}')

case "$power_args" in
*Lock)
  if [[ -n "$NIRI_SOCKET" ]]; then
    command -v swaylock &>/dev/null && 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