gtkglibvalavapi

Missing gtk_menu_popup_at_pointer()


I am writing a Gtk program in Vala that uses a Gtk.Menu.
I need to use Gtk.Menu.popup_at_pointer() to display a menu when the right mouse button is clicked.

When compiling (with --pkg gtk+-3.0), GCC gives me an error: warning: implicit declaration of function ‘gtk_menu_popup_at_pointer’ [-Wimplicit-function-declaration]

The method exists in /usr/share/vala-0.34/vapi/gtk+-3.0.vapi, but is missing in /usr/include/gtk-3.0/gtk/gtkmenu.h.

Here are the versions of the relevant packages on my system:

$ dpkg -s libgtk-3-dev | grep '^Version:'       
Version: 3.18.9-1ubuntu3.1
$ dpkg -s valac | grep '^Version:'
Version: 0.34.4-0ubuntu1~16.04~valateam1
$ dpkg -s libglib2.0-0 | grep '^Version:'
Version: 2.48.2-0elementary0.4.1

What should I do to be able to use this method?


Solution

  • Your version of GTK+ is too old.

    If you look at the GTK+ docs for the function, you can see it was introduced in GTK+ 3.22: https://developer.gnome.org/gtk3/stable/GtkMenu.html#gtk-menu-popup-at-pointer, whereas you only have 3.18 installed.

    Note also that the method is also declared as unstable, meaning that in the future it might change in a way that breaks your app, and hence you're probably better off finding an alternative solution for now anyway.