fix(sxmo): re-enable automatic screen-off on idle to stop backlight battery drain

The previous commit disabled sxmo_idle.sh and the idle_locker in the
unlock/lock hooks, leaving the display backlight pinned at maximum
brightness forever (Xorg runs with -s 0 -dpms and /sys/power/state is
empty, so the panel never blanks). On a phone with no suspend this is by
far the dominant battery drain.

Restore sxmo_idle.sh and start idle_locker from the unlock and lock hooks
so the screen blanks after SXMO_UNLOCK_IDLE_TIME (default 30s) / once
locked after SXMO_LOCK_IDLE_TIME (default 8s). Locking itself stays
explicit-only, matching the documented design; only the display blanks.

Verified live on the device: after the idle timeout the state transitions
to screenoff and /sys/class/backlight/backlight/brightness drops to 0.
This commit is contained in:
Luxferre
2026-10-23 08:45:42 +03:00
parent 5eb8be223d
commit 3f37e4efa1
4 changed files with 94 additions and 7 deletions
+76 -2
View File
@@ -1,4 +1,78 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Automatic idle locking and screen blanking are disabled on Bananarchy.
exit 0
# Copyright 2022 Sxmo Contributors
_swayidletoidles() {
while [ $# -gt 0 ]; do
case "$1" in
timeout)
printf "%s|%s" "$2" "$3"
shift 3
case "$1" in
resume)
printf "|%s" "$2"
shift 2
;;
esac
printf "\n"
;;
*)
shift
;;
esac
done
}
xorgidle() {
if ! command -v xprintidle >/dev/null 2>&1; then
while : ; do
sleep 3600
done
fi
idles="$(_swayidletoidles "$@")"
resumes=""
tick=0
new_idle="$(xprintidle 2>/dev/null || printf '0')"
[ -n "$new_idle" ] || new_idle=0
last_idle="$new_idle"
finish() {
sh -c "$resumes"
resumes=""
exit
}
trap 'finish' TERM INT EXIT
while : ; do
last_idle="$new_idle"
new_idle="$(xprintidle 2>/dev/null || printf '0')"
[ -n "$new_idle" ] || new_idle=0
if [ "$last_idle" -gt "$new_idle" ] 2>/dev/null; then
sh -c "$resumes"
tick=0
resumes=""
fi
if printf "%b\n" "$idles" | grep -q "^$tick|"; then
printf "%b\n" "$idles" | \
grep "^$tick|" | \
cut -d'|' -f2 | \
xargs -I{} -0 sh -c "{}"
resumes="$(printf "%b\n" "$idles" | grep "^$tick|" | cut -d'|' -f3);$resumes"
fi
sleep 1
tick=$((tick + 1))
done
}
case "$SXMO_WM" in
dwm|i3)
xorgidle "$@"
;;
sway|river)
exec swayidle "$@"
;;
esac