diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 55a30d839..90b7ad40b 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -137,7 +137,6 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) : NotifyClientAreaSizeChanged(std::pair(child->width(), child->height())); BackupGeometry(); - } void GRenderWindow::moveContext() @@ -287,11 +286,11 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair& minimal_size) override; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index a59553e40..7e87037b2 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -186,8 +186,7 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget, SLOT(OnEmulationStarting(EmuThread*))); connect(this, SIGNAL(EmulationStopping()), graphicsTracingWidget, SLOT(OnEmulationStopping())); - connect(render_window, SIGNAL(gotFocus()), this, SLOT(OnStartGame())); - connect(render_window, SIGNAL(lostFocus()), this, SLOT(OnPauseGame())); + connect(render_window, SIGNAL(focusChanged(bool)), this, SLOT(OnFocusChanged(bool))); // Setup hotkeys RegisterHotkey("Main Window", "Load File", QKeySequence::Open); @@ -472,6 +471,8 @@ void GMainWindow::OnStartGame() { ui.action_Stop->setEnabled(true); render_window->setFocus(); + + emulation_paused = false; } void GMainWindow::OnPauseGame() { @@ -480,12 +481,30 @@ void GMainWindow::OnPauseGame() { ui.action_Start->setEnabled(true); ui.action_Pause->setEnabled(false); ui.action_Stop->setEnabled(true); + + emulation_paused = true; } void GMainWindow::OnStopGame() { ShutdownGame(); } +void GMainWindow::OnFocusChanged(bool hasFocus) { + // The focus change does not impact actual emulator state if: + // - the option is disabled + // - the emulation is not started + // - the emulation has been paused through menu + if(!UISettings::values.pause_onfocuslost || + !emu_thread || + emulation_paused) + return; + + if (hasFocus) + emu_thread->SetRunning(true); + else // focus lost + emu_thread->SetRunning(false); +} + void GMainWindow::ToggleWindowMode() { if (ui.action_Single_Window_Mode->isChecked()) { // Render in the main window... @@ -521,6 +540,10 @@ void GMainWindow::OnConfigure() { render_window->ReloadSetKeymaps(); config->Save(); } + + // Make sure the emulation is running when all pauses are disabled + if (emu_thread && !UISettings::values.pause_onfocuslost && !emulation_paused) + emu_thread->SetRunning(true); } void GMainWindow::OnCreateGraphicsSurfaceViewer() { diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index b836b13fb..7893102c0 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -98,6 +98,8 @@ private slots: void OnStartGame(); void OnPauseGame(); void OnStopGame(); + /// Called whenever the render window focus is changed + void OnFocusChanged(bool hasFocus); /// Called whenever a user selects a game in the game list widget. void OnGameListLoadFile(QString game_path); void OnMenuLoadFile(); @@ -118,6 +120,8 @@ private: std::unique_ptr config; + // Whether emulation has been paused (through menus) + bool emulation_paused = false; // Whether emulation is currently running in Citra. bool emulation_running = false; std::unique_ptr emu_thread;