a3188c16c2d36b1e3262955452bff6c36edc3f48 — Charles Daniels 5 months ago 717bba4
fix edge case where xautolock might not be running

If the DPMS timeout was set to 0, then xautolock might be killed and
never started. apply-dpms now guarantees that xautolock is running even
if the profile is unchanged. It also has more verbose logging.
1 files changed, 25 insertions(+), 1 deletions(-)

M overlay/bin/apply-dpms
M overlay/bin/apply-dpms => overlay/bin/apply-dpms +25 -1
@@ 26,6 26,7 @@
 			# on battery
 			config="$(cat "$CFG_FILE" | grep BAT | cut -f2)"
 		fi
+		echo "selected profile $config from config" 1>&2
 	else
 		echo "no profile specified, and no $CFG_FILE" 1>&2
 		exit 1


@@ 38,25 39,47 @@
 # bell, whatever that is.
 xset b off
 
+set +e
 current_config=$(expr $(xset q dpms | grep Standby | cut -d: -f2 | cut -d' ' -f2) / 60)
+set -e
 
 case "$config" in
 	never)
+		echo "disabling sleep" 1>&2
 		set +e
 		killall xautolock
 		set -e
 		xset dpms 0 0 0
 		;;
 	[0-9]*)
+
+		# if the profile matches the current settings, do nothing
+		# to avoid disturbing any timers
 		if [ $config -eq $current_config ] ; then
-			echo "profile is unchanged."
+			echo "profile is unchanged." 1>&2
+
+			# xautolock should still be running, make sure it has
+			# not been killed
+			if [ $(ps aux | awk '$11 ~ /xautolock/' | wc -l) -le 0 ] ; then
+				echo "xautolock not running, starting it" 1>&2
+				xautolock -time $config -locker "xset dpms force off && xtrlock -b" &
+				disown
+			fi
+
 			exit 0
 		fi
+
+		# settings need to be changed
+		echo "set timeout to $config minutes" 1>&2
+
+		# restart xautolock
 		set +e
 		killall xautolock
 		set -e
 		xautolock -time $config -locker "xset dpms force off && xtrlock -b" &
 		disown
+
+		# apply dpms settings
 		timeout=$(expr $config '*' 60)
 		xset dpms $timeout $timeout $timeout
 		;;


@@ 68,3 91,4 @@
 		exit 1
 		;;
 esac
+echo "applied DPMS settings successfully" 1>&2