diff --git a/MANUAL.md b/MANUAL.md index 019df4c..8221188 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -118,7 +118,7 @@ sudo dd if=./images/bananarchy-nokia-argon.img of=/dev/sdX bs=4M status=progress | **Slider close / open** | `SW_LID` (`lid:on` / `lid:off`) | **Close**: close open menu, turn off keypad backlight, and lock/turn screen off; **Open**: restore keypad backlight, unlock, and turn screen on | > **Explicit locking & waking**: -> X11 screensaver/DPMS blanking and automatic idle locking are disabled so the phone only locks when explicitly requested (`Power -> Lock / Lock (Screen off)`, `XDrawer -> Lock`, `2× End / Power`, or closing the physical slider). When locked, you can wake and unlock the phone in a single action by either: +> X11 screensaver/DPMS blanking is disabled (the display is blanked explicitly by Sxmo, not by the X server), and automatic idle *locking* is disabled so the phone only locks when explicitly requested (`Power -> Lock / Lock (Screen off)`, `XDrawer -> Lock`, `2× End / Power`, or closing the physical slider). To save battery, the display still blanks automatically after a period of inactivity (`SXMO_UNLOCK_IDLE_TIME`, default 30s; `SXMO_LOCK_IDLE_TIME`, default 8s once locked) without locking. When the screen is off, you can wake and unlock the phone in a single action by either: > - **Opening the slider** (`SW_LID` off), or > - Pressing **End / Power (red)**, **Left softkey**, **Right softkey**, or **Call (green)** once. diff --git a/overlay/rootfs/usr/bin/sxmo_idle.sh b/overlay/rootfs/usr/bin/sxmo_idle.sh index 927d6b3..b55d71a 100755 --- a/overlay/rootfs/usr/bin/sxmo_idle.sh +++ b/overlay/rootfs/usr/bin/sxmo_idle.sh @@ -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 diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh index 5721286..e128932 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_lock.sh @@ -32,7 +32,14 @@ if [ -z "$SXMO_DISABLE_LEDS" ]; then fi sxmo_jobs.sh stop periodic_wakelock_check -# Automatic idle transitions are disabled; only explicit locking is used -sxmo_jobs.sh stop idle_locker 2>/dev/null || true +# Re-enable automatic screen-off on idle to save battery. The phone only +# locks on explicit request; once locked we blank the screen after a short +# idle period. +if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then + sxmo_jobs.sh stop idle_locker +else + sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \ + timeout "${SXMO_LOCK_IDLE_TIME:-8}" 'sh -c "sxmo_state.sh set screenoff"' +fi wait diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh index 2508548..42860e2 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh @@ -26,7 +26,13 @@ if [ -z "$SXMO_DISABLE_LEDS" ]; then fi sxmo_jobs.sh stop periodic_wakelock_check -# Automatic idle locking is disabled; only explicit locking is used -sxmo_jobs.sh stop idle_locker 2>/dev/null || true +# Re-enable automatic screen-off on idle to save battery. Locking stays +# explicit (the user locks only on request); we only blank the display. +if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then + sxmo_jobs.sh stop idle_locker +else + sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \ + timeout "${SXMO_UNLOCK_IDLE_TIME:-30}" 'sh -c "sxmo_state.sh set screenoff"' +fi wait