I’m trying to use the gtk_menu_popup_at_rect function. Here is a simplified version of the code I’ve written…
// declare a menu and add an item to it
GtkWidget *menu = gtk_menu_new();
GtkWidget *item = gtk_menu_item_new_with_label("foo");
gtk_widget_show(item);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
GdkRectangle rect;
rect.x = 0;
rect.y = 0;
rect.width = 0;
rect.height = 0;
// trigger the popup
gtk_menu_popup_at_rect(
GTK_MENU(menu),
GDK_WINDOW(gtk_widget_get_window(window)),
&rect,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_NORTH_WEST,
0
);
This displays the menu, but there are a few issues.
- The popup is not focused initially. Clicking the popup initially just gives it focus, only after that can you interact with it normally. That isn’t the desired behavior. It seems like there is a procedure that im not aware of. I tried calling gtk_widget_grab_focus first but it had no effect.
- I get these two runtime warnings which i assume are related…
Gtk-WARNING **: 10:53:16.743: no trigger event for menu popup
Gdk-WARNING **: 10:53:16.824: Tried to map a popup with a non-top most parent