From 23405b4ce19cba8c33d3ead1541ea37e3c3d9e0b Mon Sep 17 00:00:00 2001 From: vitor-k Date: Tue, 10 Sep 2019 21:52:17 -0300 Subject: [PATCH 1/6] 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 d9d9a6c0e..0fc10508e 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 204d1c8f1..82c94972c 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: /** From 7224ec57f6c7a0df82f3f4e0aa06f47fd1723cf9 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Wed, 11 Sep 2019 21:53:26 -0300 Subject: [PATCH 2/6] Only auto unpause when auto paused --- src/citra_qt/main.cpp | 4 +++- src/citra_qt/main.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0fc10508e..a401ce2d9 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -503,9 +503,11 @@ void GMainWindow::OnLoseFocus(Qt::ApplicationState state) { if (ui.action_Pause->isEnabled() && (state == Qt::ApplicationSuspended || state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { + auto_paused = true; OnPauseGame(); } - if (ui.action_Start->isEnabled() && state == Qt::ApplicationActive) { + if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { + auto_paused = false; OnStartGame(); } } diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 82c94972c..9cb6886d3 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -233,6 +233,8 @@ private: // The path to the game currently running QString game_path; + bool auto_paused = false; + // Movie bool movie_record_on_start = false; QString movie_record_path; From 356fd60520fe28991b83a1d784853aa660973317 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Fri, 13 Sep 2019 23:01:12 -0300 Subject: [PATCH 3/6] Add option to enable pause when on background --- src/citra_qt/configuration/config.cpp | 2 ++ .../configuration/configure_general.cpp | 2 ++ .../configuration/configure_general.ui | 7 +++++++ src/citra_qt/main.cpp | 20 ++++++++++--------- src/citra_qt/uisettings.h | 1 + 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index ddcb71e3d..970dc7bca 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -384,6 +384,7 @@ void Config::ReadValues() { UISettings::values.first_start = ReadSetting("firstStart", true).toBool(); UISettings::values.callout_flags = ReadSetting("calloutFlags", 0).toUInt(); UISettings::values.show_console = ReadSetting("showConsole", false).toBool(); + UISettings::values.pause_when_on_background = ReadSetting("pauseWhenOnBackground", false).toBool(); qt_config->beginGroup("Multiplayer"); UISettings::values.nickname = ReadSetting("nickname", "").toString(); @@ -636,6 +637,7 @@ void Config::SaveValues() { WriteSetting("firstStart", UISettings::values.first_start, true); WriteSetting("calloutFlags", UISettings::values.callout_flags, 0); WriteSetting("showConsole", UISettings::values.show_console, false); + WriteSetting("pauseWhenOnBackground", UISettings::values.pause_when_on_background, false); qt_config->beginGroup("Multiplayer"); WriteSetting("nickname", UISettings::values.nickname, ""); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index 7332d959a..2911c26fe 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -26,6 +26,7 @@ ConfigureGeneral::~ConfigureGeneral() = default; void ConfigureGeneral::SetConfiguration() { ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); + ui->toggle_background_pause->setChecked(UISettings::values.pause_when_on_background); ui->toggle_update_check->setChecked(UISettings::values.check_for_update_on_start); ui->toggle_auto_update->setChecked(UISettings::values.update_on_close); @@ -53,6 +54,7 @@ void ConfigureGeneral::ResetDefaults() { void ConfigureGeneral::ApplyConfiguration() { UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); + UISettings::values.pause_when_on_background = ui->toggle_background_pause->isChecked(); UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked(); UISettings::values.update_on_close = ui->toggle_auto_update->isChecked(); diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 0e7933625..046169c3b 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -29,6 +29,13 @@ + + + + Pause emulation when on background + + + diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index a401ce2d9..eb8cc55c7 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -500,15 +500,17 @@ void GMainWindow::RestoreUIState() { } void GMainWindow::OnLoseFocus(Qt::ApplicationState state) { - if (ui.action_Pause->isEnabled() && - (state == Qt::ApplicationSuspended || - state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { - auto_paused = true; - OnPauseGame(); - } - if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { - auto_paused = false; - OnStartGame(); + if (UISettings::values.pause_when_on_background) { + if (ui.action_Pause->isEnabled() && + (state == Qt::ApplicationSuspended || + state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { + auto_paused = true; + OnPauseGame(); + } + if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { + auto_paused = false; + OnStartGame(); + } } } diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h index 573b4d975..175c68a2b 100644 --- a/src/citra_qt/uisettings.h +++ b/src/citra_qt/uisettings.h @@ -72,6 +72,7 @@ struct Values { bool confirm_before_closing; bool first_start; + bool pause_when_on_background; bool updater_found; bool update_on_close; From 66b1e419c38e301d8b2ead9ca4ab3893c9d4ff35 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Sat, 14 Sep 2019 18:14:23 -0300 Subject: [PATCH 4/6] Naming changes and clang format --- src/citra_qt/configuration/config.cpp | 5 +++-- src/citra_qt/configuration/configure_general.cpp | 4 ++-- src/citra_qt/main.cpp | 6 +++--- src/citra_qt/main.h | 2 +- src/citra_qt/uisettings.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 970dc7bca..0a7a78835 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -384,7 +384,8 @@ void Config::ReadValues() { UISettings::values.first_start = ReadSetting("firstStart", true).toBool(); UISettings::values.callout_flags = ReadSetting("calloutFlags", 0).toUInt(); UISettings::values.show_console = ReadSetting("showConsole", false).toBool(); - UISettings::values.pause_when_on_background = ReadSetting("pauseWhenOnBackground", false).toBool(); + UISettings::values.pause_when_in_background = + ReadSetting("pauseWhenInBackground", false).toBool(); qt_config->beginGroup("Multiplayer"); UISettings::values.nickname = ReadSetting("nickname", "").toString(); @@ -637,7 +638,7 @@ void Config::SaveValues() { WriteSetting("firstStart", UISettings::values.first_start, true); WriteSetting("calloutFlags", UISettings::values.callout_flags, 0); WriteSetting("showConsole", UISettings::values.show_console, false); - WriteSetting("pauseWhenOnBackground", UISettings::values.pause_when_on_background, false); + WriteSetting("pauseWhenInBackground", UISettings::values.pause_when_in_background, false); qt_config->beginGroup("Multiplayer"); WriteSetting("nickname", UISettings::values.nickname, ""); diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index 2911c26fe..47d559e3d 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -26,7 +26,7 @@ ConfigureGeneral::~ConfigureGeneral() = default; void ConfigureGeneral::SetConfiguration() { ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); - ui->toggle_background_pause->setChecked(UISettings::values.pause_when_on_background); + ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background); ui->toggle_update_check->setChecked(UISettings::values.check_for_update_on_start); ui->toggle_auto_update->setChecked(UISettings::values.update_on_close); @@ -54,7 +54,7 @@ void ConfigureGeneral::ResetDefaults() { void ConfigureGeneral::ApplyConfiguration() { UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); - UISettings::values.pause_when_on_background = ui->toggle_background_pause->isChecked(); + UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked(); UISettings::values.update_on_close = ui->toggle_auto_update->isChecked(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index eb8cc55c7..9b2fc5253 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -499,8 +499,8 @@ void GMainWindow::RestoreUIState() { statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked()); } -void GMainWindow::OnLoseFocus(Qt::ApplicationState state) { - if (UISettings::values.pause_when_on_background) { +void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { + if (UISettings::values.pause_when_in_background) { if (ui.action_Pause->isEnabled() && (state == Qt::ApplicationSuspended || state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { @@ -2030,7 +2030,7 @@ int main(int argc, char* argv[]) { main_window.show(); QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window, - &GMainWindow::OnLoseFocus); + &GMainWindow::OnAppFocusStateChanged); int result = app.exec(); detached_tasks.WaitForAllTasks(); diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 9cb6886d3..c86d99b79 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -69,7 +69,7 @@ public: std::unique_ptr discord_rpc; public slots: - void OnLoseFocus(Qt::ApplicationState state); + void OnAppFocusStateChanged(Qt::ApplicationState state); signals: /** diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h index 175c68a2b..bc1fc9f0f 100644 --- a/src/citra_qt/uisettings.h +++ b/src/citra_qt/uisettings.h @@ -72,7 +72,7 @@ struct Values { bool confirm_before_closing; bool first_start; - bool pause_when_on_background; + bool pause_when_in_background; bool updater_found; bool update_on_close; From 05b1cfc63b58798d95f68632f26b349b44bd99e9 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Sun, 15 Sep 2019 01:08:12 -0300 Subject: [PATCH 5/6] Pause in background guard clause and unused flag --- .../configuration/configure_general.ui | 2 +- src/citra_qt/main.cpp | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 046169c3b..74b9da7ad 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -32,7 +32,7 @@ - Pause emulation when on background + Pause emulation when in background diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 9b2fc5253..45344126a 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -500,17 +500,17 @@ void GMainWindow::RestoreUIState() { } void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { - if (UISettings::values.pause_when_in_background) { - if (ui.action_Pause->isEnabled() && - (state == Qt::ApplicationSuspended || - state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { - auto_paused = true; - OnPauseGame(); - } - if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { - auto_paused = false; - OnStartGame(); - } + if (!UISettings::values.pause_when_in_background) { + return; + } + if (ui.action_Pause->isEnabled() && + (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { + auto_paused = true; + OnPauseGame(); + } + if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { + auto_paused = false; + OnStartGame(); } } From 8d8bc8fee72deb8221f7f302630bc731b48a0ce0 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Wed, 18 Sep 2019 15:26:38 -0300 Subject: [PATCH 6/6] small changes to ApplicationState handling, just in case --- src/citra_qt/configuration/configure_general.ui | 2 +- src/citra_qt/main.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 74b9da7ad..2a461a05d 100644 --- a/src/citra_qt/configuration/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -29,7 +29,7 @@ - + Pause emulation when in background diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 45344126a..482dd6f10 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -503,12 +503,15 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { if (!UISettings::values.pause_when_in_background) { return; } + if (state != Qt::ApplicationHidden && state != Qt::ApplicationInactive && + state != Qt::ApplicationActive) { + LOG_DEBUG(Frontend, "ApplicationState unusual flag: {} ", state); + } if (ui.action_Pause->isEnabled() && (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { auto_paused = true; OnPauseGame(); - } - if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { + } else if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { auto_paused = false; OnStartGame(); }