Hello world,
migrating my app from GTK3 to GTK4 … still …
In the past days I commented here about how difficult it is with GTK4 to handle dynamical menus:
https://discourse.gnome.org/t/gtk4-and-dynamical-menus/8529
Since then, and since I cannot insert/remove/refresh menu elements at will, at least for the time being, I decided to refresh, that is recreate, the entire menu bar each time I need to do it, therefore a menu bar action can trigger the rebuild of the menu bar, but for some reason it does not work because the program freezes.
I noticed the following behavior, that I cannot explain:
-
Refresh/rebuild of the menu bar from the menu bar action, freezes:
G_MODULE_EXPORT void menu_bar_action (GSimpleAction * action, GVariant * parameter, gpointer data) { // Do some action, then: re_create_menu_bar (); }
-
Refresh/rebuild of the menu bar from a window called by the menu bar action, works fine:
GMainLoop * Event_loop; G_MODULE_EXPORT void destroy_dialog (GtkDialog * dialog, gint response_id, gpointer data) { // Destroying the dialog window gtk_window_destroy (GTK_WINDOW(dialog)); g_main_loop_quit (Event_loop); } G_MODULE_EXPORT void menu_bar_action (GSimpleAction * action, GVariant * parameter, gpointer data) { // Window to do some action, with MainWindow defined elsewhere: GtkWidget * dialog = gtk_dialog_new_with_buttons ("Menu action", MainWindow, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "Close", GTK_RESPONSE_CLOSE, NULL); gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); g_signal_connect (G_OBJECT(dialog), "response", G_CALLBACK(destroy_dialog), NULL); gtk_widget_show (dialog); Event_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (Event_loop); // Then refreshing the menu bar based on what happened in the dialog re_create_menu_bar (); }
I reproduce this behavior at several points in my app.
Can anyone share some thoughts on what is going on there ?
Also I create the menu by coding, using GMenu
and GMenuItem
elements.
Thanks in advance.
S.
Update:
As if that wasn’t easy enough to understand I cannot debug menu action, as explained here:
https://discourse.gnome.org/t/gtk4-menus-focus-behavior-and-gdb-debugging/8697/4
So I am not able to find a way to get more information on this issue … if anyone has a clue I will gladly take it