Configurable screen blank (default 5 min), instant lock/lid blank, instant call/SMS wake

- Config -> Screen blank submenu (Off / 30 s / 1 / 5 / 10 / 30 min) backed by
  ~/.config/sxmo/idle_blank_timeout and the new bananarchy-idle-timeout.sh
  get|label|set. Default changed from 60 s to 300 s. dwm reads the file live
  and reloads it on SIGUSR1, so a menu change takes effect without a restart;
  sxmo.noidle and SXMO_UNLOCK_IDLE_TIME still override/disable it.
- Power -> Lock now uses @plugin:locker:screenoff (like Lock (Screen off)), and
  lock_phone_screenoff() resets dwm's idle state, so closing the slider/lid or
  locking blanks the panel immediately instead of waiting for the timeout.
- New bananarchy-screen-wake.sh restores the panel via sxmo_wm.sh display on,
  records /tmp/bananarchy_last_wake and signals dwm (SIGUSR1) to reset
  idle_blanked / last_input_ms. Called from sxmo_hook_ring.sh (incoming call)
  and sxmo_hook_notification.sh (SMS / notifications). dwm also self-heals if
  an external hook turns the panel on without a signal.

Verified live on the connected phone (after deploying the rebuilt dwm/dmenu
and restarting dwm with a rollback backup): idle_locker job is gone, default
reads 300 / 5m, setting 10 s blanks the panel (br 14->0, bl 0->4, DPMS On->Off)
after ~14 s of no input, and bananarchy-screen-wake.sh restores it immediately.
Lock state and 5-minute default were restored afterwards. All scripts pass sh -n.

Rebuilt dwm/dmenu and images/bananarchy-nokia-argon.img with --mkinitfs;
boot.img still contains the known-good zImage + DTB byte-for-byte.
check-rebuild.sh passes and artifact drift is 0.

Docs: MANUAL.md, CHANGELOG.md, AGENTS.md, BATTERY-OPTIMIZATION-ANALYSIS.md (13).
This commit is contained in:
Bantam committed 2026-11-07 18:16:26 +02:00
1 parent 22d629f59b
commit da68bb8c60
14 files changed
+226 -12

No files matched your search

+58 -1
View File
@@ -2428,6 +2428,42 @@ scan_zoneinfo_recursive(const char *base_dir, const char *rel_dir,
closedir(d);
}
/* U1: Config-menu idle-blank timeout helpers. */
static int
read_idle_blank_secs(void)
{
const char *home = getenv("HOME");
char path[256], buf[32];
if (!home || !home[0])
home = "/home/user";
snprintf(path, sizeof(path), "%s/.config/sxmo/idle_blank_timeout", home);
if (!read_first_line(path, buf, sizeof(buf)))
return 300;
char *end = NULL;
long v = strtol(buf, &end, 10);
if (end == buf || v < 0 || v > 86400)
return 300;
return (int)v;
}
static const char *
idle_blank_label(int secs)
{
static char out[32];
if (secs <= 0)
return "Off";
if (secs < 60) {
snprintf(out, sizeof(out), "%d s", secs);
return out;
}
if (secs % 60 == 0) {
snprintf(out, sizeof(out), "%d min", secs / 60);
return out;
}
snprintf(out, sizeof(out), "%d min %d s", secs / 60, secs % 60);
return out;
}
static void
populate_timezone_menu(void)
{
@@ -2890,6 +2926,10 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Change Timezone", ICON_CLK);
add_menu_item(label, "@menu:timezone", 1);
snprintf(label, sizeof(label), "%s Screen blank: %s", ICON_CLK,
idle_blank_label(read_idle_blank_secs()));
add_menu_item(label, "@menu:idle_blank", 1);
if (!duress) {
int ext_log_on = (access("/tmp/bananarchy_ext_logging", F_OK) == 0 ||
access("/etc/bananarchy/ext_logging", F_OK) == 0);
@@ -2910,11 +2950,28 @@ open_builtin_menu(const char *menu_name, int keep_idx)
add_menu_item(label, "@menu:sys", 1);
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
add_menu_item(label, "@close", 0);
} else if (strcmp(menu_name, "idle_blank") == 0) {
reset_session_defaults(1, "Screen blank");
int cur = read_idle_blank_secs();
static const struct { int secs; const char *name; } opts[] = {
{ 0, "Off" }, { 30, "30 seconds" }, { 60, "1 minute" },
{ 300, "5 minutes" }, { 600, "10 minutes" }, { 1800, "30 minutes" }
};
for (size_t i = 0; i < sizeof(opts) / sizeof(opts[0]); i++) {
snprintf(label, sizeof(label), "%s %s",
opts[i].secs == cur ? ICON_TON : ICON_TOF, opts[i].name);
snprintf(cmd, sizeof(cmd), "bananarchy-idle-timeout.sh set %d", opts[i].secs);
add_menu_item(label, cmd, 1);
}
snprintf(label, sizeof(label), "%s Back to Config", ICON_CFG);
add_menu_item(label, "@menu:config", 1);
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
add_menu_item(label, "@close", 0);
} else if (strcmp(menu_name, "power") == 0) {
reset_session_defaults(1, "Power");
append_active_call_entries();
snprintf(label, sizeof(label), "%s Lock", ICON_LCK);
add_menu_item(label, "@plugin:locker", 0);
add_menu_item(label, "@plugin:locker:screenoff", 0);
snprintf(label, sizeof(label), "%s Lock (Screen off)", ICON_LCK);
add_menu_item(label, "@plugin:locker:screenoff", 0);
snprintf(label, sizeof(label), "%s Logout", ICON_OUT);
+58 -9
View File
@@ -340,10 +340,11 @@ static long long last_wake_ms = 0;
* with evdev input because dwm consumes key events before X sees them,
* which made the screen turn back off immediately after a wake. */
static long long last_input_ms = 0;
static int idle_blank_secs = 60;
static int idle_blank_secs = 300;
static int idle_blank_enabled = 1;
static int idle_blanked = 0;
static int idle_cfg_loaded = 0;
static volatile sig_atomic_t wake_requested = 0;
static int star_down = 0;
static int pound_down = 0;
static long long last_screenshot_ms = 0;
@@ -2465,6 +2466,8 @@ lock_phone_screenoff(void)
int lfd, cfd;
lid_close_pending = 0;
lid_close_deadline_ms = 0;
idle_blanked = 0;
last_input_ms = dwm_now_ms();
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
@@ -3126,6 +3129,42 @@ restack(Monitor *m)
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
/* U1: read the Config-menu timeout live. 0 / sxmo.noidle disables it. */
static void
read_idle_blank_config(void)
{
const char *env = getenv("SXMO_UNLOCK_IDLE_TIME");
const char *home = getenv("HOME");
char path[256], buf[32] = "";
int secs = 300;
if (!home || !home[0])
home = "/home/user";
snprintf(path, sizeof(path), "%s/.cache/sxmo/sxmo.noidle", home);
idle_blank_enabled = (access(path, F_OK) != 0);
snprintf(path, sizeof(path), "%s/.config/sxmo/idle_blank_timeout", home);
read_sysfs_str(path, buf, sizeof(buf));
if (buf[0] != '\0') {
char *end = NULL;
long v = strtol(buf, &end, 10);
if (end != buf && v >= 0 && v <= 86400) {
secs = (int)v;
if (v == 0)
idle_blank_enabled = 0;
}
} else if (env && atoi(env) > 0) {
secs = atoi(env);
}
idle_blank_secs = secs;
}
static void
idle_wake_signal(int sig)
{
(void)sig;
wake_requested = 1;
}
void
run(void)
{
@@ -3137,19 +3176,29 @@ run(void)
/* main event loop */
XSync(dpy, False);
if (!idle_cfg_loaded) {
const char *env = getenv("SXMO_UNLOCK_IDLE_TIME");
char noidle[256];
struct sigaction sa;
idle_cfg_loaded = 1;
if (env && atoi(env) > 0)
idle_blank_secs = atoi(env);
snprintf(noidle, sizeof(noidle), "%s/.cache/sxmo/sxmo.noidle",
getenv("HOME") ? getenv("HOME") : "/home/user");
if (access(noidle, F_OK) == 0)
idle_blank_enabled = 0;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = idle_wake_signal;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGUSR1, &sa, NULL);
read_idle_blank_config();
last_input_ms = dwm_now_ms();
}
xfd = ConnectionNumber(dpy);
while (running) {
if (wake_requested) {
wake_requested = 0;
read_idle_blank_config();
last_input_ms = dwm_now_ms();
idle_blanked = 0;
}
if (idle_blanked && !is_screen_off()) {
/* A call/SMS hook turned the panel back on externally. */
idle_blanked = 0;
last_input_ms = dwm_now_ms();
}
while (XPending(dpy)) {
if (XNextEvent(dpy, &ev))
return;