systray icon: fix icon menu in Unity
For some reason Unity doesn't like the GtkMenu which is built
from the GMenuModel from a .ui file. This patch creates the menu
via code and fixes these issues in the status icon menu in Unity:
- the "Show Ring" checkbox is not consistent when the window is
closed via the 'x'
- the 'Quit' menu item was being rendered with a checkbox
Change-Id: I9fe488a88c881ac795b93e88f4925096a4acf361
Tuleap: #370
diff --git a/src/ring_client.cpp b/src/ring_client.cpp
index 15c5a5d..fb6c3be 100644
--- a/src/ring_client.cpp
+++ b/src/ring_client.cpp
@@ -258,15 +258,23 @@
// init menu
if (!priv->icon_menu) {
- auto builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringiconmenu.ui");
- auto menu_model = G_MENU_MODEL(gtk_builder_get_object(builder, "menu"));
- priv->icon_menu = gtk_menu_new_from_model(menu_model);
- /* enable the menu actions */
- gtk_widget_insert_action_group(priv->icon_menu, "app", G_ACTION_GROUP(client));
- g_object_unref(builder);
- g_object_unref(menu_model);
+ /* for some reason AppIndicator doesn't like the menu being built from a GMenuModel and/or
+ * the GMenuModel being built from an xml resource. So we build the menu in code.
+ */
+ priv->icon_menu = gtk_menu_new();
g_object_ref_sink(priv->icon_menu);
+
+ auto item = gtk_check_menu_item_new_with_label(C_("In the status icon menu, toggle action to show or hide the Ring main window", "Show Ring"));
+ gtk_actionable_set_action_name(GTK_ACTIONABLE(item), "app.show-main-window");
+ gtk_menu_shell_append(GTK_MENU_SHELL(priv->icon_menu), item);
+
+ item = gtk_menu_item_new_with_label(_("Quit"));
+ gtk_actionable_set_action_name(GTK_ACTIONABLE(item), "app.quit");
+ gtk_menu_shell_append(GTK_MENU_SHELL(priv->icon_menu), item);
+
+ gtk_widget_insert_action_group(priv->icon_menu, "app", G_ACTION_GROUP(client));
+ gtk_widget_show_all(priv->icon_menu);
}
#if USE_APPINDICATOR