ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #03483
lp:~cimi/indicator-messages/update-fixes-to-right-label-and-icon-dimension into lp:indicator-messages
Andrea Cimitan has proposed merging lp:~cimi/indicator-messages/update-fixes-to-right-label-and-icon-dimension into lp:indicator-messages.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
For more details, see:
https://code.launchpad.net/~cimi/indicator-messages/update-fixes-to-right-label-and-icon-dimension/+merge/55377
An updated version of fixes-to-right-label-and-icon-dimension
--
https://code.launchpad.net/~cimi/indicator-messages/update-fixes-to-right-label-and-icon-dimension/+merge/55377
Your team ayatana-commits is subscribed to branch lp:indicator-messages.
=== modified file 'src/dbus-data.h'
--- src/dbus-data.h 2011-01-14 20:19:48 +0000
+++ src/dbus-data.h 2011-03-29 16:38:19 +0000
@@ -8,15 +8,16 @@
#define INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT "/com/canonical/indicator/messages/service"
#define INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE "com.canonical.indicator.messages.service"
-#define APPLICATION_MENUITEM_TYPE "application-item"
-#define APPLICATION_MENUITEM_PROP_NAME "label"
-#define APPLICATION_MENUITEM_PROP_ICON "icon-name"
+#define APPLICATION_MENUITEM_TYPE "application-item"
+#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"
-#define INDICATOR_MENUITEM_PROP_ICON "indicator-icon"
-#define INDICATOR_MENUITEM_PROP_RIGHT "right-side-text"
+#define INDICATOR_MENUITEM_TYPE "indicator-item"
+#define INDICATOR_MENUITEM_PROP_LABEL "indicator-label"
+#define INDICATOR_MENUITEM_PROP_ICON "indicator-icon"
+#define INDICATOR_MENUITEM_PROP_RIGHT_TIME "right-side-time"
+#define INDICATOR_MENUITEM_PROP_RIGHT_COUNTER "right-side-counter"
#define MAX_NUMBER_OF_INDICATORS 7
=== modified file 'src/im-menu-item.c'
--- src/im-menu-item.c 2011-01-14 19:35:21 +0000
+++ src/im-menu-item.c 2011-03-29 16:38:19 +0000
@@ -196,7 +196,7 @@
/* Seconds hasn't been set, so we just want to keep the time
area blank. */
if (priv->seconds == 0) {
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, "");
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT_TIME, "");
return;
}
@@ -235,7 +235,7 @@
}
if (timestring != NULL) {
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, timestring);
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT_TIME, timestring);
g_free(timestring);
}
@@ -349,7 +349,7 @@
}
priv->count = g_strdup_printf("%s", propertydata);
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, priv->count);
+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT_COUNTER, priv->count);
return;
}
=== modified file 'src/indicator-messages.c'
--- src/indicator-messages.c 2011-02-17 18:04:32 +0000
+++ src/indicator-messages.c 2011-03-29 16:38:19 +0000
@@ -45,7 +45,6 @@
#define M_PI 3.1415926535897932384626433832795028841971693993751
-#define RIGHT_LABEL_FONT_SIZE 12
#define RIGHT_LABEL_RADIUS 20
typedef struct _IndicatorMessages IndicatorMessages;
@@ -61,6 +60,12 @@
IndicatorServiceManager * service;
};
+typedef enum
+{
+ INDICATOR_MENUITEM_RIGHT_TIME,
+ INDICATOR_MENUITEM_RIGHT_COUNTER
+} IndicatorRightLabelType;
+
GType indicator_messages_get_type (void);
/* Indicator Module Config */
@@ -75,6 +80,7 @@
static GDBusInterfaceInfo * bus_interface_info = NULL;
static const gchar * accessible_desc = NULL;
static IndicatorObject * indicator = NULL;
+static GtkIconSize design_team_size;
/* Prototypes */
static void indicator_messages_class_init (IndicatorMessagesClass *klass);
@@ -144,6 +150,8 @@
}
}
+ design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
+
return;
}
@@ -379,7 +387,7 @@
if (!g_strcmp0(prop, APPLICATION_MENUITEM_PROP_ICON)) {
/* Set the main icon */
if (GTK_IS_IMAGE(user_data)) {
- gtk_image_set_from_icon_name(GTK_IMAGE(user_data), g_variant_get_string(value, NULL), GTK_ICON_SIZE_MENU);
+ gtk_image_set_from_icon_name(GTK_IMAGE(user_data), g_variant_get_string(value, NULL), design_team_size);
}
}
@@ -419,7 +427,7 @@
/* 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;;
+ return FALSE;
/* get style */
style = gtk_widget_get_style (widget);
@@ -467,19 +475,103 @@
cairo_arc (cr, x+radius, y+radius, radius, M_PI, M_PI*1.5);
}
+static gint
+get_current_font_size (GtkWidget *widget)
+{
+ gchar *font_name;
+ gint font_size;
+ GtkSettings *settings;
+ PangoFontDescription *font_description;
+
+ if (!GTK_IS_WIDGET (widget))
+ settings = gtk_settings_get_default();
+ else
+ settings = gtk_widget_get_settings (widget);
+
+ g_object_get (settings, "gtk-font-name", &font_name, NULL);
+
+ font_description = pango_font_description_from_string (font_name);
+ font_size = pango_font_description_get_size (font_description);
+
+ pango_font_description_free (font_description);
+ g_free (font_name);
+
+ return font_size / PANGO_SCALE;
+}
+
+/* Draws a subtle text. */
+static gboolean
+time_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ GtkAllocation allocation;
+ GtkStyle *style;
+ cairo_t *cr;
+ double x, y, w, h;
+ PangoLayout * layout;
+ gint font_size;
+ gint layout_width;
+
+ if (!GTK_IS_WIDGET (widget)) return FALSE;
+
+ font_size = get_current_font_size(widget);
+
+ /* get style */
+ style = gtk_widget_get_style (widget);
+
+ /* set arrow position / dimensions */
+ gtk_widget_get_allocation (widget, &allocation);
+ w = allocation.width;
+ h = allocation.height;
+ x = allocation.x;
+ y = allocation.y;
+
+ layout = gtk_label_get_layout (GTK_LABEL(widget));
+
+ pango_layout_get_pixel_size(layout, &layout_width, NULL);
+
+ /* don't draw if the layout has no text */
+ if (layout_width < 1) return FALSE;
+
+ /* reduce the size accordingly to layout_width */
+ x = x + w - layout_width;
+ w = layout_width;
+
+ /* initialize cairo drawing area */
+ cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));
+
+ /* set line width */
+ cairo_set_line_width (cr, 1.0);
+
+ cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
+
+ cairo_move_to (cr, x, (int)(y + h/2.0 - font_size + font_size/4));
+ pango_cairo_show_layout (cr, layout);
+ cairo_stroke (cr);
+
+ /* remember to destroy cairo context to avoid leaks */
+ cairo_destroy (cr);
+
+ return TRUE;
+}
+
/* Draws a rounded rectangle with text inside. */
static gboolean
-numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+counter_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GtkAllocation allocation;
GtkStyle *style;
cairo_t *cr;
double x, y, w, h;
PangoLayout * layout;
- gint font_size = RIGHT_LABEL_FONT_SIZE;
+ gint font_size;
+ gint layout_width;
if (!GTK_IS_WIDGET (widget)) return FALSE;
+ font_size = get_current_font_size(widget);
+
/* get style */
style = gtk_widget_get_style (widget);
@@ -492,28 +584,30 @@
layout = gtk_label_get_layout (GTK_LABEL(widget));
- /* This does not work, don't ask me why but font_size is 0.
- * I wanted to use a dynamic font size to adjust the padding on left/right edges
- * of the rounded rectangle. Andrea Cimitan */
- /* const PangoFontDescription * font_description = pango_layout_get_font_description (layout);
- font_size = pango_font_description_get_size (font_description); */
+ pango_layout_get_pixel_size(layout, &layout_width, NULL);
+
+ /* don't draw if the layout has no text */
+ if (layout_width < 1) return FALSE;
+
+ /* reduce the size accordingly to layout_width */
+ x = x + w - layout_width;
+ w = layout_width;
/* initialize cairo drawing area */
cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));
- /* set line width */
+ /* set line width */
cairo_set_line_width (cr, 1.0);
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- /* cairo drawing code */
- custom_cairo_rounded_rectangle (cr, x - font_size/2.0, y, w + font_size, h);
+ custom_cairo_rounded_rectangle (cr, x - font_size/2.0, (int)(y + h/2.0 - font_size/2.0 - 2), w + font_size, font_size + 5);
cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
- style->fg[gtk_widget_get_state(widget)].green/65535.0,
- style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
- cairo_move_to (cr, x, y);
+ cairo_move_to (cr, x, (int)(y + h/2.0 - font_size + font_size/4));
pango_cairo_layout_path (cr, layout);
cairo_fill (cr);
@@ -523,6 +617,95 @@
return TRUE;
}
+#if 0
+/* Draws a rounded rectangle with text inside or subtle text, with heuristic. */
+static gboolean
+numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ GtkAllocation allocation;
+ GtkStyle *style;
+ cairo_t *cr;
+ double x, y, w, h;
+ PangoLayout * layout;
+ gint font_size;
+ gint layout_width;
+ const gchar *text;
+ const gchar *c;
+ gboolean only_digits = TRUE;
+
+ if (!GTK_IS_WIDGET (widget)) return FALSE;
+
+ font_size = get_current_font_size(widget);
+
+ /* get style */
+ style = gtk_widget_get_style (widget);
+
+ /* set arrow position / dimensions */
+ gtk_widget_get_allocation (widget, &allocation);
+ w = allocation.width;
+ h = allocation.height;
+ x = allocation.x;
+ y = allocation.y;
+
+ layout = gtk_label_get_layout (GTK_LABEL(widget));
+
+ pango_layout_get_pixel_size(layout, &layout_width, NULL);
+
+ /* don't draw if the layout has no text */
+ if (layout_width < 1) return FALSE;
+
+ /* reduce the size accordingly to layout_width */
+ x = x + w - layout_width;
+ w = layout_width;
+
+ text = pango_layout_get_text (layout);
+ for (c = text; *c != '\0'; c++)
+ {
+ if (!g_ascii_isdigit(*c))
+ {
+ only_digits = FALSE;
+ break;
+ }
+ }
+
+ /* initialize cairo drawing area */
+ cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));
+
+ /* set line width */
+ cairo_set_line_width (cr, 1.0);
+
+ if (only_digits)
+ {
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+
+ custom_cairo_rounded_rectangle (cr, x - font_size/2.0, (int)(y + h/2.0 - font_size/2.0 - 2), w + font_size, font_size + 5);
+
+ cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
+
+ cairo_move_to (cr, x, (int)(y + h/2.0 - font_size + font_size/4));
+ pango_cairo_layout_path (cr, layout);
+ cairo_fill (cr);
+ }
+ else
+ {
+ cairo_set_source_rgba (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
+ style->fg[gtk_widget_get_state(widget)].green/65535.0,
+ style->fg[gtk_widget_get_state(widget)].blue/65535.0, 0.5);
+
+ cairo_move_to (cr, x, (int)(y + h/2.0 - font_size + font_size/4));
+ pango_cairo_show_layout (cr, layout);
+ cairo_stroke (cr);
+ }
+
+ /* remember to destroy cairo context to avoid leaks */
+ cairo_destroy (cr);
+
+ return TRUE;
+}
+#endif
+
/* Builds a menu item representing a running application in the
messaging menu */
static gboolean
@@ -540,14 +723,13 @@
/* Set the minimum size, we always want it to take space */
gint width, height;
- 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
- + 5 /* ref triangle is 5x9 pixels */
- + 2 /* padding */,
- height);
- gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5);
+ gtk_icon_size_lookup(design_team_size, &width, &height);
+
+ GtkWidget * icon = gtk_image_new_from_icon_name(dbusmenu_menuitem_property_get(newitem, APPLICATION_MENUITEM_PROP_ICON), design_team_size);
+
+ gtk_widget_set_size_request(icon, width, height);
+ /* Not needed if you remove the padding, I guess
+ gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0); */
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), icon);
gtk_widget_show(icon);
@@ -587,7 +769,10 @@
if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_LABEL)) {
/* Set the main label */
gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL));
- } else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_RIGHT)) {
+ } else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_RIGHT_TIME)) {
+ /* Set the right label */
+ gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL));
+ } else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_RIGHT_COUNTER)) {
/* Set the right label */
gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL));
} else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_ICON)) {
@@ -600,7 +785,7 @@
size to fit in the menu. If not, rescale it. */
GdkPixbuf * resized_pixbuf;
gint width, height;
- gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
+ gtk_icon_size_lookup(design_team_size, &width, &height);
if (gdk_pixbuf_get_width(pixbuf) > width ||
gdk_pixbuf_get_height(pixbuf) > height) {
g_debug("Resizing icon from %dx%d to %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), width, height);
@@ -645,7 +830,8 @@
GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
gint padding = 4;
- gint font_size = RIGHT_LABEL_FONT_SIZE;
+ gint font_size;
+
gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL);
GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
@@ -655,7 +841,7 @@
/* Set the minimum size, we always want it to take space */
gint width, height;
- gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
+ gtk_icon_size_lookup(design_team_size, &width, &height);
gtk_widget_set_size_request(mi_data->icon, width, height);
GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON);
@@ -697,14 +883,38 @@
/* Usually either the time or the count on the individual
item. */
- mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT));
+ IndicatorRightLabelType label_type;
+
+ if (dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT_COUNTER))
+ {
+ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT_COUNTER));
+ label_type = INDICATOR_MENUITEM_RIGHT_COUNTER;
+ }
+ else
+ {
+ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT_TIME));
+ label_type = INDICATOR_MENUITEM_RIGHT_TIME;
+ }
gtk_size_group_add_widget(indicator_right_group, mi_data->right);
+
+ font_size = get_current_font_size(GTK_WIDGET(mi_data->right));
+
/* install extra decoration overlay */
- g_signal_connect (G_OBJECT (mi_data->right), "expose_event",
- G_CALLBACK (numbers_draw_cb), NULL);
+ switch (label_type)
+ {
+ default:
+ case INDICATOR_MENUITEM_RIGHT_TIME:
+ g_signal_connect (G_OBJECT (mi_data->right), "expose_event",
+ G_CALLBACK (time_draw_cb), NULL);
+ break;
+ case INDICATOR_MENUITEM_RIGHT_COUNTER:
+ g_signal_connect (G_OBJECT (mi_data->right), "expose_event",
+ G_CALLBACK (counter_draw_cb), NULL);
+ break;
+ }
gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5);
- gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size/2.0);
+ gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size / 2.0);
gtk_widget_show(mi_data->right);
gtk_container_add(GTK_CONTAINER(gmi), hbox);
Follow ups