1
0
Fork 0
forked from suyu/suyu

yuzu: Mute audio when in background

This commit is contained in:
german77 2022-02-06 20:46:22 -06:00
parent 49eb78497b
commit ab93b4c66d
6 changed files with 27 additions and 4 deletions

View file

@ -769,6 +769,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);
qt_config->endGroup();
@ -1297,6 +1298,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);
qt_config->endGroup();

View file

@ -46,6 +46,7 @@ void ConfigureGeneral::SetConfiguration() {
ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing.GetValue());
ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot.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_speed_limit->setChecked(Settings::values.use_speed_limit.GetValue());
@ -95,6 +96,7 @@ void ConfigureGeneral::ApplyConfiguration() {
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();
UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->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();
Settings::values.fps_cap.SetValue(ui->fps_cap->value());

View file

@ -163,6 +163,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="toggle_background_mute">
<property name="text">
<string>Mute audio when in background</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="toggle_hide_mouse">
<property name="text">

View file

@ -1034,14 +1034,14 @@ 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 (emulation_running) {
if (!emulation_running) {
return;
}
if (UISettings::values.pause_when_in_background) {
if (emu_thread->IsRunning() &&
(state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) {
auto_paused = true;
@ -1051,6 +1051,16 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) {
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;
}
}
}
void GMainWindow::ConnectWidgetEvents() {

View file

@ -372,6 +372,7 @@ private:
QString game_path;
bool auto_paused = false;
bool auto_muted = false;
QTimer mouse_hide_timer;
// FS

View file

@ -73,6 +73,7 @@ struct Values {
Settings::BasicSetting<bool> confirm_before_closing{true, "confirmClose"};
Settings::BasicSetting<bool> first_start{true, "firstStart"};
Settings::BasicSetting<bool> pause_when_in_background{false, "pauseWhenInBackground"};
Settings::BasicSetting<bool> mute_when_in_background{false, "muteWhenInBackground"};
Settings::BasicSetting<bool> hide_mouse{true, "hideInactiveMouse"};
Settings::BasicSetting<bool> select_user_on_boot{false, "select_user_on_boot"};