[Xfce4-commits] <libxfcegui4:xfce-4.6> redo how icon sizing works for the apps menu
Brian J. Tarricone
brian at tarricone.org
Mon Aug 17 21:42:03 CEST 2009
Updating branch refs/heads/xfce-4.6
to e9aba8edc828113dfc4a4eef4cf14bc5a4932b7e (commit)
from 644325fb171d63c0ec778c33d0421a6930ce056d (commit)
commit e9aba8edc828113dfc4a4eef4cf14bc5a4932b7e
Author: Brian J. Tarricone <brian at tarricone.org>
Date: Mon Aug 17 12:37:28 2009 -0700
redo how icon sizing works for the apps menu
the old method could result in different sizes for icons specified as
themed icon names and icons specified with full paths. this also gets
rid of the old custom size code entirely, which had been disabled for a
while. (bug 5660)
libxfcegui4/xfce-appmenuitem.c | 139 ++++++++++++++++++++-------------------
1 files changed, 71 insertions(+), 68 deletions(-)
diff --git a/libxfcegui4/xfce-appmenuitem.c b/libxfcegui4/xfce-appmenuitem.c
index b72d30d..3362f7a 100644
--- a/libxfcegui4/xfce-appmenuitem.c
+++ b/libxfcegui4/xfce-appmenuitem.c
@@ -72,15 +72,15 @@ static void xfce_app_menu_item_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void xfce_app_menu_item_size_request(GtkWidget *widget,
- GtkRequisition *req);
static void xfce_app_menu_item_finalize(GObject *object);
+static void xfce_app_menu_item_realize(GtkWidget *widget);
+
+static void xfce_app_menu_item_update_icon(XfceAppMenuItem *app_menu_item);
+
static void _command_activate_cb(GtkMenuItem *menu_item,
gpointer user_data);
-static gint _xfce_app_menu_item_icon_size = -1;
-
G_DEFINE_TYPE(XfceAppMenuItem, xfce_app_menu_item, GTK_TYPE_IMAGE_MENU_ITEM)
@@ -222,7 +222,7 @@ xfce_app_menu_item_class_init(XfceAppMenuItemClass *klass)
g_type_class_add_private(klass, sizeof(XfceAppMenuItemPriv));
- widget_class->size_request = xfce_app_menu_item_size_request;
+ widget_class->realize = xfce_app_menu_item_realize;
gobject_class->finalize = xfce_app_menu_item_finalize;
gobject_class->set_property = xfce_app_menu_item_set_property;
@@ -257,11 +257,6 @@ xfce_app_menu_item_class_init(XfceAppMenuItemClass *klass)
g_param_spec_boolean("use-underline", _("Use underline"),
_("Whether or not to use an underscore in the label as a keyboard mnemonic"),
FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE));
-
- if(-1 == _xfce_app_menu_item_icon_size) {
- gtk_icon_size_lookup(GTK_ICON_SIZE_MENU,
- &_xfce_app_menu_item_icon_size, NULL);
- }
}
static void
@@ -361,43 +356,6 @@ xfce_app_menu_item_get_property(GObject *object, guint prop_id, GValue *value,
}
static void
-xfce_app_menu_item_size_request(GtkWidget *widget,
- GtkRequisition *req)
-{
-
- XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(widget);
- GtkWidget *img;
- GdkPixbuf *pix;
-
- if(app_menu_item->priv->icon_path && !app_menu_item->priv->icon_set) {
- img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
- if(!img) {
- img = gtk_image_new();
- gtk_widget_show(img);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
- }
-
- pix = gdk_pixbuf_new_from_file_at_size(app_menu_item->priv->icon_path,
- _xfce_app_menu_item_icon_size,
- _xfce_app_menu_item_icon_size,
- NULL);
-
- if(pix) {
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), pix);
- g_object_unref(G_OBJECT(pix));
- app_menu_item->priv->icon_set = TRUE;
- } else {
- g_free(app_menu_item->priv->icon_path);
- app_menu_item->priv->icon_path = NULL;
- }
- }
-
- /* let the parent do its magic */
- GTK_WIDGET_CLASS(xfce_app_menu_item_parent_class)->size_request(widget,
- req);
-}
-
-static void
xfce_app_menu_item_finalize(GObject *object)
{
XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(object);
@@ -415,34 +373,50 @@ xfce_app_menu_item_finalize(GObject *object)
}
static void
+xfce_app_menu_item_realize(GtkWidget *widget)
+{
+ XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(widget);
+
+ GTK_WIDGET_CLASS(xfce_app_menu_item_parent_class)->realize(widget);
+
+ xfce_app_menu_item_update_icon(app_menu_item);
+}
+
+static void
xfce_app_menu_item_update_icon(XfceAppMenuItem *app_menu_item)
{
+ GtkWidget *img;
+
if(!GTK_WIDGET_REALIZED(app_menu_item))
return;
- if(app_menu_item->priv->icon_name)
- gtk_image_set_from_icon_name(GTK_IMAGE(img), app_menu_item->priv->icon_name);
- else if(app_menu_item->priv->icon_path) {
+ img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
+ if(!img) {
+ img = gtk_image_new();
+ gtk_widget_show(img);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
+ } else
+ gtk_image_clear(GTK_IMAGE(img));
+
+ if(app_menu_item->priv->icon_name) {
GtkIconTheme *itheme = gtk_icon_theme_get_default();
- GdkPixbuf *pix = gtk_icon_theme_load_icon(itheme, app_menu_item->priv->icon_path, 0, NULL);
- if(pix) {
- GtkWidget *img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
- if(!img) {
- img = gtk_image_new();
- gtk_widget_show(img);
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
- }
+ if(gtk_icon_theme_has_icon(itheme, app_menu_item->priv->icon_name)) {
+ gtk_image_set_from_icon_name(GTK_IMAGE(img), app_menu_item->priv->icon_name,
+ GTK_ICON_SIZE_MENU);
+ }
+ } else if(app_menu_item->priv->icon_path) {
+ GdkPixbuf *pix;
+ gint w, h;
+ gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
+
+ pix = gdk_pixbuf_new_from_file_at_scale(app_menu_item->priv->icon_path,
+ w, h, TRUE, NULL);
+ if(pix) {
gtk_image_set_from_pixbuf(GTK_IMAGE(img), pix);
g_object_unref(G_OBJECT(pix));
}
- } else {
- GtkWidget *img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
- if(img) {
- gtk_image_set_from_icon_name(GTK_IMAGE(img), NULL);
- gtk_image_set_from_pixbuf(GTK_IMAGE(img), NULL);
- }
}
}
@@ -725,10 +699,39 @@ xfce_app_menu_item_set_icon_name(XfceAppMenuItem *app_menu_item,
g_free(app_menu_item->priv->icon_path);
app_menu_item->priv->icon_path = NULL;
- if(!strstr(filename, G_DIR_SEPARATOR_S))
- app_menu_item->priv->icon_name = g_strdup(filename);
- else
- app_menu_item->priv->icon_path = g_strdup(filename);
+ if(filename) {
+ if(g_path_is_absolute(filename))
+ app_menu_item->priv->icon_path = g_strdup(filename);
+ else {
+ gchar *p, *q;
+ gsize len;
+
+ /* yes, there are really broken .desktop files out there
+ * messed up like this */
+
+ /* first make sure we aren't a weird relative path */
+ p = g_strrstr(filename, G_DIR_SEPARATOR_S);
+ if(p)
+ p++;
+ else
+ p = (gchar *)filename;
+
+ len = strlen(p);
+
+ /* now make sure we don't have an extension */
+ q = g_strrstr(p, ".");
+ if(q && (!strcmp(q, ".png") || !strcmp(q, ".svg")
+ || !strcmp(q, ".jpg") || !strcmp(q, ".gif")
+ || !strcmp(q, ".bmp")))
+ {
+ len -= strlen(q);
+ }
+
+ /* whatever's left... */
+ if(p[0] && len)
+ app_menu_item->priv->icon_name = g_strndup(p, len);
+ }
+ }
xfce_app_menu_item_update_icon(app_menu_item);
}
More information about the Xfce4-commits
mailing list