summaryrefslogtreecommitdiff
path: root/.local/bin/desktop/i3exit
blob: 5aea730f824d3ab4696fb00da3d7b283ae641616 (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
#!/bin/sh

# with openrc use loginctl
[ "$(cat /proc/1/comm)" = "systemd" ] && logind=systemctl || logind=loginctl

command="$1"
system_control() {
	if [ "$(loginctl show-session --property=NCurrentSessions --value)" -gt 2 ]; then
		notify-send --replace-id=4252 \
			"i3exit" "Multiple users are logged in\nCant't $command"
		exit
	fi
	eval "$@"
}

lockWall="$HOME/.local/share/lockWall"
lock_desktop() {
	[ -f "$lockWall" ] &&
		i3lock --tiling --image="$lockWall" ||
		i3lock --color=001177
	pkill ssh-agent
}

case "$command" in
    off)          xset dpms force off ;;
    lock)         lock_desktop; xset dpms force off ;;
    logout)       switch-session; i3-msg exit ;;
    switch_user)  dm-tool switch-to-greeter ;;
    suspend)      $logind suspend ;;
    sleep)        lock_desktop; $logind suspend ;;
    hibernate)    system_control lock_desktop && $logind hibernate ;;
    reboot)       system_control $logind reboot ;;
    shutdown)     system_control $logind poweroff ;;
    *)
        echo "== ! i3exit: missing or invalid argument ! =="
        echo "Try again with: lock | logout | switch_user | suspend | hibernate | reboot | shutdown"
        exit 2
esac

exit 0