From 7d581f4b52d48c0eccb2a4cccb4b284ea76eed8f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 11 May 2023 02:00:16 +0300 Subject: [PATCH 30/30] Add silent_when_not_in_focus client options See osdn #43757 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/gui_main.c | 14 ++++++++------ client/gui-gtk-4.0/gui_main.c | 14 ++++++++------ client/options.c | 10 ++++++++-- client/options.h | 5 +++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 1c06a05014..180ba586e9 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -244,12 +244,14 @@ static gboolean timer_callback(gpointer data) { double seconds = real_timer_callback(); - if (!audio_paused && !client_focus) { - audio_pause(); - audio_paused = TRUE; - } else if (audio_paused && client_focus) { - audio_resume(); - audio_paused = FALSE; + if (gui_options.silent_when_not_in_focus) { + if (!audio_paused && !client_focus) { + audio_pause(); + audio_paused = TRUE; + } else if (audio_paused && client_focus) { + audio_resume(); + audio_paused = FALSE; + } } timer_id = g_timeout_add(seconds * 1000, timer_callback, NULL); diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c index 4b8b3ba915..f525d6aeb4 100644 --- a/client/gui-gtk-4.0/gui_main.c +++ b/client/gui-gtk-4.0/gui_main.c @@ -244,12 +244,14 @@ static gboolean timer_callback(gpointer data) { double seconds = real_timer_callback(); - if (!audio_paused && !client_focus) { - audio_pause(); - audio_paused = TRUE; - } else if (audio_paused && client_focus) { - audio_resume(); - audio_paused = FALSE; + if (gui_options.silent_when_not_in_focus) { + if (!audio_paused && !client_focus) { + audio_pause(); + audio_paused = TRUE; + } else if (audio_paused && client_focus) { + audio_resume(); + audio_paused = FALSE; + } } timer_id = g_timeout_add(seconds * 1000, timer_callback, NULL); diff --git a/client/options.c b/client/options.c index 2a065a1e7a..3b59963b14 100644 --- a/client/options.c +++ b/client/options.c @@ -151,8 +151,9 @@ struct client_options gui_options = { .sound_enable_menu_music = TRUE, .sound_enable_game_music = TRUE, .sound_effects_volume = 100, + .silent_when_not_in_focus = TRUE, -/* This option is currently set by the client - not by the user. */ + /* This option is currently set by the client - not by the user. */ .update_city_text_in_refresh_tile = TRUE, .draw_city_outlines = TRUE, @@ -2342,12 +2343,17 @@ static struct client_option client_options[] = { N_("Play music during the game, assuming there's suitable " "sound plugin and musicset with in-game tracks."), COC_SOUND, GUI_STUB, TRUE, game_music_enable_callback), - GEN_BOOL_OPTION(sound_enable_menu_music, + GEN_BOOL_OPTION(sound_enable_menu_music, N_("Enable menu music"), N_("Play music while not in actual game, " "assuming there's suitable " "sound plugin and musicset with menu music tracks."), COC_SOUND, GUI_STUB, TRUE, menu_music_enable_callback), + GEN_BOOL_OPTION(silent_when_not_in_focus, + N_("Silent when not in focus"), + N_("Fade all sound out when the client is not in focus. " + "Not all clients support this."), + COC_SOUND, GUI_STUB, TRUE, NULL), GEN_INT_OPTION(sound_effects_volume, N_("Sound volume"), N_("Volume scale from 0-100"), diff --git a/client/options.h b/client/options.h index 419dd766e4..f667a71cae 100644 --- a/client/options.h +++ b/client/options.h @@ -180,6 +180,7 @@ struct client_options bool sound_enable_menu_music; bool sound_enable_game_music; int sound_effects_volume; + bool silent_when_not_in_focus; bool draw_city_outlines; bool draw_city_output; @@ -306,7 +307,7 @@ struct client_options bool gui_gtk3_22_chatline_autocompletion; int gui_gtk3_22_citydlg_xsize; int gui_gtk3_22_citydlg_ysize; - int gui_gtk3_22_popup_tech_help; + int gui_gtk3_22_popup_tech_help; int gui_gtk3_22_governor_range_min; int gui_gtk3_22_governor_range_max; char gui_gtk3_22_font_city_label[512]; @@ -342,7 +343,7 @@ struct client_options bool gui_gtk4_chatline_autocompletion; int gui_gtk4_citydlg_xsize; int gui_gtk4_citydlg_ysize; - int gui_gtk4_popup_tech_help; + int gui_gtk4_popup_tech_help; int gui_gtk4_governor_range_min; int gui_gtk4_governor_range_max; char gui_gtk4_font_city_label[512]; -- 2.39.2