Still looking for help here,
Just for information, I ensured in my code that the custom ‘id’ used to create the menu item is the same that the one I use to try to insert the new widget:
gchar * custom = "target";
g_print ("Custom at:: %s\n", custom);
g_menu_item_set_attribute (item, "custom", "s", custom, NULL);
GVariant * cust = g_menu_item_get_attribute_value (item, "custom", g_variant_type_new("s"));
if (cust) g_print ("item custom is:: %s\n", g_variant_get_string (cust, NULL));
The previous piece of code actually prints properly the insert custom “target”.
I read the GTK code source for the gtk_popover_menu_bar_add_child
function, and following the code I figured that the function gtk_menu_section_box_add_custom
is supposed to insert the widget in the menu:
gboolean
gtk_menu_section_box_add_custom (GtkPopoverMenu *popover,
GtkWidget *child,
const char *id)
{
GtkWidget *stack;
GtkMenuSectionBox *box;
GtkWidget *slot;
stack = gtk_popover_menu_get_stack (popover);
box = GTK_MENU_SECTION_BOX (gtk_stack_get_child_by_name (GTK_STACK (stack), "main"));
if (box == NULL)
return FALSE;
slot = (GtkWidget *)g_hash_table_lookup (box->custom_slots, id);
if (slot == NULL)
return FALSE;
if (gtk_widget_get_first_child (slot))
return FALSE;
gtk_widget_insert_before (child, slot, NULL);
return TRUE;
}
I wish I could run gdb on that part of the code to try to see what’s to read in box
and the custom_slots
property, only I can’t and there is no documentation available for these objects (GtkMenuSectionBox…) in the main doc of the GTK4 API …
Any help would be much appreciated.
Edit: it seems that as the ‘custom’ attribute is an issue here, I verified that as soon as I setup a g_menu_item with a custom attribute using:
g_menu_item_set_attribute (item, “custom”, “s”, “target”, NULL);
or similarly
g_menu_item_set_attribute_value (item, “custom”, g_variant_new_string (“target”));
Then the menu item does not even appear in the menu at runtime … if any one could help, again that would be much appreciated.