]> Dogcows Code - chaz/openbox/blobdiff - openbox/menu.c
Allow setting icons for submenus
[chaz/openbox] / openbox / menu.c
index a4f62f6c7301f87778dbf571dc3e36556a96911f..daea0b65e12d025f3261ae45de0c96edb9752b0f 100644 (file)
@@ -294,19 +294,7 @@ static void parse_menu_item(xmlNodePtr node,  gpointer data)
             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 */
-                        ic = NULL;
-                    }
-                }
-                e->data.normal.icon = ic;
+                e->data.normal.icon = RrImageNewFromName(ob_rr_icons, icon);
 
                 if (e->data.normal.icon)
                     e->data.normal.icon_alpha = 0xff;
@@ -338,6 +326,8 @@ static void parse_menu(xmlNodePtr node, gpointer data)
     ObMenuParseState *state = data;
     gchar *name = NULL, *title = NULL, *script = NULL;
     ObMenu *menu;
+    ObMenuEntry *e;
+    gchar *icon;
 
     if (!obt_xml_attr_string(node, "id", &name))
         goto parse_menu_fail;
@@ -361,8 +351,20 @@ static void parse_menu(xmlNodePtr node, gpointer data)
         }
     }
 
-    if (state->parent)
-        menu_add_submenu(state->parent, -1, name);
+    if (state->parent) {
+        e = menu_add_submenu(state->parent, -1, name);
+
+        if (config_menu_show_icons &&
+            obt_xml_attr_string(node, "icon", &icon))
+        {
+            e->data.submenu.icon = RrImageNewFromName(ob_rr_icons, icon);
+
+            if (e->data.submenu.icon)
+                e->data.submenu.icon_alpha = 0xff;
+
+            g_free(icon);
+        }
+    }
 
 parse_menu_fail:
     g_free(name);
@@ -546,6 +548,7 @@ void menu_entry_unref(ObMenuEntry *self)
             }
             break;
         case OB_MENU_ENTRY_TYPE_SUBMENU:
+            RrImageUnref(self->data.submenu.icon);
             g_free(self->data.submenu.name);
             break;
         case OB_MENU_ENTRY_TYPE_SEPARATOR:
This page took 0.026841 seconds and 4 git commands to generate.