ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #02470
lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
David Barth has proposed merging lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages.
Requested reviews:
Indicator Applet Developers (indicator-applet-developers)
Fixes an icon size issue inside the menu
--
https://code.launchpad.net/~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension/+merge/37272
Your team ayatana-commits is subscribed to branch lp:indicator-messages.
=== modified file 'src/indicator-messages.c'
--- src/indicator-messages.c 2010-09-03 18:13:16 +0000
+++ src/indicator-messages.c 2010-10-01 15:05:58 +0000
@@ -46,7 +46,6 @@
#define M_PI 3.1415926535897932384626433832795028841971693993751
-#define RIGHT_LABEL_FONT_SIZE 12
#define RIGHT_LABEL_RADIUS 20
typedef struct _IndicatorMessages IndicatorMessages;
@@ -71,6 +70,7 @@
static GtkWidget * main_image = NULL;
static DBusGProxy * icon_proxy = NULL;
static GtkSizeGroup * indicator_right_group = NULL;
+static GtkIconSize design_team_size;
/* Prototypes */
static void indicator_messages_class_init (IndicatorMessagesClass *klass);
@@ -99,6 +99,8 @@
io_class->get_image = get_icon;
io_class->get_menu = get_menu;
+ design_team_size = gtk_icon_size_register("design-team-size", 22, 22);
+
return;
}
@@ -269,7 +271,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_value_get_string(value), GTK_ICON_SIZE_MENU);
+ gtk_image_set_from_icon_name(GTK_IMAGE(user_data), g_value_get_string(value), design_team_size);
}
}
@@ -355,6 +357,29 @@
cairo_arc (cr, x+radius, y+radius, radius, M_PI, M_PI*1.5);
}
+static gchar *
+get_current_font_name ()
+{
+ GtkSettings *settings = gtk_settings_get_default();
+ gchar *font_name;
+
+ g_object_get (settings, "gtk-font-name", &font_name, NULL);
+
+ return font_name;
+}
+
+static gint
+get_current_font_size (gchar *font_name)
+{
+ gint font_size;
+ PangoFontDescription *font_description;
+
+ font_description = pango_font_description_from_string (font_name);
+ font_size = pango_font_description_get_size (font_description);
+
+ return font_size / PANGO_SCALE;
+}
+
/* Draws a rounded rectangle with text inside. */
static gboolean
numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
@@ -363,10 +388,14 @@
cairo_t *cr;
double x, y, w, h;
PangoLayout * layout;
- gint font_size = RIGHT_LABEL_FONT_SIZE;
+ gint font_size;
+ char *font_name;
if (!GTK_IS_WIDGET (widget)) return FALSE;
+ font_name = get_current_font_name();
+ font_size = get_current_font_size(font_name);
+
/* get style */
style = gtk_widget_get_style (widget);
@@ -378,12 +407,6 @@
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); */
-
/* initialize cairo drawing area */
cr = (cairo_t*) gdk_cairo_create (widget->window);
@@ -393,13 +416,13 @@
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 - (double)font_size / 2.0, y + 1, w + font_size, h - 2);
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, 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);
@@ -426,14 +449,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);
@@ -486,7 +508,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);
@@ -531,7 +553,12 @@
GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
gint padding = 4;
- gint font_size = RIGHT_LABEL_FONT_SIZE;
+ gint font_size;
+ char *font_name;
+
+ font_name = get_current_font_name();
+ font_size = get_current_font_size(font_name);
+
gtk_widget_style_get(GTK_WIDGET(gmi), "horizontal-padding", &padding, NULL);
GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
@@ -541,7 +568,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);
@@ -590,7 +617,7 @@
G_CALLBACK (numbers_draw_cb), NULL);
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
-
lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Ted Gould, 2011-03-02
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Ted Gould, 2011-01-04
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Andrea Cimitan, 2010-10-20
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Ted Gould, 2010-10-08
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Andrea Cimitan, 2010-10-08
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: David Barth, 2010-10-08
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Andrea Cimitan, 2010-10-08
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Andrea Cimitan, 2010-10-08
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Ted Gould, 2010-10-05
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: David Barth, 2010-10-05
-
Re: lp:~cimi/indicator-messages/fixes-to-right-label-and-icon-dimension into lp:indicator-messages
From: Andrea Cimitan, 2010-10-05