From 3f2cfa8a0d20c036a99cb8223bb36148b7cac186 Mon Sep 17 00:00:00 2001 From: Nikita Borodikhin Date: Sat, 6 Jun 2026 23:01:10 -0500 Subject: [PATCH] feat: add /tmp/stay_awake and /tmp/stay_alive suspend-inhibit lock files Two well-known marker files let external processes (Pak scripts, debug sessions, long-running tools) defer the auto power-save transitions: /tmp/stay_awake - blocks autosleep (no screen-off, no deep sleep) /tmp/stay_alive - blocks deep sleep only (screen may still blank) stay_awake plugs into PWR_preventAutosleep so the autosleep timer is pinned while the file exists; manual SLEEP-button and HW-requested sleep paths are unaffected. Both files are also checked in PWR_waitForWake's deferral loop next to the existing is_charging branch, so deep sleep is skipped while either lock is present (with the same 60s re-check cadence). This also catches the race where stay_awake appears after the device already entered light sleep. /tmp is tmpfs on the device, so the locks evaporate on reboot. Addresses https://github.com/LoveRetro/NextUI/issues/755. --- workspace/all/common/api.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 25b4998e9..9b1f57b72 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -3935,6 +3935,12 @@ void PWR_powerOff(int reboot) } } +// Suspend-inhibit lock files (see SystemDoc.md §5). +// /tmp/stay_awake → block autosleep (no screen-off, no deep sleep) +// /tmp/stay_alive → allow screen-off, block deep sleep +static int hasStayAwake(void) { return access("/tmp/stay_awake", F_OK) == 0; } +static int hasStayAlive(void) { return access("/tmp/stay_alive", F_OK) == 0; } + static void PWR_enterSleep(void) { SND_pauseAudio(true); @@ -4014,6 +4020,11 @@ static void PWR_waitForWake(void) sleep_ticks += 60000; // check again in a minute continue; } + if (hasStayAwake() || hasStayAlive()) + { + sleep_ticks += 60000; // external lock-file override + continue; + } if (PLAT_supportsDeepSleep()) { int ret = PWR_deepSleep(); @@ -4090,7 +4101,7 @@ void PWR_enableAutosleep(void) } int PWR_preventAutosleep(void) { - return SDL_AtomicGet(&pwr.is_charging) || !pwr.can_autosleep || GetHDMI(); + return SDL_AtomicGet(&pwr.is_charging) || !pwr.can_autosleep || GetHDMI() || hasStayAwake(); } // updated by PWR_updateBatteryStatus()