1

I'm working on an otherwise non-GTK application (actually SDL2), where the right click into the window causes to open a GTK pop-up menu, so as you can see, here, GTK is just used for that purpose (and for some other, like file selection dialogue box, etc, but it's not the scope of my question).

I can happily use gtk_menu_popup(), and it works nicely. The only problem is the following warning during compilation:

warning: ‘gtk_menu_popup’ is deprecated: Use '(gtk_menu_popup_at_widget, gtk_menu_popup_at_pointer, gtk_menu_popup_at_rect)' instead

Which is fair enough, so I want to use gtk_menu_popup_at_pointer(), since this is what I want basically. However this is my problem. That it expects a trigger_event, which I don't have, since no GTK event triggered that, but my own code, which is SDL2 ... According to the documentation I can use NULL as the trigger_event, however if I do this, I get the following messages at stdout, and no popup is shown:

Gtk-WARNING **: 19:10:53.512: no trigger event for menu popup Gtk-CRITICAL **: 19:10:53.512: gtk_menu_popup_at_rect: assertion 'GDK_IS_WINDOW (rect_window)' failed

My question: is it possible to solve my problem (using GTK popup from a non-GTK application) without using deprecated function (gtk_menu_popup - which is actually works, just it's ugly that I use a deprecated feature ...).

The popup menu is created with gtk_menu_new() it has no "parent" or containers, or anything, since it's the only thing I want to use from GTK at this part of my application.

  • Maybe create [GdkEventButton](https://developer.gnome.org/gdk3/3.24/gdk3-Event-Structures.html#GdkEventButton)? I guess `gtk_menu_popup_at_pointer()` uses it's fields to position the menu. – pan-mroku Sep 20 '19 at 10:09
  • Thanks for the comment, however I'm unsure how. That event again - generic problem with GTK - wants to refer a window. I have no window, since it's not a GTK app. I have similar problem with the file selector dialog btw. It seems GTK makes that extra hard to use it, in a non-GTK app just as an "aux lib" ... Now if I try to "fake" an event, and its window member is NULL, I get: Gtk-CRITICAL **: 22:25:40.965: gtk_menu_popup_at_rect: assertion 'GDK_IS_WINDOW (rect_window)' failed – LGB Gábor Lénárt Oct 12 '19 at 20:27
  • Does [creating GdkWindow from XID](https://stackoverflow.com/questions/6850698/how-to-get-gdk-window-from-xid) solve it? – pan-mroku Oct 14 '19 at 09:07
  • Yes it seems, however now I'm afraid, this is too complicated. What if, somebody runs GTK on Windows, or Linux/Wayland etc? Then no XID ... The sad thing that the old and deprecated gtk_menu_popup() simply works everywhere, without any additional code, but gtk_menu_popup_at_pointer() causes major headache, that it's dependent on the current situation how I can "fake" some GdkWindow for GTK, it's not always X11 and XID, etc ... :-O – LGB Gábor Lénárt Oct 14 '19 at 15:33
  • Yes, for multi-platform you will need `ifdef` and using Windows' API. I think the other way round (wrapping SDL in GTK widget) would be easier. – pan-mroku Oct 15 '19 at 08:58

0 Answers0