From 50f47f1ed5f5a15c0c207f550407ae51b44dd7dd Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 26 Mar 2019 21:11:24 -0700 Subject: [PATCH] Fix handling of screen saver after fa4c0e82bde20b8d5b652c81842bda11a692538a and reset background events hint for UI after streaming --- app/main.cpp | 30 ++++++++++++++++++------------ app/streaming/input.cpp | 3 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index 9d2eb6c9..5ca3e4c9 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -311,6 +311,11 @@ int main(int argc, char *argv[]) // Register custom metatypes for use in signals qRegisterMetaType("NvApp"); + // Allow the display to sleep by default. We will manually use SDL_DisableScreenSaver() + // and SDL_EnableScreenSaver() when appropriate. This hint must be set before + // initializing the SDL video subsystem to have any effect. + SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); + // Steam Link requires that we initialize video before creating our // QGuiApplication in order to configure the framebuffer correctly. // It's fine to do on other platforms too, and it can save some time @@ -319,8 +324,21 @@ int main(int argc, char *argv[]) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER) failed: %s", SDL_GetError()); + return -1; } + // Use atexit() to ensure SDL_Quit() is called. This avoids + // racing with object destruction where SDL may be used. + atexit(SDL_Quit); + + // Avoid the default behavior of changing the timer resolution to 1 ms. + // We don't want this all the time that Moonlight is open. We will set + // it manually when we start streaming. + SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0"); + + // Disable minimize on focus loss by default. Users seem to want this off by default. + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); + QGuiApplication app(argc, argv); // Override the default palette to fix dialog rendering on Linux @@ -441,18 +459,6 @@ int main(int argc, char *argv[]) if (engine.rootObjects().isEmpty()) return -1; - // Use atexit() to ensure SDL_Quit() is called. This avoids - // racing with object destruction where SDL may be used. - atexit(SDL_Quit); - - // Avoid the default behavior of changing the timer resolution to 1 ms. - // We don't want this all the time that Moonlight is open. We will set - // it manually when we start streaming. - SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0"); - - // Disable minimize on focus loss by default. Users seem to want this off by default. - SDL_SetHintWithPriority(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0", SDL_HINT_DEFAULT); - int err = app.exec(); // Give worker tasks time to properly exit. Fixes PendingQuitTask diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index a0c08eb7..ec728c88 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -128,6 +128,9 @@ SdlInputHandler::~SdlInputHandler() SDL_QuitSubSystem(SDL_INIT_JOYSTICK); SDL_assert(!SDL_WasInit(SDL_INIT_JOYSTICK)); + + // Return background event handling to off + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0"); } void SdlInputHandler::handleKeyEvent(SDL_KeyboardEvent* event)