From 74cd070e61b5024ed97c2a7fbe88318d05f3d20f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 30 Aug 2020 01:25:55 +0200 Subject: [PATCH] GTK: Reimplement the toolbar using GtkBuilder --- desmume/src/frontend/posix/gtk/main.cpp | 52 ++++++++++++++++++++----- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/main.cpp b/desmume/src/frontend/posix/gtk/main.cpp index dcd386f09..66cb8324a 100644 --- a/desmume/src/frontend/posix/gtk/main.cpp +++ b/desmume/src/frontend/posix/gtk/main.cpp @@ -963,6 +963,42 @@ static const GActionEntry app_entries[] = { { "about", About }, }; +static const char *toolbar = +"" +"" +" " +" " +" " +" " +" _Open" +" document-open" +" app.open" +" " +" " +" " +" " +" _Run" +" media-playback-start" +" app.run" +" " +" " +" " +" " +" _Pause" +" media-playback-pause" +" app.pause" +" " +" " +" " +" " +" _Quit" +" application-exit" +" app.quit" +" " +" " +" " +""; + static const char *graphics_settings = "" "" @@ -1305,6 +1341,7 @@ cairo_filter_t Interpolation = CAIRO_FILTER_NEAREST; static GtkApplication *pApp; static GtkWidget *pWindow; +static GtkWidget *pToolBar; static GtkWidget *pStatusBar; static GtkWidget *pDrawingArea; @@ -1363,9 +1400,6 @@ static void ToggleMenuVisible(GSimpleAction *action, GVariant *parameter, gpoint static void ToggleToolbarVisible(GSimpleAction *action, GVariant *parameter, gpointer user_data) { -#if 0 - GtkWidget *pToolBar = gtk_ui_manager_get_widget (ui_manager, "/ToolBar"); - GVariant *variant = g_action_get_state(G_ACTION(action)); gboolean value = !g_variant_get_boolean(variant); config.view_toolbar = value; @@ -1374,7 +1408,6 @@ static void ToggleToolbarVisible(GSimpleAction *action, GVariant *parameter, gpo else gtk_widget_hide(pToolBar); g_simple_action_set_state(action, g_variant_new_boolean(value)); -#endif } static void ToggleStatusbarVisible(GSimpleAction *action, GVariant *parameter, gpointer user_data) @@ -1391,7 +1424,6 @@ static void ToggleStatusbarVisible(GSimpleAction *action, GVariant *parameter, g static void ToggleFullscreen(GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkWidget *pToolBar = NULL; //gtk_ui_manager_get_widget (ui_manager, "/ToolBar"); GVariant *variant = g_action_get_state(G_ACTION(action)); gboolean fullscreen = !g_variant_get_boolean(variant); config.window_fullscreen = fullscreen; @@ -3627,9 +3659,7 @@ common_gtk_main(GApplication *app, gpointer user_data) SDL_TimerID limiter_timer = NULL; - GtkAccelGroup * accel_group; GtkWidget *pBox; - GtkWidget *pToolBar; /* use any language set on the command line */ if ( my_config->firmware_language != -1) { @@ -3785,7 +3815,11 @@ common_gtk_main(GApplication *app, gpointer user_data) pBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(pWindow), pBox); - accel_group = gtk_accel_group_new(); + /* Create the toolbar */ + GtkBuilder *builder = gtk_builder_new_from_string(toolbar, -1); + pToolBar = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar")); + gtk_container_add(GTK_CONTAINER(pBox), pToolBar); + g_object_unref(builder); /* Update audio toggle status */ if (my_config->disable_sound || !config.audio_enabled) { @@ -4070,7 +4104,7 @@ common_gtk_main(GApplication *app, gpointer user_data) nds_screen.swap = config.view_swap; g_simple_action_set_state(G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "swapscreens")), g_variant_new_boolean(config.view_swap)); - GtkBuilder *builder = gtk_builder_new_from_string(menu_builder, -1); + builder = gtk_builder_new_from_string(menu_builder, -1); GMenuModel *menubar = G_MENU_MODEL(gtk_builder_get_object(builder, "menubar")); gtk_application_set_menubar(GTK_APPLICATION(app), menubar); g_object_unref(builder);