From afa3607259caf92d2991df1815e6d8c9d54984d3 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Fri, 30 Oct 2026 15:30:16 +0300 Subject: [PATCH] Keep the display and the system awake while the game window is up and not minimized Windows turned the monitor off after its idle timeout during play, since gamepad input does not count as activity (#7). Co-Authored-By: Claude Opus 5.5 --- runtime/gfx_window.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runtime/gfx_window.c b/runtime/gfx_window.c index fc449051..98bc8fe3 100644 --- a/runtime/gfx_window.c +++ b/runtime/gfx_window.c @@ -203,6 +203,16 @@ static void cfg_window_size(int *w, int *h) { *h = y; } +// Windows turns the display off and sleeps after the idle timeout, and gamepad input does not count as activity. While +// the window is up and not minimized it holds the display and the system on, as other games do. The state belongs to +// the calling thread, so only the window thread (window_main and wnd_proc) calls this; the process exit releases it. +static void keep_awake(int on) { + static int cur = -1; + if (on == cur) return; + cur = on; + SetThreadExecutionState(on ? ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED : ES_CONTINUOUS); +} + // F11: borderless window over the whole monitor, and back to the saved window. The swapchain follows through WM_SIZE. // Not Alt+Enter: Enter is the Plus button (input_win.c). A background window (test runs) keeps its place behind the // user's windows and takes no focus. @@ -372,6 +382,7 @@ static LRESULT CALLBACK wnd_proc(HWND h, UINT m, WPARAM w, LPARAM l) { } return 0; case WM_SIZE: + keep_awake(w != SIZE_MINIMIZED); if (w != SIZE_MINIMIZED) InterlockedExchange(&g_dirty, 1); refresh_rate_update(h, 0); return 0; @@ -441,6 +452,7 @@ static DWORD WINAPI window_main(void *arg) { } note_applied(); refresh_rate_update(g_hwnd, 1); + keep_awake(1); } SetEvent(g_wnd_ready); if (g_wnd_failed) return 1;