aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/xblank-toggle
blob: f013b93762a32abb17af5baec4ef040eafae143d (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.

main()
{
	# Handle opts
	while getopts ":S:h" opt
	do
		case "$opt" in
			S) rundir=$OPTARG ;;
			h) usage && exit 0 ;;
			*)
				printf "Invalid option passed: %s\n" "$OPTARG" >&2
				;;
		esac
	done

	shift $(( OPTIND - 1 ))

	# Set default values
	[ -z "$rundir" ] && rundir="$XDG_RUNTIME_DIR/xblank"

	# Check if xblank is currently paused
	if [ "$(head -n 1 "$rundir/paused")" = "0" ]
	then
		# xblank is currently not paused
		printf "1\n" > "$rundir/paused"
		notify "stock_lock-open" "xblank" "Paused"
	else
		# xblank is already paused
		printf "0\n" > "$rundir/paused"
		notify "stock_lock" "xblank" "Unpaused"
	fi
}

notify()
{
	icon=$1
	shift

	notify-send -i "$icon" -n 26012 -s -t 3 "$@"
}

usage()
{
	cat <<EOF
Usage:
	${0##*/} -h

Nondescript

Options:
	-h  Show this help text and exit.
EOF
}

main "$@"