~charles/dotfiles

ref: 717bba4297a0fdb2e43e0a2ee96a48778ef65915 dotfiles/overlay/bin/apply-dpms -rwxr-xr-x 1.5 KiB View raw
717bba42Charles Daniels explicitly blank screen when locking 1 year, 1 month ago
                                                                                
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
67
68
69
70
#!/usr/bin/env bash

set -e
set -u

CFG_FILE="$HOME/.config/dpmsconf"
DEFAULT=20

# Configure DPMS settings to one of several profiles

# if no profile specified, then read CFG_FILE, which should be TSV with
# either AC or BAT as column 0, and a profile as column 1

# A profile may be either the string 'never', which means to never sleep the
# monitor, or a number of minutes before blanking

# if "printcfg" is used as the profile, then CFG_FILE is printed to standard
# out and the DPMS settings are unchanged

if [ $# -eq 0 ] ; then
	if [ -e "$CFG_FILE" ] ; then
		if acpi -a | grep "on-line" > /dev/null 2>&1 ; then
			# on AC
			config="$(cat "$CFG_FILE" | grep AC | cut -f2)"
		else
			# on battery
			config="$(cat "$CFG_FILE" | grep BAT | cut -f2)"
		fi
	else
		echo "no profile specified, and no $CFG_FILE" 1>&2
		exit 1
	fi
else
	config="$1"
fi

# not sure this does much on modern systems, but in theory it turns of the
# bell, whatever that is.
xset b off

current_config=$(expr $(xset q dpms | grep Standby | cut -d: -f2 | cut -d' ' -f2) / 60)

case "$config" in
	never)
		set +e
		killall xautolock
		set -e
		xset dpms 0 0 0
		;;
	[0-9]*)
		if [ $config -eq $current_config ] ; then
			echo "profile is unchanged."
			exit 0
		fi
		set +e
		killall xautolock
		set -e
		xautolock -time $config -locker "xset dpms force off && xtrlock -b" &
		disown
		timeout=$(expr $config '*' 60)
		xset dpms $timeout $timeout $timeout
		;;
	printcfg)
		echo "$CFG_FILE"
		;;
	*)
		echo "Invalid DPMS configuration '$config'" 1>&2
		exit 1
		;;
esac