From 5a40fa084024e174cd1e76781102d1c366a13d0a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 12:51:34 -0500 Subject: Putting in a little code to scale icons. --- src/indicator-messages.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/indicator-messages.c') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index a3f22aa..070b2be 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -194,7 +194,27 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm mi_data->icon = gtk_image_new(); GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); if (pixbuf != NULL) { - gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), pixbuf); + /* If we've got a pixbuf we need to make sure it's of a reasonable + 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); + if (gdk_pixbuf_get_width(pixbuf) > width || + gdk_pixbuf_get_height(pixbuf) > height) { + resized_pixbuf = gdk_pixbuf_scale_simple(pixbuf, + width, + height, + GDK_INTERP_BILINEAR); + } else { + resized_pixbuf = pixbuf; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), resized_pixbuf); + + /* The other pixbuf should be free'd by the dbusmenu. */ + if (resized_pixbuf != pixbuf) { + g_object_unref(resized_pixbuf); + } } 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, 0); -- cgit v1.2.3 From fcda1c20e3ebfa62d3696a493af3ef3ef4716402 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 13:22:08 -0500 Subject: Forgot to scale on icon changing. --- src/indicator-messages.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/indicator-messages.c') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 070b2be..01f2579 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -164,7 +164,29 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, in is already cached, shouldn't be a big deal really. */ GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(mi, INDICATOR_MENUITEM_PROP_ICON); if (pixbuf != NULL) { - gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), pixbuf); + /* If we've got a pixbuf we need to make sure it's of a reasonable + 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); + 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); + resized_pixbuf = gdk_pixbuf_scale_simple(pixbuf, + width, + height, + GDK_INTERP_BILINEAR); + } else { + g_debug("Happy with icon sized %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); + resized_pixbuf = pixbuf; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), resized_pixbuf); + + /* The other pixbuf should be free'd by the dbusmenu. */ + if (resized_pixbuf != pixbuf) { + g_object_unref(resized_pixbuf); + } } } else { g_warning("Indicator Item property '%s' unknown", prop); @@ -201,11 +223,13 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &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); resized_pixbuf = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR); } else { + g_debug("Happy with icon sized %dx%d", gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); resized_pixbuf = pixbuf; } -- cgit v1.2.3 From a8ccb31fbb4a2c7a6bba2b19933ffad754e7f910 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 15:49:37 -0500 Subject: Putting in teh size request a minimum width --- src/indicator-messages.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/indicator-messages.c') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index a3f22aa..e180992 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -241,6 +241,7 @@ new_launcher_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusme GtkWidget * dsc_label = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(dsc_label), 0.05, 0.5); gtk_label_set_ellipsize(GTK_LABEL(dsc_label), PANGO_ELLIPSIZE_END); + gtk_widget_set_size_request(dsc_label, 250, -1); gchar * markup = g_markup_printf_escaped("%s", dbusmenu_menuitem_property_get(newitem, LAUNCHER_MENUITEM_PROP_APP_DESC)); gtk_label_set_markup(GTK_LABEL(dsc_label), markup); g_free(markup); -- cgit v1.2.3 From 3d2040f341e56d9de99fa9a2dd35c1fa4821eafc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Sep 2009 15:58:34 -0500 Subject: Too big --- src/indicator-messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-messages.c') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index e180992..c86389c 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -241,7 +241,7 @@ new_launcher_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusme GtkWidget * dsc_label = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(dsc_label), 0.05, 0.5); gtk_label_set_ellipsize(GTK_LABEL(dsc_label), PANGO_ELLIPSIZE_END); - gtk_widget_set_size_request(dsc_label, 250, -1); + gtk_widget_set_size_request(dsc_label, 200, -1); gchar * markup = g_markup_printf_escaped("%s", dbusmenu_menuitem_property_get(newitem, LAUNCHER_MENUITEM_PROP_APP_DESC)); gtk_label_set_markup(GTK_LABEL(dsc_label), markup); g_free(markup); -- cgit v1.2.3