So I have GtkMenuButton with an attached popover. Inside the popover all I have is a box with a button in it. I connect to the show and closed signals to create/destroy the button inside the popover.
The weird behaviour is that on every second click the popover quickly shows and hides thus making it look like it doesn’t show every other click.
This only happens as long as I remove a widget in the closed signal. If I don’t remove a widget everything works.
The signal handlers look something like this:
g_signal_connect(popover->popover, "show", gfn(
Auto popover = static_cast<UiPopover*>(data);
Auto button = ui_button_new(context.fast_mem, 0, "I am a popup", false, false, false);
gtk_box_append(GTK_BOX(popover->box), button->widget);
printf("open\n");
), popover);
g_signal_connect(popover->popover, "closed", gfn(
Auto popover = static_cast<UiPopover*>(data);
popover->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_popover_set_child(GTK_POPOVER(popover->popover), popover->box);
printf("closed\n");
), popover);
I suppose it’s because popovers track the focused widget to show/hide themselves, so adding/removing widgets at the same time may add confusion.
Consider trying g_signal_connect_after().
You can also connect to the windows notify::focus-widget to watch which widget gets the focus, that may give you some hints.