[Xfce4-commits] <xfdesktop:master> Fill in the icon area better
Eric Koegel
noreply at xfce.org
Sun Sep 1 16:20:04 CEST 2013
Updating branch refs/heads/master
to 2cdfde11b827b97576347c2eacb043780abc9415 (commit)
from bc48d533bd0dbaaad8d865bd6f26bc9c8f47e042 (commit)
commit 2cdfde11b827b97576347c2eacb043780abc9415
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Mon Aug 12 16:26:58 2013 +0300
Fill in the icon area better
It bypasses the thumbnailer for svg icons so they look better.
common/xfdesktop-common.h | 3 +--
src/xfdesktop-file-utils.c | 50 ++++++++++++++++++++++++-------------
src/xfdesktop-file-utils.h | 3 ++-
src/xfdesktop-icon-view.c | 10 +++++---
src/xfdesktop-icon.c | 4 +--
src/xfdesktop-icon.h | 5 ++--
src/xfdesktop-regular-file-icon.c | 31 ++++++++++++++++-------
src/xfdesktop-special-file-icon.c | 13 +++++-----
src/xfdesktop-volume-icon.c | 12 ++++-----
src/xfdesktop-window-icon.c | 23 +++++++++--------
10 files changed, 93 insertions(+), 61 deletions(-)
diff --git a/common/xfdesktop-common.h b/common/xfdesktop-common.h
index cda8f75..3b496fc 100644
--- a/common/xfdesktop-common.h
+++ b/common/xfdesktop-common.h
@@ -36,8 +36,7 @@
#define DEFAULT_ICON_FONT_SIZE 12
#define DEFAULT_ICON_SIZE 32
#define ITHEME_FLAGS (GTK_ICON_LOOKUP_USE_BUILTIN \
- | GTK_ICON_LOOKUP_GENERIC_FALLBACK \
- | GTK_ICON_LOOKUP_FORCE_SIZE)
+ | GTK_ICON_LOOKUP_GENERIC_FALLBACK)
#define LIST_TEXT "# xfce backdrop list"
#define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d"
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 1a29b69..ba0e753 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -491,12 +491,16 @@ xfdesktop_file_utils_get_fallback_icon(gint size)
GdkPixbuf *
xfdesktop_file_utils_get_icon(GIcon *icon,
- gint size,
+ gint width,
+ gint height,
guint opacity)
{
GtkIconTheme *itheme = gtk_icon_theme_get_default();
GdkPixbuf *pix_theme = NULL, *pix = NULL;
GIcon *base_icon = NULL;
+ gint size = MIN(width, height);
+
+ g_return_val_if_fail(width > 0 && height > 0 && icon != NULL, NULL);
/* Extract the base icon if available */
if(G_IS_EMBLEMED_ICON(icon))
@@ -504,26 +508,36 @@ xfdesktop_file_utils_get_icon(GIcon *icon,
else
base_icon = icon;
- if(!pix_theme && base_icon) {
- if(G_IS_THEMED_ICON(base_icon) || G_IS_FILE_ICON(base_icon)) {
- GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(itheme,
- base_icon, size,
- ITHEME_FLAGS);
- if(icon_info) {
- pix_theme = gtk_icon_info_load_icon(icon_info, NULL);
- gtk_icon_info_free(icon_info);
- }
- } else if(G_IS_LOADABLE_ICON(base_icon)) {
- GInputStream *stream = g_loadable_icon_load(G_LOADABLE_ICON(base_icon),
- size, NULL, NULL, NULL);
- if(stream) {
- pix = gdk_pixbuf_new_from_stream(stream, NULL, NULL);
- g_object_unref(stream);
- }
+ if(!base_icon)
+ return NULL;
+
+ if(G_IS_THEMED_ICON(base_icon)) {
+ GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(itheme,
+ base_icon, size,
+ ITHEME_FLAGS);
+ if(icon_info) {
+ pix_theme = gtk_icon_info_load_icon(icon_info, NULL);
+ gtk_icon_info_free(icon_info);
+ }
+ } else if(G_IS_LOADABLE_ICON(base_icon)) {
+ GInputStream *stream = g_loadable_icon_load(G_LOADABLE_ICON(base_icon),
+ size, NULL, NULL, NULL);
+ if(stream) {
+ pix = gdk_pixbuf_new_from_stream_at_scale(stream, width, height, TRUE, NULL, NULL);
+ g_object_unref(stream);
}
+ } else if(G_IS_FILE_ICON(base_icon)) {
+ GFile *file = g_file_icon_get_file(G_FILE_ICON(icon));
+ gchar *path = g_file_get_path(file);
+
+ pix = gdk_pixbuf_new_from_file_at_size(path, width, height, NULL);
+
+ g_free(path);
+ g_object_unref(file);
}
- if(G_LIKELY(pix_theme)) {
+
+ if(pix_theme) {
/* we can't edit thsese icons */
pix = gdk_pixbuf_copy(pix_theme);
g_object_unref(G_OBJECT(pix_theme));
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index 3a80e0c..1975ae5 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -51,7 +51,8 @@ void xfdesktop_file_utils_file_list_free(GList *file_list);
GdkPixbuf *xfdesktop_file_utils_get_fallback_icon(gint size);
GdkPixbuf *xfdesktop_file_utils_get_icon(GIcon *icon,
- gint size,
+ gint width,
+ gint height,
guint opacity);
void xfdesktop_file_utils_set_window_cursor(GtkWindow *window,
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index a04b83e..48c5aab 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -57,6 +57,7 @@
#define ICON_SIZE (icon_view->priv->icon_size)
#define TEXT_WIDTH ((icon_view->priv->cell_text_width_proportion) * ICON_SIZE)
+#define ICON_WIDTH (TEXT_WIDTH)
#define CELL_PADDING (icon_view->priv->cell_padding)
#define CELL_SIZE (TEXT_WIDTH + CELL_PADDING * 2)
#define SPACING (icon_view->priv->cell_spacing)
@@ -1064,6 +1065,7 @@ xfdesktop_icon_view_show_tooltip(GtkWidget *widget,
if(icon_view->priv->tooltip_size > 0) {
gtk_tooltip_set_icon(tooltip,
xfdesktop_icon_peek_pixbuf(icon_view->priv->item_under_pointer,
+ icon_view->priv->tooltip_size * 1.5f,
icon_view->priv->tooltip_size));
}
@@ -1268,7 +1270,7 @@ xfdesktop_icon_view_drag_begin(GtkWidget *widget,
if(xfdesktop_icon_get_extents(icon, NULL, NULL, &extents)) {
GdkPixbuf *pix;
- pix = xfdesktop_icon_peek_pixbuf(icon, ICON_SIZE);
+ pix = xfdesktop_icon_peek_pixbuf(icon, ICON_WIDTH, ICON_SIZE);
if(pix)
gtk_drag_set_icon_pixbuf(context, pix, 0, 0);
}
@@ -2677,7 +2679,7 @@ xfdesktop_icon_view_invalidate_icon_pixbuf(XfdesktopIconView *icon_view,
{
GdkPixbuf *pix;
- pix = xfdesktop_icon_peek_pixbuf(icon, ICON_SIZE);
+ pix = xfdesktop_icon_peek_pixbuf(icon, ICON_WIDTH, ICON_SIZE);
if(pix) {
GdkRectangle rect = { 0, };
@@ -2782,7 +2784,7 @@ xfdesktop_icon_view_calculate_icon_pixbuf_area(XfdesktopIconView *icon_view,
pixbuf_area->x = 0;
pixbuf_area->y = 0;
- pix = xfdesktop_icon_peek_pixbuf(icon, ICON_SIZE);
+ pix = xfdesktop_icon_peek_pixbuf(icon, ICON_WIDTH, ICON_SIZE);
if(G_LIKELY(pix)) {
pixbuf_area->width = gdk_pixbuf_get_width(pix);
pixbuf_area->height = gdk_pixbuf_get_height(pix);
@@ -2984,7 +2986,7 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
state = GTK_STATE_NORMAL;
if(gdk_rectangle_intersect(area, &pixbuf_extents, &intersection)) {
- GdkPixbuf *pix = xfdesktop_icon_peek_pixbuf(icon, ICON_SIZE);
+ GdkPixbuf *pix = xfdesktop_icon_peek_pixbuf(icon, ICON_WIDTH, ICON_SIZE);
GdkPixbuf *pix_free = NULL;
if(state != GTK_STATE_NORMAL) {
diff --git a/src/xfdesktop-icon.c b/src/xfdesktop-icon.c
index ffe3d2f..f78189c 100644
--- a/src/xfdesktop-icon.c
+++ b/src/xfdesktop-icon.c
@@ -179,7 +179,7 @@ xfdesktop_icon_get_extents(XfdesktopIcon *icon,
/*< required >*/
GdkPixbuf *
xfdesktop_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size)
+ gint width, gint height)
{
XfdesktopIconClass *klass;
@@ -187,7 +187,7 @@ xfdesktop_icon_peek_pixbuf(XfdesktopIcon *icon,
klass = XFDESKTOP_ICON_GET_CLASS(icon);
g_return_val_if_fail(klass->peek_pixbuf, NULL);
- return klass->peek_pixbuf(icon, size);
+ return klass->peek_pixbuf(icon, width, height);
}
/*< required >*/
diff --git a/src/xfdesktop-icon.h b/src/xfdesktop-icon.h
index 5b750fd..e69c880 100644
--- a/src/xfdesktop-icon.h
+++ b/src/xfdesktop-icon.h
@@ -63,7 +63,7 @@ struct _XfdesktopIconClass
gboolean (*activated)(XfdesktopIcon *icon);
/*< virtual functions >*/
- GdkPixbuf *(*peek_pixbuf)(XfdesktopIcon *icon, gint size);
+ GdkPixbuf *(*peek_pixbuf)(XfdesktopIcon *icon, gint width, gint height);
G_CONST_RETURN gchar *(*peek_label)(XfdesktopIcon *icon);
GdkDragAction (*get_allowed_drag_actions)(XfdesktopIcon *icon);
@@ -85,7 +85,8 @@ GType xfdesktop_icon_get_type(void) G_GNUC_CONST;
/* xfdesktop virtual function accessors */
GdkPixbuf *xfdesktop_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size);
+ gint width,
+ gint height);
G_CONST_RETURN gchar *xfdesktop_icon_peek_label(XfdesktopIcon *icon);
G_CONST_RETURN gchar *xfdesktop_icon_peek_tooltip(XfdesktopIcon *icon);
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index 0d51a18..974407b 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -63,7 +63,7 @@ struct _XfdesktopRegularFileIconPrivate
gchar *display_name;
gchar *tooltip;
guint pix_opacity;
- gint cur_pix_size;
+ gint cur_pix_width, cur_pix_height;
GFileInfo *file_info;
GFileInfo *filesystem_info;
GFile *file;
@@ -77,7 +77,7 @@ static void xfdesktop_regular_file_icon_set_thumbnail_file(XfdesktopIcon *icon,
static void xfdesktop_regular_file_icon_delete_thumbnail_file(XfdesktopIcon *icon);
static GdkPixbuf *xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size);
+ gint width, gint height);
static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
@@ -292,15 +292,16 @@ xfdesktop_load_icon_from_desktop_file(XfdesktopRegularFileIcon *regular_icon)
static GdkPixbuf *
xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size)
+ gint width, gint height)
{
XfdesktopRegularFileIcon *regular_icon = XFDESKTOP_REGULAR_FILE_ICON(icon);
XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
- if(size != regular_icon->priv->cur_pix_size)
+ if(width != regular_icon->priv->cur_pix_width
+ || height != regular_icon->priv->cur_pix_height)
xfdesktop_regular_file_icon_invalidate_pixbuf(regular_icon);
- /* Still valid */
+ /* Still valid */
if(regular_icon->priv->pix != NULL)
return regular_icon->priv->pix;
@@ -310,8 +311,19 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
file_icon->gicon = xfdesktop_load_icon_from_desktop_file(regular_icon);
} else {
/* If we have a thumbnail then they are enabled, use it. */
- if(regular_icon->priv->thumbnail_file)
- file_icon->gicon = g_file_icon_new(regular_icon->priv->thumbnail_file);
+ if(regular_icon->priv->thumbnail_file) {
+ gchar *file = g_file_get_path(regular_icon->priv->file);
+ gchar *mimetype = xfdesktop_get_file_mimetype(file);
+
+ /* Don't use thumbnails for svg, use the file itself */
+ if(g_strcmp0(mimetype, "image/svg+xml") == 0)
+ file_icon->gicon = g_file_icon_new(regular_icon->priv->file);
+ else
+ file_icon->gicon = g_file_icon_new(regular_icon->priv->thumbnail_file);
+
+ g_free(mimetype);
+ g_free(file);
+ }
}
/* If we still don't have an icon, use the default */
@@ -352,10 +364,11 @@ xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
}
regular_icon->priv->pix = xfdesktop_file_utils_get_icon(file_icon->gicon,
- size,
+ width, height,
regular_icon->priv->pix_opacity);
- regular_icon->priv->cur_pix_size = size;
+ regular_icon->priv->cur_pix_width = width;
+ regular_icon->priv->cur_pix_height = height;
return regular_icon->priv->pix;
}
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index cda392e..3f4b96e 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -57,7 +57,7 @@ struct _XfdesktopSpecialFileIconPrivate
XfdesktopSpecialFileIconType type;
GdkPixbuf *pix;
gchar *tooltip;
- gint cur_pix_size;
+ gint cur_pix_height;
GFileMonitor *monitor;
GFileInfo *file_info;
GFileInfo *filesystem_info;
@@ -71,7 +71,7 @@ struct _XfdesktopSpecialFileIconPrivate
static void xfdesktop_special_file_icon_finalize(GObject *obj);
static GdkPixbuf *xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size);
+ gint width, gint height);
static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_special_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
@@ -218,13 +218,13 @@ xfdesktop_special_file_icon_invalidate_pixbuf(XfdesktopSpecialFileIcon *icon)
static GdkPixbuf *
xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size)
+ gint width, gint height)
{
XfdesktopSpecialFileIcon *special_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon);
XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
GFile *parent = NULL;
- if(size != special_icon->priv->cur_pix_size)
+ if(height != special_icon->priv->cur_pix_height)
xfdesktop_special_file_icon_invalidate_pixbuf(special_icon);
/* Still valid */
@@ -269,10 +269,11 @@ xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon,
}
special_icon->priv->pix = xfdesktop_file_utils_get_icon(file_icon->gicon,
- size,
+ height,
+ height,
100);
- special_icon->priv->cur_pix_size = size;
+ special_icon->priv->cur_pix_height = height;
return special_icon->priv->pix;
}
diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c
index 47301e5..024bca2 100644
--- a/src/xfdesktop-volume-icon.c
+++ b/src/xfdesktop-volume-icon.c
@@ -62,7 +62,7 @@ struct _XfdesktopVolumeIconPrivate
{
GdkPixbuf *pix;
gchar *tooltip;
- gint cur_pix_size;
+ gint cur_pix_height;
gchar *label;
GVolume *volume;
GFileInfo *file_info;
@@ -77,7 +77,7 @@ struct _XfdesktopVolumeIconPrivate
static void xfdesktop_volume_icon_finalize(GObject *obj);
static GdkPixbuf *xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size);
+ gint width, gint height);
static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
@@ -254,7 +254,7 @@ xfdesktop_volume_icon_is_mounted(XfdesktopIcon *icon)
static GdkPixbuf *
xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size)
+ gint width, gint height)
{
XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon);
XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
@@ -262,7 +262,7 @@ xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
g_return_val_if_fail(XFDESKTOP_IS_VOLUME_ICON(icon), NULL);
- if(size != volume_icon->priv->cur_pix_size)
+ if(height != volume_icon->priv->cur_pix_height)
xfdesktop_volume_icon_invalidate_pixbuf(volume_icon);
/* Still valid */
@@ -287,10 +287,10 @@ xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
opacity = 50;
volume_icon->priv->pix = xfdesktop_file_utils_get_icon(file_icon->gicon,
- size,
+ height, height,
opacity);
- volume_icon->priv->cur_pix_size = size;
+ volume_icon->priv->cur_pix_height = height;
return volume_icon->priv->pix;
}
diff --git a/src/xfdesktop-window-icon.c b/src/xfdesktop-window-icon.c
index c2a9b62..feabd4d 100644
--- a/src/xfdesktop-window-icon.c
+++ b/src/xfdesktop-window-icon.c
@@ -36,7 +36,7 @@ struct _XfdesktopWindowIconPrivate
{
gint workspace;
GdkPixbuf *pix;
- gint cur_pix_size;
+ gint cur_pix_height;
gchar *label;
WnckWindow *window;
};
@@ -44,7 +44,7 @@ struct _XfdesktopWindowIconPrivate
static void xfdesktop_window_icon_finalize(GObject *obj);
static GdkPixbuf *xfdesktop_window_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size);
+ gint width, gint height);
static G_CONST_RETURN gchar *xfdesktop_window_icon_peek_label(XfdesktopIcon *icon);
static gboolean xfdesktop_window_icon_activated(XfdesktopIcon *icon);
@@ -151,27 +151,28 @@ xfdesktop_window_icon_changed_cb(WnckWindow *window,
static GdkPixbuf *
xfdesktop_window_icon_peek_pixbuf(XfdesktopIcon *icon,
- gint size)
+ gint width, gint height)
{
XfdesktopWindowIcon *window_icon = XFDESKTOP_WINDOW_ICON(icon);
-
- if(!window_icon->priv->pix || window_icon->priv->cur_pix_size != size) {
+
+ if(!window_icon->priv->pix || window_icon->priv->cur_pix_height != height) {
if(window_icon->priv->pix)
g_object_unref(G_OBJECT(window_icon->priv->pix));
-
+
window_icon->priv->pix = wnck_window_get_icon(window_icon->priv->window);
if(window_icon->priv->pix) {
- if(gdk_pixbuf_get_width(window_icon->priv->pix) != size) {
+ if(gdk_pixbuf_get_height(window_icon->priv->pix) != height) {
window_icon->priv->pix = gdk_pixbuf_scale_simple(window_icon->priv->pix,
- size,
- size,
+ height,
+ height,
GDK_INTERP_BILINEAR);
} else
g_object_ref(G_OBJECT(window_icon->priv->pix));
- window_icon->priv->cur_pix_size = size;
+
+ window_icon->priv->cur_pix_height = height;
}
}
-
+
return window_icon->priv->pix;
}
More information about the Xfce4-commits
mailing list