From b2e40193835c9a9899d8e1140005b63dbfdd86ca Mon Sep 17 00:00:00 2001 From: Corwin Mcknight Date: Tue, 8 Sep 2015 17:20:36 -0700 Subject: [PATCH] DolphinQt: Disable Display Sleep on Windows. Disables Display Sleeping on Windows on DolphinQt while the game runs, and re-enables it after the game closes. --- Source/Core/DolphinQt/MainWindow.cpp | 21 ++++++++++++++++++--- Source/Core/DolphinQt/MainWindow.h | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 4c371678e5..219500e244 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -138,11 +138,27 @@ void DMainWindow::StartGame(const QString filename) } else { - // TODO: Disable screensaver! + DisableScreensaver(); emit CoreStateChanged(Core::CORE_RUN); } } +void DMainWindow::DisableScreensaver() +{ +#ifdef Q_OS_WIN + // Prevents Windows from sleeping or turning off the display + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); +#endif +} + +void DMainWindow::EnableScreensaver() +{ +#ifdef Q_OS_WIN + // Allows Windows to sleep and turn off the display + SetThreadExecutionState(ES_CONTINUOUS); +#endif +} + QString DMainWindow::RequestBootFilename() { // If a game is already selected, just return the filename @@ -263,8 +279,7 @@ bool DMainWindow::Stop() // TODO: Show the author/description dialog here BootManager::Stop(); - - // TODO: Allow screensaver again + EnableScreensaver(); // TODO: Restore original window title // TODO: diff --git a/Source/Core/DolphinQt/MainWindow.h b/Source/Core/DolphinQt/MainWindow.h index 164e4528c5..28adee535a 100644 --- a/Source/Core/DolphinQt/MainWindow.h +++ b/Source/Core/DolphinQt/MainWindow.h @@ -68,6 +68,9 @@ private: std::unique_ptr m_ui; DGameTracker* m_game_tracker; + // Misc. + void DisableScreensaver(); + void EnableScreensaver(); // Emulation QString RequestBootFilename(); QString ShowFileDialog();