From 015e42be053d6ed72bc08dfe14b4d0a71dc8041a Mon Sep 17 00:00:00 2001
From: Steveice10 <1269164+Steveice10@users.noreply.github.com>
Date: Tue, 9 Jan 2024 09:56:39 -0800
Subject: [PATCH] Port yuzu-emu/yuzu#7506 & yuzu-emu/yuzu#7861: "Fix
yuzu-emu/yuzu#7502" & "yuzu: Mute audio when in background" (#7321)
---
src/citra_qt/configuration/config.cpp | 2 ++
.../configuration/configure_general.cpp | 3 ++
.../configuration/configure_general.ui | 7 ++++
src/citra_qt/main.cpp | 34 +++++++++++++------
src/citra_qt/main.h | 1 +
src/citra_qt/uisettings.h | 1 +
6 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp
index 5c0abbc2a..74d779b0a 100644
--- a/src/citra_qt/configuration/config.cpp
+++ b/src/citra_qt/configuration/config.cpp
@@ -768,6 +768,7 @@ void Config::ReadUIValues() {
ReadBasicSetting(UISettings::values.callout_flags);
ReadBasicSetting(UISettings::values.show_console);
ReadBasicSetting(UISettings::values.pause_when_in_background);
+ ReadBasicSetting(UISettings::values.mute_when_in_background);
ReadBasicSetting(UISettings::values.hide_mouse);
}
@@ -1239,6 +1240,7 @@ void Config::SaveUIValues() {
WriteBasicSetting(UISettings::values.callout_flags);
WriteBasicSetting(UISettings::values.show_console);
WriteBasicSetting(UISettings::values.pause_when_in_background);
+ WriteBasicSetting(UISettings::values.mute_when_in_background);
WriteBasicSetting(UISettings::values.hide_mouse);
}
diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp
index bdcb640c9..a402523bf 100644
--- a/src/citra_qt/configuration/configure_general.cpp
+++ b/src/citra_qt/configuration/configure_general.cpp
@@ -74,6 +74,8 @@ void ConfigureGeneral::SetConfiguration() {
ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing.GetValue());
ui->toggle_background_pause->setChecked(
UISettings::values.pause_when_in_background.GetValue());
+ ui->toggle_background_mute->setChecked(
+ UISettings::values.mute_when_in_background.GetValue());
ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse.GetValue());
ui->toggle_update_check->setChecked(
@@ -174,6 +176,7 @@ void ConfigureGeneral::ApplyConfiguration() {
if (Settings::IsConfiguringGlobal()) {
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked();
+ UISettings::values.mute_when_in_background = ui->toggle_background_mute->isChecked();
UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked();
UISettings::values.check_for_update_on_start = ui->toggle_update_check->isChecked();
diff --git a/src/citra_qt/configuration/configure_general.ui b/src/citra_qt/configuration/configure_general.ui
index 316edadb1..deb6c4282 100644
--- a/src/citra_qt/configuration/configure_general.ui
+++ b/src/citra_qt/configuration/configure_general.ui
@@ -36,6 +36,13 @@
+ -
+
+
+ Mute audio when in background
+
+
+
-
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 302ebc1f7..b129a0e5f 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -778,21 +778,33 @@ void GMainWindow::RestoreUIState() {
}
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 (emulation_running && !emu_thread->IsRunning() && auto_paused &&
- state == Qt::ApplicationActive) {
- auto_paused = false;
- OnStartGame();
+ if (!emulation_running) {
+ return;
+ }
+ if (UISettings::values.pause_when_in_background) {
+ if (emu_thread->IsRunning() &&
+ (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) {
+ auto_paused = true;
+ OnPauseGame();
+ } else if (!emu_thread->IsRunning() && auto_paused && state == Qt::ApplicationActive) {
+ auto_paused = false;
+ OnStartGame();
+ }
+ }
+ if (UISettings::values.mute_when_in_background) {
+ if (!Settings::values.audio_muted &&
+ (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) {
+ Settings::values.audio_muted = true;
+ auto_muted = true;
+ } else if (auto_muted && state == Qt::ApplicationActive) {
+ Settings::values.audio_muted = false;
+ auto_muted = false;
+ }
+ UpdateVolumeUI();
}
}
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h
index a89561ad2..934b56d34 100644
--- a/src/citra_qt/main.h
+++ b/src/citra_qt/main.h
@@ -325,6 +325,7 @@ private:
QString game_path;
bool auto_paused = false;
+ bool auto_muted = false;
QTimer mouse_hide_timer;
// Movie
diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h
index a0e7559c0..8e671f49f 100644
--- a/src/citra_qt/uisettings.h
+++ b/src/citra_qt/uisettings.h
@@ -80,6 +80,7 @@ struct Values {
Settings::Setting save_state_warning{true, "saveStateWarning"};
Settings::Setting first_start{true, "firstStart"};
Settings::Setting pause_when_in_background{false, "pauseWhenInBackground"};
+ Settings::Setting mute_when_in_background{false, "muteWhenInBackground"};
Settings::Setting hide_mouse{false, "hideInactiveMouse"};
bool updater_found;