From f6838a901c8a85a911d5e49b9e8d11c8651aeaec Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 12 May 2020 23:32:49 +0200 Subject: [PATCH] =?UTF-8?q?[GTK3]=20Persist=20=E2=80=9Cmute=20sound?= =?UTF-8?q?=E2=80=9D=20state=20in=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gtk3/main.c | 8 ++++---- gtk3/settings.c | 17 ++++++++++++----- gtk3/settings.h | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index e039a92..6cdfddc 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -1526,7 +1526,7 @@ static void start(void) { gui_data.stopped = false; GB_audio_clear_queue(); - GB_audio_set_paused(false); + GB_audio_set_paused(config.audio.muted); /* Run emulation */ while (gui_data.running) { @@ -1994,7 +1994,7 @@ static void startup(GApplication *app, gpointer null_ptr) { gui_data.preferences = GTK_WINDOW(get_object("preferences")); 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.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) { - 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); } diff --git a/gtk3/settings.c b/gtk3/settings.c index 9971472..f763828 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -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) { GtkWindow *preferences = GTK_WINDOW(w); GtkBuilder *builder = (GtkBuilder *) builder_ptr; - + GApplication *app = G_APPLICATION(gtk_builder_get_application(builder)); + update_boot_rom_selector(builder); // 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, "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, "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, "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_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_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_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); @@ -143,7 +147,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) { #endif } -void init_settings(gchar *path, GtkWindow *preferences) { +void init_settings(GApplication *app, gchar *path, GtkWindow *preferences) { free_settings(); 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); } - load_settings(); + load_settings(app); } -int load_settings(void) { +int load_settings(GApplication *app) { GError *error = NULL; 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); _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; } @@ -472,7 +479,7 @@ GB_model_t get_model(void) { } else if (g_strcmp0(config.emulation.model, "MGB") == 0) { g_warning("Emulation of MGBs is unsupported, falling back to DMG."); - + return get_dmg_model(); } else if (g_strcmp0(config.emulation.model, "AGB") == 0) { diff --git a/gtk3/settings.h b/gtk3/settings.h index 59059a9..60e153f 100644 --- a/gtk3/settings.h +++ b/gtk3/settings.h @@ -47,6 +47,7 @@ EXPAND_GROUP(audio, \ EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \ EXPAND_GROUP_MEMBER(sample_rate, integer, -1) \ + EXPAND_GROUP_MEMBER(muted, boolean, false) \ ) \ EXPAND_GROUP(controls, \ 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 load_config_from_key_file(config_t *config, GKeyFile *key_file); -void init_settings(gchar *path, GtkWindow *preferences); -int load_settings(void); +void init_settings(GApplication *app, gchar *path, GtkWindow *preferences); +int load_settings(GApplication *app); void save_settings(void); void free_settings(void);