I am trying to build a simple indicator in C. This is my code:
void make_indicator(){
//Making the indicator
appindicator = app_indicator_new("My Indicator", "/home/alex/Qt/normal_tray_icon/a.png", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
//the construction of the main menu
GtkWidget* indicatormenu = gtk_menu_new();
//adding a submenu
GtkWidget* submenu1 = gtk_menu_item_new_with_label("SubMenu1");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenu1), indicatormenu);
/* HERE */
//here comes the error! Adding an option to the submenu
GtkWidget* submenu1_option;
submenu1_option = gtk_menu_item_new_with_label("Submenu option!");
gtk_menu_shell_append(GTK_MENU_SHELL(submenu1), submenu1_option);
//adding an option to the main menu and connecting it to a slot
GtkWidget* showapp_option;
showapp_option = gtk_menu_item_new_with_label("Show App!");
g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app), this);
gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), showapp_option);
//showing the indicator
gtk_widget_show_all(indicatormenu);
app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_attention_icon(appindicator, "dialog-warning");
app_indicator_set_menu(appindicator, GTK_MENU (indicatormenu));
}
I fail to add an action to a submenu. I add the submenu as a simple menu item, thus I cannot append to it actions, or can I?
I don't get error messages on compilation, but on run time I get:
(normal_tray_icon:9203): GLib-GObject-WARNING **: invalid cast from `GtkMenuItem' to `GtkMenuShell'
(normal_tray_icon:9203): Gtk-CRITICAL **: IA__gtk_menu_shell_insert: assertion `GTK_IS_MENU_SHELL (menu_shell)' failed
which I can understand but I don't know how to solve.
Thanks for any answers.
Best Answer
You created only item for submenu, not submenu. This can be done in this way: