We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4302

Summary: [PATCH] SDL_DisableScreenSaver() not implemented for Win32
Product: SDL Reporter: Cameron Gutman <cameron.gutman>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: flibitijibibo
Version: HG 2.0   
Hardware: x86_64   
OS: Windows 10   
Attachments: Implement WIN_SuspendScreenSaver

Description Cameron Gutman 2018-10-10 06:10:48 UTC
Created attachment 3358 [details]
Implement WIN_SuspendScreenSaver

Copying from my attached changeset summary:

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.
Comment 1 Sam Lantinga 2018-10-11 05:48:40 UTC
Your patch is in, thanks!
https://hg.libsdl.org/SDL/rev/e9954c42ee01
Comment 2 Ethan Lee 2018-10-11 15:25:11 UTC
One quick comment on this, just saw the commit...

In addition to ThreadExecutionState I also found this as a means of toggling the screensaver; the docs suggest this works as long as the PC isn't in power saving mode or in a locked state:

--------------------------------------------------------------------------------
void SetUp()
{
    SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);

    UINT vParam = 0;
    if (SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &vParam, 0))
    {
        if (vParam == 1)
            screenSaverWasEnabled = true;
        else
            screenSaverWasEnabled = false;
    }

    if (screenSaverWasEnabled)
        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, 0, 0);
}

void TearDown()
{
    if (screenSaverWasEnabled)
        SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, 0, 0);
}
--------------------------------------------------------------------------------

This has been shipping in FEZ for a while, so we know it works, but it's also a pretty aggressive way to do this (you can even set the wallpaper with this function o_o).