From 8c9fb63baaf7d6245cccc584359bf09359663bea Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 8 Jan 2010 17:48:07 -0500 Subject: Rework the code provided by Kadlcik Libor for loading/showing icons in Openbox menus. This changes how the imagecache works, you can load an image into it directly, or you can load it by name (then it will load it from a file on disk). NOTE: The name part is incomplete, as it needs to use the freedesktop.org icon spec to search for the right file. Also to resize it should look for another icon on disk with the same name but different size (icon themes). --- openbox/menu.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'openbox/menu.c') diff --git a/openbox/menu.c b/openbox/menu.c index 77d9548c..524220c0 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -36,7 +36,6 @@ #include "gettext.h" #include "obt/xml.h" #include "obt/paths.h" -#include "imageload.h" typedef struct _ObMenuParseState ObMenuParseState; @@ -275,29 +274,39 @@ static void parse_menu_item(xmlNodePtr node, gpointer data) if (state->parent) { /* 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; - } + 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); - if (icon) { /* Icon will be used. */ - e->data.normal.icon = RrImageFetchFromFile(ob_rr_icons, icon); + 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); } g_free(label); -- cgit v1.2.3