Trigger the screenlock daemon on idle screen blanking

This commit is contained in:
Luxferre committed 2026-11-10 12:51:15 +02:00
1 parent 77d95c715c
commit 5d859d7b11
11 files changed
+382 -12

No files matched your search

@@ -1,13 +1,17 @@
#!/bin/sh
# Blank/restore the display without engaging the passcode locker (U1).
# sxmo_wm.sh display off/on already handles brightness, bl_power, DPMS,
# the CPU governor and the keyboard backlight.
# Blank/restore the display and arm the screenlock daemon (U1).
# sxmo_wm.sh display off/on handles brightness, bl_power, DPMS, the CPU
# governor and the keyboard backlight. bananarchy-idle-lock.sh then arms the
# trusted screenoff transition that starts xlocker screenoff (LOCK_BLANK on
# locker.so); without it the resident locker daemon never sees a blank event.
#
# A wake-grace guard makes this safe even on the legacy sxmo_idle.sh path:
# xprintidle can report a stale large idle value right after a wake, which
# used to fire the blank command again immediately.
WAKE_TS=/tmp/bananarchy_last_wake
WAKE_TS="${BANANARCHY_WAKE_TS:-/tmp/bananarchy_last_wake}"
GRACE="${BANANARCHY_IDLE_BLANK_GRACE:-10}"
LOCK_HELPER="${BANANARCHY_IDLE_LOCK_HELPER:-/usr/bin/bananarchy-idle-lock.sh}"
WM_CMD="${BANANARCHY_WM_CMD:-/usr/bin/sxmo_wm.sh}"
case "${1:-}" in
off)
@@ -18,14 +22,22 @@ case "${1:-}" in
if [ $((now - last)) -lt "$GRACE" ]; then
exit 0
fi
exec /usr/bin/sxmo_wm.sh display off
"$WM_CMD" display off >/dev/null 2>&1 || true
"$LOCK_HELPER" arm >/dev/null 2>&1 || true
exit 0
;;
on)
"$LOCK_HELPER" cancel >/dev/null 2>&1 || true
date +%s > "$WAKE_TS" 2>/dev/null || true
exec /usr/bin/sxmo_wm.sh display on
exec "$WM_CMD" display on
;;
cancel)
# Called by the wake paths before they power the panel back on.
"$LOCK_HELPER" cancel >/dev/null 2>&1 || true
exit 0
;;
*)
printf 'Usage: %s [off|on]\n' "${0##*/}" >&2
printf 'Usage: %s [off|on|cancel]\n' "${0##*/}" >&2
exit 1
;;
esac
+119
View File
@@ -0,0 +1,119 @@
#!/bin/sh
# Arm the screenlock daemon when dwm blanks the panel on idle.
#
# dwm's native idle blanking (bananarchy-idle-blank.sh off) only powers the
# panel down: it does not call sxmo_state.sh / sxmo_hook_screenoff.sh and no
# idle_locker job is started by the session any more. As a result locker.so
# never receives LOCK_BLANK on a blank event and the phone stays unlocked.
# This helper arms a trusted "sxmo_state.sh set screenoff" (which starts
# xlocker screenoff -> LOCK_BLANK) after a short dark-panel delay. Waking the
# panel before the deadline cancels the pending lock, so a quick key press
# still returns to the unlocked desktop on every target.
#
# Config: ~/.config/sxmo/idle_lock_delay (seconds, "off" disables, 0 locks
# immediately when the panel blanks). Default 30 s.
set -u
CFGDIR="${XDG_CONFIG_HOME:-${HOME:-/home/user}/.config}/sxmo"
CFG="$CFGDIR/idle_lock_delay"
PIDFILE="${BANANARCHY_IDLE_LOCK_PIDFILE:-/tmp/bananarchy_idle_lock.pid}"
DEFAULT=30
MAX_DELAY=3600
LOCK_FLAG="${BANANARCHY_LOCK_FLAG:-/tmp/bananarchy_screen_locked}"
STATE_CMD="${BANANARCHY_STATE_CMD:-/usr/bin/sxmo_state.sh}"
WM_CMD="${BANANARCHY_WM_CMD:-/usr/bin/sxmo_wm.sh}"
get_delay() {
v="$DEFAULT"
if [ -r "$CFG" ]; then
read -r v < "$CFG" 2>/dev/null || v="$DEFAULT"
fi
case "$v" in
off|OFF|no|NO|none|NONE) printf 'off\n'; return 0 ;;
esac
case "$v" in ''|*[!0-9]*) v="$DEFAULT" ;; esac
[ "$v" -le "$MAX_DELAY" ] || v="$MAX_DELAY"
printf '%s\n' "$v"
}
label() {
v="$(get_delay)"
case "$v" in
off) printf 'Off\n' ;;
0) printf 'Immediately\n' ;;
*) printf '%ss\n' "$v" ;;
esac
}
panel_is_dark() {
st="$("$WM_CMD" display 2>/dev/null || true)"
[ "$st" = "off" ] && return 0
if [ -r /sys/class/backlight/backlight/brightness ]; then
_bl=1
read -r _bl < /sys/class/backlight/backlight/brightness 2>/dev/null || _bl=1
[ "${_bl:-1}" -le 0 ] 2>/dev/null && return 0
fi
return 1
}
cancel() {
[ -r "$PIDFILE" ] || return 0
pid=""
read -r pid < "$PIDFILE" 2>/dev/null || pid=""
case "$pid" in
''|*[!0-9]*) ;;
*) kill "$pid" 2>/dev/null || true ;;
esac
rm -f "$PIDFILE" 2>/dev/null || true
return 0
}
lock_panel() {
[ -f "$LOCK_FLAG" ] && return 0
panel_is_dark || return 0
"$STATE_CMD" set screenoff >/dev/null 2>&1 || true
}
arm() {
cancel
d="$(get_delay)"
[ "$d" = "off" ] && return 0
if [ "$d" -eq 0 ]; then
lock_panel
return 0
fi
(
sleep "$d" || exit 0
lock_panel
) >/dev/null 2>&1 &
printf '%s\n' "$!" > "$PIDFILE" 2>/dev/null || true
return 0
}
case "${1:-get}" in
get) get_delay ;;
label) label ;;
set)
v="${2:-}"
case "$v" in
off|OFF|no|NO|none|NONE) v=off ;;
''|*[!0-9]*)
printf 'Usage: %s [get|label|set <seconds|off>|arm|cancel]\n' "${0##*/}" >&2
exit 1
;;
esac
case "$v" in off) ;; *)
[ "$v" -le "$MAX_DELAY" ] || v="$MAX_DELAY"
;; esac
mkdir -p "$CFGDIR" 2>/dev/null || exit 1
printf '%s\n' "$v" > "$CFG" || exit 1
printf '%s\n' "$v"
;;
arm) arm ;;
cancel) cancel ;;
*)
printf 'Usage: %s [get|label|set <seconds|off>|arm|cancel]\n' "${0##*/}" >&2
exit 1
;;
esac
exit 0
@@ -2,7 +2,10 @@
# Wake the screen for an external event (incoming call / SMS / notification)
# and reset dwm's idle-blank timer so it cannot blank again immediately.
export DISPLAY="${DISPLAY:-:0}"
/usr/bin/sxmo_wm.sh display on >/dev/null 2>&1 || true
# Cancel a pending idle-blank lock before the panel is powered on, so a wake
# does not race with the screenoff transition started by the blank handler.
"${BANANARCHY_IDLE_LOCK_HELPER:-/usr/bin/bananarchy-idle-lock.sh}" cancel >/dev/null 2>&1 || true
"${BANANARCHY_WM_CMD:-/usr/bin/sxmo_wm.sh}" display on >/dev/null 2>&1 || true
date +%s > /tmp/bananarchy_last_wake 2>/dev/null || true
p="$(pidof -s dwm 2>/dev/null || true)"
[ -n "$p" ] && kill -USR1 "$p" 2>/dev/null || true
@@ -41,5 +41,8 @@ fi
# evdev handling and turned the screen back off immediately after a wake.
# Create ~/.cache/sxmo/sxmo.noidle to disable it entirely.
sxmo_jobs.sh stop idle_locker 2>/dev/null || true
# The idle-blank path arms a delayed trusted screenoff transition; a real
# unlock must cancel it or locker.so would re-lock the freshly woken panel.
/usr/bin/bananarchy-idle-lock.sh cancel >/dev/null 2>&1 || true
wait