From 23405b4ce19cba8c33d3ead1541ea37e3c3d9e0b Mon Sep 17 00:00:00 2001 From: vitor-k Date: Tue, 10 Sep 2019 21:52:17 -0300 Subject: [PATCH] Pause on unfocused first draft This is a MVP, still needs one or more configuration option(s) and review of the code style. --- src/citra_qt/main.cpp | 15 +++++++++++++++ src/citra_qt/main.h | 2 ++ 2 files changed, 17 insertions(+) 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: /**