summaryrefslogtreecommitdiff
path: root/scripts/rofi-powermenu
blob: d7c292729a79994f94f97ddf28ff96b052fa64ea (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
#!/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
		_have_cmd swaylock && swaylock --daemonize && niri msg action power-off-monitors
	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)
	_have_cmd swaylock && swaylock --daemonize && sleep 0.5 && niri msg action power-off-monitors && 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