1

I'm trying to assign an accelerator to a GTK menu item:

group = gtk_accel_group_new();

item = gtk_image_menu_item_new_from_stock(GTK_STOCK_UNDO, group);

gtk_widget_add_accelerator(item, "activate", group, GDK_Z, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

But when I compile I get the following error:

./src/main.c:171:55: error: ‘GDK_Z’ undeclared (first use in this function)
   gtk_widget_add_accelerator(item, "activate", group, GDK_Z, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
                                                       ^

This is the output from pkg-config --cflags gtk+-2.0:

-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2

How can I make the GDK_Z identifier available to my program?

Luke
  • 20,878
  • 35
  • 119
  • 178
  • Do you have development package for GTK+ (`libgtk2.0-dev`) installed correctly? – Michi Oct 03 '18 at 10:07
  • Hmm. Interesting thought. I tried `sudo apt-get remove libgtk2.0-dev --purge` and then a reinstall `sudo apt-get install libgtk2.0-dev`. Same problem.. – Luke Oct 03 '18 at 10:30
  • I am not sure if I have idea about what I am going to say, but does that work if you do `guint key = GDK_z;` or `guint key = GDK_Z;`and then =>> `gtk_widget_add_accelerator(item, "activate", group, key, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); ` ? – Michi Oct 03 '18 at 10:48
  • Thanks for that. I tried both, same error. These are the reference docs for `gtk_widget_add_accelerator`, they speak of `accel_key` to be `GDK keyval of the accelerator` but I can't find any docs for those. I got the `GDK_Z` example from a GTK 2 book that was popular back in the day. But no reference in there to include anything specific. https://developer.gnome.org/gtk2/stable/GtkWidget.html#gtk-widget-add-accelerator – Luke Oct 03 '18 at 10:54
  • 1
    The only thing which I found related to this , [Is This](https://github.com/genesi/gtk2/blob/master/modules/input/imipa.c). – Michi Oct 03 '18 at 10:56
  • 1
    Thank you! And `#include ` it is. If you add it as an answer I will accept it as correct. – Luke Oct 03 '18 at 10:59

1 Answers1

1

You did not included gdkkeysyms.h:

#include <gdk/gdkkeysyms.h>

Which contains GDK_Z needed for your program.

Michi
  • 5,175
  • 7
  • 33
  • 58