Implement SuspendScreenSaver for Win32
authorCameron Gutman <cameron.gutman@gmail.com>
Tue, 09 Oct 2018 23:01:43 -0700
changeset 12316e9954c42ee01
parent 12315 5ce13990c5fb
child 12317 d147224c0f28
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
     1.1 --- a/src/video/windows/SDL_windowsvideo.c	Wed Oct 10 15:20:56 2018 -0400
     1.2 +++ b/src/video/windows/SDL_windowsvideo.c	Tue Oct 09 23:01:43 2018 -0700
     1.3 @@ -63,6 +63,15 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static void WIN_SuspendScreenSaver(_THIS)
     1.8 +{
     1.9 +    if (_this->suspend_screensaver) {
    1.10 +        SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
    1.11 +    } else {
    1.12 +        SetThreadExecutionState(ES_CONTINUOUS);
    1.13 +    }
    1.14 +}
    1.15 +
    1.16  
    1.17  /* Windows driver bootstrap functions */
    1.18  
    1.19 @@ -136,6 +145,7 @@
    1.20      device->GetDisplayModes = WIN_GetDisplayModes;
    1.21      device->SetDisplayMode = WIN_SetDisplayMode;
    1.22      device->PumpEvents = WIN_PumpEvents;
    1.23 +    device->SuspendScreenSaver = WIN_SuspendScreenSaver;
    1.24  
    1.25      device->CreateSDLWindow = WIN_CreateWindow;
    1.26      device->CreateSDLWindowFrom = WIN_CreateWindowFrom;