diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index d0060f6901..d9d9a6c0ea 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -712,6 +712,18 @@ void GMainWindow::OnOpenUpdater() { updater->LaunchUI(); } +void GMainWindow::PreventOSSleep() { +#ifdef _WIN32 + SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); +#endif +} + +void GMainWindow::AllowOSSleep() { +#ifdef _WIN32 + SetThreadExecutionState(ES_CONTINUOUS); +#endif +} + bool GMainWindow::LoadROM(const QString& filename) { // Shutdown previous session if the emu thread is still active... if (emu_thread != nullptr) @@ -902,9 +914,7 @@ void GMainWindow::ShutdownGame() { return; } -#ifdef _WIN32 - SetThreadExecutionState(ES_CONTINUOUS); -#endif + AllowOSSleep(); discord_rpc->Pause(); OnStopRecordingPlayback(); @@ -1223,9 +1233,7 @@ void GMainWindow::OnStartGame() { movie_record_path.clear(); } -#ifdef _WIN32 - SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); -#endif + PreventOSSleep(); emu_thread->SetRunning(true); qRegisterMetaType("Core::System::ResultStatus"); @@ -1255,9 +1263,7 @@ void GMainWindow::OnPauseGame() { ui.action_Stop->setEnabled(true); ui.action_Capture_Screenshot->setEnabled(false); -#ifdef _WIN32 - SetThreadExecutionState(ES_CONTINUOUS); -#endif + AllowOSSleep(); } void GMainWindow::OnStopGame() { diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 780589141a..204d1c8f13 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -104,6 +104,9 @@ private: void ConnectWidgetEvents(); void ConnectMenuEvents(); + void PreventOSSleep(); + void AllowOSSleep(); + bool LoadROM(const QString& filename); void BootGame(const QString& filename); void ShutdownGame();