From 7661f5a3d758c334926e47920fb2a190f8c10104 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 20 Aug 2018 21:36:23 -0700 Subject: [PATCH] Use SetThreadExecutionState() to disable the screensaver since SDL doesn't currently call that. Fixes #46 --- app/streaming/session.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index b8a90769..cf69b5d3 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -5,6 +5,12 @@ #include #include "utils.h" +// HACK: Need to call SetThreadExecutionState() because SDL doesn't +#ifdef Q_OS_WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + #ifdef HAVE_FFMPEG #include "video/ffmpeg.h" #endif @@ -732,6 +738,13 @@ void Session::exec() // Disable the screen saver SDL_DisableScreenSaver(); +#ifdef Q_OS_WIN32 + // HACK: SDL doesn't call this, so we must do so to disable the + // screensaver when we're in windowed mode. DirectX will disable + // it for us when we're in full-screen exclusive mode. + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); +#endif + // Set timer resolution to 1 ms on Windows for greater // sleep precision and more accurate callback timing. SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "1"); @@ -869,6 +882,11 @@ void Session::exec() SDL_GetError()); DispatchDeferredCleanup: +#ifdef Q_OS_WIN32 + // HACK: See comment above + SetThreadExecutionState(ES_CONTINUOUS); +#endif + // Uncapture the mouse and hide the window immediately, // so we can return to the Qt GUI ASAP. SDL_SetRelativeMouseMode(SDL_FALSE);