[GTK3] Persist “mute sound” state in config

This commit is contained in:
Maximilian Mader 2020-05-12 23:32:49 +02:00
parent bdb22e7034
commit f6838a901c
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 19 additions and 11 deletions

View File

@ -1526,7 +1526,7 @@ static void start(void) {
gui_data.stopped = false; gui_data.stopped = false;
GB_audio_clear_queue(); GB_audio_clear_queue();
GB_audio_set_paused(false); GB_audio_set_paused(config.audio.muted);
/* Run emulation */ /* Run emulation */
while (gui_data.running) { while (gui_data.running) {
@ -1994,7 +1994,7 @@ static void startup(GApplication *app, gpointer null_ptr) {
gui_data.preferences = GTK_WINDOW(get_object("preferences")); gui_data.preferences = GTK_WINDOW(get_object("preferences"));
g_signal_connect(gui_data.preferences, "realize", G_CALLBACK(on_preferences_realize), (gpointer) gui_data.builder); g_signal_connect(gui_data.preferences, "realize", G_CALLBACK(on_preferences_realize), (gpointer) gui_data.builder);
init_settings(gui_data.cli_options.config_path, gui_data.preferences); init_settings(app, gui_data.cli_options.config_path, gui_data.preferences);
gui_data.vram_viewer = GTK_WINDOW(get_object("vram_viewer")); gui_data.vram_viewer = GTK_WINDOW(get_object("vram_viewer"));
gui_data.memory_viewer = GTK_WINDOW(get_object("memory_viewer")); gui_data.memory_viewer = GTK_WINDOW(get_object("memory_viewer"));
@ -2496,9 +2496,9 @@ static void on_model_changed(GSimpleAction *action, GVariant *value, gpointer us
} }
static void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr) { static void on_mute_changed(GSimpleAction *action, GVariant *value, gpointer user_data_ptr) {
gboolean do_mute = g_variant_get_boolean(value); config.audio.muted = g_variant_get_boolean(value);
GB_audio_set_paused(do_mute); GB_audio_set_paused(config.audio.muted);
g_simple_action_set_state(action, value); g_simple_action_set_state(action, value);
} }

View File

@ -113,7 +113,8 @@ void save_config_to_key_file(config_t *config, GKeyFile *key_file) {
void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) { void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) {
GtkWindow *preferences = GTK_WINDOW(w); GtkWindow *preferences = GTK_WINDOW(w);
GtkBuilder *builder = (GtkBuilder *) builder_ptr; GtkBuilder *builder = (GtkBuilder *) builder_ptr;
GApplication *app = G_APPLICATION(gtk_builder_get_application(builder));
update_boot_rom_selector(builder); update_boot_rom_selector(builder);
// Hook up the static preferences // Hook up the static preferences
@ -121,6 +122,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) {
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "dmg_revision_selector"), config.emulation.dmg_revision_name); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "dmg_revision_selector"), config.emulation.dmg_revision_name);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sgb_revision_selector"), config.emulation.sgb_revision_name); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sgb_revision_selector"), config.emulation.sgb_revision_name);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "cgb_revision_selector"), config.emulation.cgb_revision_name); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "cgb_revision_selector"), config.emulation.cgb_revision_name);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "shader_selector"), config.video.shader); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "shader_selector"), config.video.shader);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "color_correction_selector"), config.video.color_correction_id); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "color_correction_selector"), config.video.color_correction_id);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "frame_blending_selector"), config.video.frame_blending_mode); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "frame_blending_selector"), config.video.frame_blending_mode);
@ -128,8 +130,10 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) {
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "monochrome_palette_selector"), config.video.monochrome_palette_id); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "monochrome_palette_selector"), config.video.monochrome_palette_id);
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "integer_scaling_toggle"), config.video.use_integer_scaling); gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "integer_scaling_toggle"), config.video.use_integer_scaling);
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "aspect_ratio_toggle"), config.video.keep_aspect_ratio); gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "aspect_ratio_toggle"), config.video.keep_aspect_ratio);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "highpass_filter_selector"), config.audio.high_pass_filter_id); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "highpass_filter_selector"), config.audio.high_pass_filter_id);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sample_rate_selector"), g_strdup_printf("%i", config.audio.sample_rate)); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sample_rate_selector"), g_strdup_printf("%i", config.audio.sample_rate));
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "analog_speed_controls_toggle"), config.controls.analog_speed_controls); gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "analog_speed_controls_toggle"), config.controls.analog_speed_controls);
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rumble_mode_selector"), config.controls.rumble_mode); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rumble_mode_selector"), config.controls.rumble_mode);
@ -143,7 +147,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) {
#endif #endif
} }
void init_settings(gchar *path, GtkWindow *preferences) { void init_settings(GApplication *app, gchar *path, GtkWindow *preferences) {
free_settings(); free_settings();
key_file = g_key_file_new(); key_file = g_key_file_new();
@ -154,10 +158,10 @@ void init_settings(gchar *path, GtkWindow *preferences) {
settings_file_path = g_build_filename(g_get_user_config_dir(), SETTINGS_FILE, NULL); settings_file_path = g_build_filename(g_get_user_config_dir(), SETTINGS_FILE, NULL);
} }
load_settings(); load_settings(app);
} }
int load_settings(void) { int load_settings(GApplication *app) {
GError *error = NULL; GError *error = NULL;
g_message("Trying to load settings from %s", settings_file_path); g_message("Trying to load settings from %s", settings_file_path);
@ -176,6 +180,9 @@ int load_settings(void) {
load_config_from_key_file(&config, key_file); load_config_from_key_file(&config, key_file);
_print_config(&config, G_LOG_LEVEL_DEBUG); _print_config(&config, G_LOG_LEVEL_DEBUG);
// Update GAction states
g_action_group_change_action_state(G_ACTION_GROUP(app), "toggle_mute", g_variant_new_boolean(config.audio.muted));
return 0; return 0;
} }
@ -472,7 +479,7 @@ GB_model_t get_model(void) {
} }
else if (g_strcmp0(config.emulation.model, "MGB") == 0) { else if (g_strcmp0(config.emulation.model, "MGB") == 0) {
g_warning("Emulation of MGBs is unsupported, falling back to DMG."); g_warning("Emulation of MGBs is unsupported, falling back to DMG.");
return get_dmg_model(); return get_dmg_model();
} }
else if (g_strcmp0(config.emulation.model, "AGB") == 0) { else if (g_strcmp0(config.emulation.model, "AGB") == 0) {

View File

@ -47,6 +47,7 @@
EXPAND_GROUP(audio, \ EXPAND_GROUP(audio, \
EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \ EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \
EXPAND_GROUP_MEMBER(sample_rate, integer, -1) \ EXPAND_GROUP_MEMBER(sample_rate, integer, -1) \
EXPAND_GROUP_MEMBER(muted, boolean, false) \
) \ ) \
EXPAND_GROUP(controls, \ EXPAND_GROUP(controls, \
EXPAND_GROUP_MEMBER(analog_speed_controls, boolean, false) \ EXPAND_GROUP_MEMBER(analog_speed_controls, boolean, false) \
@ -84,8 +85,8 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr);
void print_config(config_t *config); void print_config(config_t *config);
void load_config_from_key_file(config_t *config, GKeyFile *key_file); void load_config_from_key_file(config_t *config, GKeyFile *key_file);
void init_settings(gchar *path, GtkWindow *preferences); void init_settings(GApplication *app, gchar *path, GtkWindow *preferences);
int load_settings(void); int load_settings(GApplication *app);
void save_settings(void); void save_settings(void);
void free_settings(void); void free_settings(void);