]> Dogcows Code - chaz/openbox/blobdiff - openbox/menu.c
Rework the code provided by Kadlcik Libor for loading/showing icons in Openbox menus.
[chaz/openbox] / openbox / menu.c
index f53e4f0b44661e23cc82f69c17750fd865750f93..524220c0af14325eb691924ff1ea640928d44bf6 100644 (file)
@@ -36,7 +36,6 @@
 #include "gettext.h"
 #include "obt/xml.h"
 #include "obt/paths.h"
-#include "imageload.h"
 
 typedef struct _ObMenuParseState ObMenuParseState;
 
@@ -270,43 +269,46 @@ static void parse_menu_item(xmlNodePtr node,  gpointer data)
 {
     ObMenuParseState *state = data;
     gchar *label;
-    #ifdef USE_IMLIB2
     gchar *icon;
-    #endif
     ObMenuEntry *e;
 
     if (state->parent) {
-        #ifdef USE_IMLIB2
         /* Don't try to extract "icon" attribute if icons in user-defined
-          menus are not enabled. */
-        if (!(config_menu_user_show_icons &&
-            obt_xml_attr_string(node, "icon", &icon)))
-               icon = NULL;
-        #endif
+           menus are not enabled. */
 
         if (obt_xml_attr_string(node, "label", &label)) {
+            xmlNodePtr c;
             GSList *acts = NULL;
 
-            node = obt_xml_find_node(node->children, "action");
-            while (node) {
-                ObActionsAct *action = actions_parse(node);
+            c = obt_xml_find_node(node->children, "action");
+            while (c) {
+                ObActionsAct *action = actions_parse(c);
                 if (action)
                     acts = g_slist_append(acts, action);
-                node = obt_xml_find_node(node->next, "action");
+                c = obt_xml_find_node(node->next, "action");
             }
             e = menu_add_normal(state->parent, -1, label, acts, TRUE);
             
-            #ifdef USE_IMLIB2
-            if (icon) { /* Icon will be used. */
-                e->data.normal.icon = RrImageFetchFromFile(ob_rr_icons, icon);
-                if (e->data.normal.icon) {
-                    e->data.normal.icon_alpha = 0xff;
+            if (config_menu_show_icons &&
+                obt_xml_attr_string(node, "icon", &icon))
+            {
+                RrImage *ic;
+
+                ic = RrImageCacheFindName(ob_rr_icons, icon);
+                if (ic)
+                    RrImageRef(ic);
+                else {
+                    ic = RrImageNew(ob_rr_icons);
+                    if (!RrImageAddPictureName(ic, icon))
+                        RrImageUnref(ic); /* no need to keep it around */
                 }
+                e->data.normal.icon = ic;
+
+                if (e->data.normal.icon)
+                    e->data.normal.icon_alpha = 0xff;
+
                 g_free(icon);
             }
-
-            menu_add_normal(state->parent, -1, label, acts, TRUE);
-            #endif
             g_free(label);
         }
     }
This page took 0.026139 seconds and 4 git commands to generate.