From eff5f65096d406191ba87102b0909aac9fc2a98b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 9 Oct 2018 23:01:43 -0700 Subject: [PATCH] Implement SuspendScreenSaver for Win32 Creating a full-screen SDL renderer on Windows will keep the screensaver suspended by DirectX, as is default for full-screen DX applications. However, for applications that render in windowed-mode, the screensaver will still kick in, even if SDL_DisableScreenSaver() is called or SDL_HINT_VIDEO_ALLOW_SCREENSAVER is set to 0 (default). Implementing a SuspendScreenSaver() function for Win32 fixes this behavior. --- src/video/windows/SDL_windowsvideo.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 300bd2f36..358ab2356 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -63,6 +63,15 @@ UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const } } +static void WIN_SuspendScreenSaver(_THIS) +{ + if (_this->suspend_screensaver) { + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + } else { + SetThreadExecutionState(ES_CONTINUOUS); + } +} + /* Windows driver bootstrap functions */ @@ -136,6 +145,7 @@ WIN_CreateDevice(int devindex) device->GetDisplayModes = WIN_GetDisplayModes; device->SetDisplayMode = WIN_SetDisplayMode; device->PumpEvents = WIN_PumpEvents; + device->SuspendScreenSaver = WIN_SuspendScreenSaver; device->CreateSDLWindow = WIN_CreateWindow; device->CreateSDLWindowFrom = WIN_CreateWindowFrom;