--- ./src/xfdesktop-app-menu-item.c.orig 2013-09-16 07:17:42.000000000 +0000 +++ ./src/xfdesktop-app-menu-item.c 2013-11-02 20:46:16.000000000 +0000 @@ -27,6 +27,9 @@ #include #endif +#include + +#include #include #include @@ -174,6 +177,11 @@ GtkIconTheme *icon_theme; gchar *p, *name = NULL; gchar *filename; + const gchar *content_type; + gint xpm_w, xpm_h, ratio_w, ratio_h; + GFile *file; + GFileInfo *info; + GdkPixbuf *pixbuf_tmp; icon_name = garcon_menu_item_get_icon_name(app_menu_item->item); icon_theme = gtk_icon_theme_get_default(); @@ -186,7 +194,38 @@ image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_MENU); else { if (g_path_is_absolute(icon_name)) { - pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_name, w, h, TRUE, NULL); + /* XPM image */ + file = g_file_new_for_path(icon_name); + info = g_file_query_info(file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); + content_type = g_file_info_get_content_type(info); + if (g_content_type_is_a(content_type, "image/x-xpixmap")) { + pixbuf = gdk_pixbuf_new_from_file(icon_name, NULL); + + if (G_LIKELY(pixbuf)) { + xpm_w = gdk_pixbuf_get_width(pixbuf); + xpm_h = gdk_pixbuf_get_height(pixbuf); + + if (xpm_w > 22 || xpm_h > 22) { + /* Calculate new dimensions */ + ratio_w = xpm_w / 22; + ratio_h = xpm_h / 22; + + w = rint((gdouble) xpm_w / (gdouble) ratio_h); + h = rint((gdouble) xpm_h / (gdouble) ratio_w); + + pixbuf_tmp = gdk_pixbuf_scale_simple(pixbuf, + w, h, + GDK_INTERP_BILINEAR); + g_object_unref(G_OBJECT(pixbuf)); + pixbuf = pixbuf_tmp; + } + } + } + else + pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_name, w, h, TRUE, NULL); } else { /* try to lookup names like application.png in the theme */ p = strrchr(icon_name, '.'); @@ -205,7 +244,39 @@ } if(name) { - pixbuf = gdk_pixbuf_new_from_file_at_scale(name, w, h, TRUE, NULL); + /* XPM image */ + file = g_file_new_for_path(name); + info = g_file_query_info(file, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, + NULL, NULL); + content_type = g_file_info_get_content_type(info); + if (g_content_type_is_a(content_type, "image/x-xpixmap")) { + pixbuf = gdk_pixbuf_new_from_file(name, NULL); + + if (G_LIKELY(pixbuf)) { + xpm_w = gdk_pixbuf_get_width(pixbuf); + xpm_h = gdk_pixbuf_get_height(pixbuf); + + if (xpm_w > 22 || xpm_h > 22) { + /* Calculate new dimensions */ + ratio_w = xpm_w / 22; + ratio_h = xpm_h / 22; + + w = rint((gdouble) xpm_w / (gdouble) ratio_h); + h = rint((gdouble) xpm_h / (gdouble) ratio_w); + + pixbuf_tmp = gdk_pixbuf_scale_simple(pixbuf, + w, h, + GDK_INTERP_BILINEAR); + + g_object_unref(G_OBJECT(pixbuf)); + pixbuf = pixbuf_tmp; + } + } + } + else + pixbuf = gdk_pixbuf_new_from_file_at_scale(name, w, h, TRUE, NULL); g_free(name); } }