← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~dbarth/indicator-messages/triangle-n-icon into lp:indicator-messages

 

David Barth has proposed merging lp:~dbarth/indicator-messages/triangle-n-icon into lp:indicator-messages.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


Adjusts the icon position of application menuitems, also makes sure launcher menu items are seen as app-menu-items too.
-- 
https://code.launchpad.net/~dbarth/indicator-messages/triangle-n-icon/+merge/33828
Your team ayatana-commits is subscribed to branch lp:indicator-messages.
=== modified file 'src/app-menu-item.c'
--- src/app-menu-item.c	2010-04-16 15:12:11 +0000
+++ src/app-menu-item.c	2010-08-26 19:41:23 +0000
@@ -328,6 +328,7 @@
 	priv->desktop = g_strdup(value);
 
 	dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
+	dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), APPLICATION_MENUITEM_PROP_RUNNING, TRUE);
 
 	update_label(self);
 
@@ -355,7 +356,6 @@
 	AppMenuItem * self = APP_MENU_ITEM(data);
 	AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self);
 	DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(child);
-	dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(mip), DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK);
 
 	priv->shortcuts = g_list_insert(priv->shortcuts, mip, position);
 
@@ -456,7 +456,6 @@
 			g_debug("\tProcessing %d children", g_list_length(children));
 			while (children != NULL) {
 				DbusmenuMenuitemProxy * mip = dbusmenu_menuitem_proxy_new(DBUSMENU_MENUITEM(children->data));
-				dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(mip), DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK);
 				priv->shortcuts = g_list_append(priv->shortcuts, mip);
 				g_signal_emit(G_OBJECT(self), signals[SHORTCUT_ADDED], 0, mip, TRUE);
 				children = g_list_next(children);

=== modified file 'src/dbus-data.h'
--- src/dbus-data.h	2010-03-23 20:45:35 +0000
+++ src/dbus-data.h	2010-08-26 19:41:23 +0000
@@ -9,8 +9,9 @@
 #define INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE  "org.ayatana.indicator.messages.service"
 
 #define APPLICATION_MENUITEM_TYPE        "application-item"
-#define APPLICATION_MENUITEM_PROP_NAME   "app-name"
-#define APPLICATION_MENUITEM_PROP_ICON   "app-icon"
+#define APPLICATION_MENUITEM_PROP_NAME   "label"
+#define APPLICATION_MENUITEM_PROP_ICON   "icon-name"
+#define APPLICATION_MENUITEM_PROP_RUNNING "app-running"
 
 #define INDICATOR_MENUITEM_TYPE          "indicator-item"
 #define INDICATOR_MENUITEM_PROP_LABEL    "indicator-label"

=== modified file 'src/indicator-messages.c'
--- src/indicator-messages.c	2010-07-29 16:09:26 +0000
+++ src/indicator-messages.c	2010-08-26 19:41:23 +0000
@@ -287,6 +287,11 @@
 		}
 	}
 
+	if (!g_strcmp0(prop, APPLICATION_MENUITEM_PROP_RUNNING)) {
+		/* TODO: should hide/show the triangle live if the menu was open.
+		   In practice, this is rarely needed. */
+	}
+
 	return;
 }
 
@@ -299,13 +304,18 @@
 	int x, y, arrow_width, arrow_height;
 
 	if (!GTK_IS_WIDGET (widget)) return FALSE;
+	if (!DBUSMENU_IS_MENUITEM (data)) return FALSE;
+
+	/* render the triangle indicator only if the application is running */
+	if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data), APPLICATION_MENUITEM_PROP_RUNNING))
+		return FALSE;;
 
 	/* get style */
 	style = gtk_widget_get_style (widget);
 
 	/* set arrow position / dimensions */
-	arrow_width = (int) ((double)widget->allocation.height * 0.25f);
-	arrow_height = (int) ((double)widget->allocation.height * 0.50f);
+	arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
+	arrow_height = 9;
 	x = widget->allocation.x;
 	y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0;
 
@@ -326,7 +336,7 @@
 	cairo_fill (cr);
 
 	/* remember to destroy cairo context to avoid leaks */
-        cairo_destroy (cr);
+	cairo_destroy (cr);
 
 	return FALSE;
 }
@@ -404,7 +414,10 @@
 static gboolean
 new_application_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
 {
+	g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, APPLICATION_MENUITEM_PROP_NAME));
+
 	GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_image_menu_item_new());
+	gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(gmi), TRUE);
 
 	gint padding = 4;
 	gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL);
@@ -416,9 +429,12 @@
 	gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
 
 	GtkWidget * icon = gtk_image_new_from_icon_name(dbusmenu_menuitem_property_get(newitem, APPLICATION_MENUITEM_PROP_ICON), GTK_ICON_SIZE_MENU);
-	gtk_widget_set_size_request(icon, width, height);
-	gtk_misc_set_alignment(GTK_MISC(icon), 0.0, 0.5);
-	gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, padding);
+	gtk_widget_set_size_request(icon, width
+								+ 5 /* ref triangle is 5x9 pixels */
+								+ 2 /* padding */,
+								height);
+	gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5);
+	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), icon);
 	gtk_widget_show(icon);
 
 	/* Application name in a label */
@@ -489,6 +505,10 @@
 			if (resized_pixbuf != pixbuf) {
 				g_object_unref(resized_pixbuf);
 			}
+
+			gtk_widget_show(mi_data->icon);
+		} else {
+			gtk_widget_hide(mi_data->icon);
 		}
 	}
 
@@ -550,7 +570,10 @@
 	}
 	gtk_misc_set_alignment(GTK_MISC(mi_data->icon), 0.0, 0.5);
 	gtk_box_pack_start(GTK_BOX(hbox), mi_data->icon, FALSE, FALSE, padding);
-	gtk_widget_show(mi_data->icon);
+
+	if (pixbuf != NULL) {
+		gtk_widget_show(mi_data->icon);
+	}
 
 	/* Label, probably a username, chat room or mailbox name */
 	mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_LABEL));

=== modified file 'src/launcher-menu-item.c'
--- src/launcher-menu-item.c	2010-03-25 15:28:25 +0000
+++ src/launcher-menu-item.c	2010-08-26 19:41:23 +0000
@@ -197,9 +197,9 @@
 		gint i;
 		for (i = 0; nicks[i] != NULL; i++) {
 			DbusmenuMenuitem * mi = dbusmenu_menuitem_new();
+			dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_TYPE, APPLICATION_MENUITEM_TYPE);
 			g_object_set_data(G_OBJECT(mi), NICK_DATA, (gpointer)nicks[i]);
 
-			dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_ICON_NAME, DBUSMENU_MENUITEM_ICON_NAME_BLANK);
 			dbusmenu_menuitem_property_set(mi, DBUSMENU_MENUITEM_PROP_LABEL, indicator_desktop_shortcuts_nick_get_name(priv->ids, nicks[i]));
 			g_signal_connect(G_OBJECT(mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(nick_activate_cb), self);
 

=== modified file 'src/messages-service.c'
--- src/messages-service.c	2010-04-28 10:33:57 +0000
+++ src/messages-service.c	2010-08-26 19:41:23 +0000
@@ -1346,6 +1346,7 @@
 		launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort);
 
 		/* Add it to the menu */
+		dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(ll->menuitem), DBUSMENU_MENUITEM_PROP_TYPE, APPLICATION_MENUITEM_TYPE);
 		dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem));
 		GList * shortcuts = launcher_menu_item_get_items(ll->menuitem);
 		while (shortcuts != NULL) {


Follow ups