diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index d9d9a6c0ea..0fc10508eb 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -499,6 +499,17 @@ void GMainWindow::RestoreUIState() { statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked()); } +void GMainWindow::OnLoseFocus(Qt::ApplicationState state) { + if (ui.action_Pause->isEnabled() && + (state == Qt::ApplicationSuspended || + state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { + OnPauseGame(); + } + if (ui.action_Start->isEnabled() && state == Qt::ApplicationActive) { + OnStartGame(); + } +} + void GMainWindow::ConnectWidgetEvents() { connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile); connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory); @@ -2013,6 +2024,10 @@ int main(int argc, char* argv[]) { Core::System::GetInstance().RegisterSoftwareKeyboard(std::make_shared(main_window)); main_window.show(); + + QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window, + &GMainWindow::OnLoseFocus); + int result = app.exec(); detached_tasks.WaitForAllTasks(); return result; diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 204d1c8f13..82c94972cd 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -68,6 +68,8 @@ public: GameList* game_list; std::unique_ptr discord_rpc; +public slots: + void OnLoseFocus(Qt::ApplicationState state); signals: /**