diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp
index d67fb4b0f..4adc8e5ee 100644
--- a/src/citra_qt/configuration/config.cpp
+++ b/src/citra_qt/configuration/config.cpp
@@ -388,6 +388,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_in_background =
+ ReadSetting("pauseWhenInBackground", false).toBool();
qt_config->beginGroup("Multiplayer");
UISettings::values.nickname = ReadSetting("nickname", "").toString();
@@ -640,6 +642,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("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 7332d959a..47d559e3d 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_in_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_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/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui
index 0e7933625..2a461a05d 100644
--- a/src/citra_qt/configuration/configure_general.ui
+++ b/src/citra_qt/configuration/configure_general.ui
@@ -29,6 +29,13 @@
+ -
+
+
+ Pause emulation when in background
+
+
+
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index d9d9a6c0e..482dd6f10 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -499,6 +499,24 @@ void GMainWindow::RestoreUIState() {
statusBar()->setVisible(ui.action_Show_Status_Bar->isChecked());
}
+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();
+ } else if (ui.action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) {
+ auto_paused = false;
+ OnStartGame();
+ }
+}
+
void GMainWindow::ConnectWidgetEvents() {
connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile);
connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory);
@@ -2013,6 +2031,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::OnAppFocusStateChanged);
+
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..c86d99b79 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 OnAppFocusStateChanged(Qt::ApplicationState state);
signals:
/**
@@ -231,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;
diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h
index 31be267c6..ef56ea722 100644
--- a/src/citra_qt/uisettings.h
+++ b/src/citra_qt/uisettings.h
@@ -74,6 +74,7 @@ struct Values {
bool confirm_before_closing;
bool first_start;
+ bool pause_when_in_background;
bool updater_found;
bool update_on_close;