From b4289951267ba4ea15a41fe8847cd1ae4043ee45 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 15 Oct 2019 00:16:59 +0200 Subject: [PATCH] [GTK3] Reflect CLI model override in GUI --- gtk3/main.c | 26 +++++++++++++++++++++++++- gtk3/main.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gtk3/main.c b/gtk3/main.c index e5a96ca..b9dd877 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -81,6 +81,7 @@ static GMutex console_output_lock; static GPtrArray *debugger_input_queue; // List of GActions for the `app` prefix +// TODO: The order of the items in the structure are intended to reflect frequency of use static const GActionEntry app_entries[] = { { "quit", activate_quit, NULL, NULL, NULL }, { "about", activate_about, NULL, NULL, NULL }, @@ -93,8 +94,8 @@ static const GActionEntry app_entries[] = { { "reset", activate_reset, NULL, NULL, NULL }, { "toggle_blend_frames", NULL, NULL, "true", NULL }, { "toggle_developer_mode", NULL, NULL, "false", NULL }, - { "toggle_mute", NULL, NULL, "false", on_mute_changed }, { "change_model", NULL, "s", "@s 'CGB'", on_model_changed }, + { "toggle_mute", NULL, NULL, "false", on_mute_changed }, { "pause", NULL, NULL, "false", on_pause_changed }, }; @@ -155,6 +156,8 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin // TODO: Synchronize with GB_model_t (Core/gb.h) if (g_str_has_prefix(model_name, "DMG")) { + gui_data->cli_options.prefix = "DMG"; + if (g_str_has_suffix(model_name, "-B") || g_strcmp0(model_name, "DMG") == 0) { gui_data->cli_options.model = GB_MODEL_DMG_B; } @@ -164,6 +167,8 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } } else if (g_str_has_prefix(model_name, "SGB")) { + gui_data->cli_options.prefix = "SGB"; + if (g_str_has_suffix(model_name, "-NTSC") || g_strcmp0(model_name, "SGB") == 0) { gui_data->cli_options.model = GB_MODEL_SGB; } @@ -179,6 +184,8 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } } else if (g_str_has_prefix(model_name, "CGB")) { + gui_data->cli_options.prefix = "CGB"; + if (g_str_has_suffix(model_name, "-C")) { gui_data->cli_options.model = GB_MODEL_CGB_C; } @@ -191,9 +198,13 @@ static gint handle_local_options(GApplication *app, GVariantDict *options, gpoin } } else if (g_str_has_prefix(model_name, "AGB")) { + gui_data->cli_options.prefix = "AGB"; + gui_data->cli_options.model = GB_MODEL_AGB; } else { + gui_data->cli_options.prefix = NULL; + g_warning("Unknown model: %s", model_name); exit(EXIT_FAILURE); } @@ -649,6 +660,11 @@ static void startup(GApplication *app, gpointer gui_data_gptr) { // Setup application actions g_action_map_add_action_entries(G_ACTION_MAP(app), app_entries, G_N_ELEMENTS(app_entries), app); + if (gui_data->cli_options.prefix != NULL) { + GAction *action = g_action_map_lookup_action(G_ACTION_MAP(main_application), "change_model"); + g_action_change_state(action, g_variant_new_string(gui_data->cli_options.prefix)); + } + #if NDEBUG // Disable when not compiled in debug mode g_simple_action_set_enabled(G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "open_gtk_debugger")), false); @@ -1000,6 +1016,11 @@ static void activate_reset(GSimpleAction *action, GVariant *parameter, gpointer } static void on_model_changed(GSimpleAction *action, GVariant *value, gpointer user_data) { + if (!GB_is_inited(&gb)) { + g_simple_action_set_state(action, value); + return; + } + const gchar *model_str = g_variant_get_string(value, NULL); GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG(gtk_message_dialog_new( @@ -1015,6 +1036,9 @@ static void on_model_changed(GSimpleAction *action, GVariant *value, gpointer us switch (result) { case GTK_RESPONSE_YES: + // Reset the CLI model override + gui_data.cli_options.model = -1; + g_simple_action_set_state(action, value); reset(&gui_data); break; diff --git a/gtk3/main.h b/gtk3/main.h index 1fadb01..900b1a2 100644 --- a/gtk3/main.h +++ b/gtk3/main.h @@ -24,6 +24,7 @@ typedef struct GuiData { gchar *boot_rom_path; gboolean fullscreen; GB_model_t model; + gchar *prefix; } cli_options; GFile *file;