[GTK3] Reflect CLI model override in GUI

This commit is contained in:
Maximilian Mader 2019-10-15 00:16:59 +02:00
parent a53d7f1e92
commit b428995126
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
2 changed files with 26 additions and 1 deletions

View File

@ -81,6 +81,7 @@ static GMutex console_output_lock;
static GPtrArray *debugger_input_queue; static GPtrArray *debugger_input_queue;
// List of GActions for the `app` prefix // 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[] = { static const GActionEntry app_entries[] = {
{ "quit", activate_quit, NULL, NULL, NULL }, { "quit", activate_quit, NULL, NULL, NULL },
{ "about", activate_about, NULL, NULL, NULL }, { "about", activate_about, NULL, NULL, NULL },
@ -93,8 +94,8 @@ static const GActionEntry app_entries[] = {
{ "reset", activate_reset, NULL, NULL, NULL }, { "reset", activate_reset, NULL, NULL, NULL },
{ "toggle_blend_frames", NULL, NULL, "true", NULL }, { "toggle_blend_frames", NULL, NULL, "true", NULL },
{ "toggle_developer_mode", NULL, NULL, "false", 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 }, { "change_model", NULL, "s", "@s 'CGB'", on_model_changed },
{ "toggle_mute", NULL, NULL, "false", on_mute_changed },
{ "pause", NULL, NULL, "false", on_pause_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) // TODO: Synchronize with GB_model_t (Core/gb.h)
if (g_str_has_prefix(model_name, "DMG")) { 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) { if (g_str_has_suffix(model_name, "-B") || g_strcmp0(model_name, "DMG") == 0) {
gui_data->cli_options.model = GB_MODEL_DMG_B; 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")) { 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) { if (g_str_has_suffix(model_name, "-NTSC") || g_strcmp0(model_name, "SGB") == 0) {
gui_data->cli_options.model = GB_MODEL_SGB; 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")) { else if (g_str_has_prefix(model_name, "CGB")) {
gui_data->cli_options.prefix = "CGB";
if (g_str_has_suffix(model_name, "-C")) { if (g_str_has_suffix(model_name, "-C")) {
gui_data->cli_options.model = GB_MODEL_CGB_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")) { else if (g_str_has_prefix(model_name, "AGB")) {
gui_data->cli_options.prefix = "AGB";
gui_data->cli_options.model = GB_MODEL_AGB; gui_data->cli_options.model = GB_MODEL_AGB;
} }
else { else {
gui_data->cli_options.prefix = NULL;
g_warning("Unknown model: %s", model_name); g_warning("Unknown model: %s", model_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -649,6 +660,11 @@ static void startup(GApplication *app, gpointer gui_data_gptr) {
// Setup application actions // Setup application actions
g_action_map_add_action_entries(G_ACTION_MAP(app), app_entries, G_N_ELEMENTS(app_entries), app); 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 #if NDEBUG
// Disable when not compiled in debug mode // 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); 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) { 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); const gchar *model_str = g_variant_get_string(value, NULL);
GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG(gtk_message_dialog_new( 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) { switch (result) {
case GTK_RESPONSE_YES: case GTK_RESPONSE_YES:
// Reset the CLI model override
gui_data.cli_options.model = -1;
g_simple_action_set_state(action, value); g_simple_action_set_state(action, value);
reset(&gui_data); reset(&gui_data);
break; break;

View File

@ -24,6 +24,7 @@ typedef struct GuiData {
gchar *boot_rom_path; gchar *boot_rom_path;
gboolean fullscreen; gboolean fullscreen;
GB_model_t model; GB_model_t model;
gchar *prefix;
} cli_options; } cli_options;
GFile *file; GFile *file;