I changed this:
static GtkActionEntry menu_items[] = {
{ "OpenFile", GTK_STOCK_OPEN, NULL, "<control>O", NULL, G_CALLBACK(file_open) },
...
},
… to this:
static GtkActionEntry menu_items[] = {
{ "OpenFile", GTK_STOCK_OPEN, NULL, gtk_accelerator_name(GDK_o, GDK_CONTROL_MASK), NULL, G_CALLBACK(file_open) },
...
},
… and now I get “error: initializer element is not constant”. What changes do I need to make to get this working?
GtkActionEntry‘s fourth argument is a gchar pointer and gtk_accelerator_name returns that as far as I can see.
menu_items is used in a static function, like this:
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
static GtkWidget *get_menubar_menu(GtkWidget *win) {
GtkActionGroup *action_group = gtk_action_group_new("Menu");
gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
...
}
You can’t do that, the
staticdata needs to be determined at compile-time, butgtk_accelerator_name()probably resides in a shared object that might not even be available when you compile.So, you need to add code to go through the array once at startup, before you actually use it in the call to
gtk_action_group_add_actions(), to pass each string togtk_accelerator_name()as needed.