[Xfce4-commits] <xfdesktop:xfce-4.10> Improve menu icon loading (Bug #8795)

Jérôme Guelfucci noreply at xfce.org
Sat Mar 2 18:06:03 CET 2013


Updating branch refs/heads/xfce-4.10
         to e0b84b28de52d26b0a44c495e4ff453717fbd718 (commit)
       from 9916e6e0068523c058c9c29ca437b6f41d69cd40 (commit)

commit e0b84b28de52d26b0a44c495e4ff453717fbd718
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sat Dec 22 11:01:43 2012 +0300

    Improve menu icon loading (Bug #8795)
    
    This code checks if the icon theme has the custom icon name and
    loads that directly into a gtk_image widget rather than a pixbuf
    first, which should provide a small speed improvement when many
    items are present in the menu. Should that fail, it will fallback
    to checking all other possible locations for the menu item's icon.

 src/xfdesktop-app-menu-item.c |   34 +++++++++++++++++++---------------
 1 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/xfdesktop-app-menu-item.c b/src/xfdesktop-app-menu-item.c
index 3722c51..d9a1796 100644
--- a/src/xfdesktop-app-menu-item.c
+++ b/src/xfdesktop-app-menu-item.c
@@ -171,30 +171,31 @@ xfdesktop_app_menu_item_set_icon(XfdesktopAppMenuItem *app_menu_item)
     const gchar *icon_name;
     gint w, h, size;
     GdkPixbuf *pixbuf = NULL;
-    GtkWidget *image;
+    GtkWidget *image = NULL;
     GtkIconTheme *icon_theme;
     gchar *p, *name = NULL;
     gchar *filename;
 
     icon_name = garcon_menu_item_get_icon_name(app_menu_item->item);
+    icon_theme = gtk_icon_theme_get_default();
 
     if(G_LIKELY(icon_name)) {
         gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
         size = MIN(w, h);
 
-        if (g_path_is_absolute (icon_name)) {
-            pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_name, w, h, TRUE, NULL);
-        } else {
-            icon_theme = gtk_icon_theme_get_default();
-            pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, size, 0, NULL);
-
-            if (G_UNLIKELY(pixbuf == NULL)) {
+        if(gtk_icon_theme_has_icon(icon_theme, icon_name))
+            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);
+            } else {
                 /* try to lookup names like application.png in the theme */
                 p = strrchr(icon_name, '.');
                 if (p) {
                     name = g_strndup(icon_name, p - icon_name);
                     pixbuf = gtk_icon_theme_load_icon(icon_theme, name, size, 0, NULL);
                     g_free (name);
+                    name = NULL;
                 }
 
                 /* maybe they point to a file in the pixbufs folder */
@@ -202,21 +203,24 @@ xfdesktop_app_menu_item_set_icon(XfdesktopAppMenuItem *app_menu_item)
                     filename = g_build_filename("pixmaps", icon_name, NULL);
                     name = xfce_resource_lookup(XFCE_RESOURCE_DATA, filename);
                     g_free(filename);
+                }
 
-                    if(name)
-                        pixbuf = gdk_pixbuf_new_from_file(name, NULL);
+                if(name) {
+                    pixbuf = gdk_pixbuf_new_from_file_at_scale(name, w, h, TRUE, NULL);
                     g_free(name);
                 }
             }
+
+            /* Turn the pixbuf into a gtk_image */
+            if(G_LIKELY(pixbuf)) {
+                image = gtk_image_new_from_pixbuf(pixbuf);
+                g_object_unref(G_OBJECT(pixbuf));
+            }
         }
     }
 
-    if(G_LIKELY(pixbuf)) {
-        image = gtk_image_new_from_pixbuf(pixbuf);
-        g_object_unref(G_OBJECT(pixbuf));
-    } else {
+    if(!GTK_IS_IMAGE(image))
         image = gtk_image_new();
-    }
 
     gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), image);
 }


More information about the Xfce4-commits mailing list