This has some code that should be "refactored" a bit.
static void parse_menu_item(xmlNodePtr node, gpointer data)
{
ObMenuParseState *state = data;
+ xmlNodePtr n;
gchar *label;
- #ifdef USE_IMLIB2
+#ifdef USE_IMLIB2
gchar *icon;
- #endif
+#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_parse_attr_string(node, "icon", &icon)))
- icon = NULL;
- #endif
-
if (obt_parse_attr_string(node, "label", &label)) {
GSList *acts = NULL;
- for (node = node->children; node; node = node->next)
- if (!xmlStrcasecmp(node->name, (const xmlChar*) "action")) {
- ObActionsAct *a = actions_parse(node);
+ for (n = node->children; n; n = n->next)
+ if (!xmlStrcasecmp(n->name, (const xmlChar*) "action")) {
+ ObActionsAct *a = actions_parse(n);
if (a)
acts = g_slist_append(acts, a);
}
e = menu_add_normal(state->parent, -1, label, acts, TRUE);
- #ifdef USE_IMLIB2
+#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_parse_attr_string(node, "icon", &icon)))
+ icon = NULL;
+
if (icon) { /* Icon will be used. */
e->data.normal.icon = RrImageFetchFromFile(ob_rr_icons, icon);
if (e->data.normal.icon) {
}
g_free(icon);
}
- #endif
+#endif
g_free(label);
}
}
ObMenuParseState *state = data;
gchar *name = NULL, *title = NULL, *script = NULL;
ObMenu *menu;
+ ObMenuEntry *e;
+ gchar *icon;
if (!obt_parse_attr_string(node, "id", &name))
goto parse_menu_fail;
}
}
- if (state->parent)
- menu_add_submenu(state->parent, -1, name);
+ if (state->parent) {
+ e = menu_add_submenu(state->parent, -1, name);
+
+ if (!(config_menu_user_show_icons &&
+ obt_parse_attr_string(node, "icon", &icon)))
+ icon = NULL;
+
+ if (icon) {
+ e->data.submenu.icon = RrImageFetchFromFile(ob_rr_icons, icon);
+ if (e->data.submenu.icon)
+ e->data.submenu.icon_alpha = 0xff;
+ g_free(icon);
+ }
+ }
parse_menu_fail:
g_free(name);
/* List of ObActions */
GSList *actions;
-
+
/* Icon stuff. If you set this, make sure you RrImageRef() it too. */
RrImage *icon;
gint icon_alpha;
struct _ObSubmenuMenuEntry {
gchar *name;
ObMenu *submenu;
+
+ /* Icon stuff. If you set this, make sure you RrImageRef() it too. */
+ RrImage *icon;
+ gint icon_alpha;
+
guint show_from;
};
self->text = createWindow(self->window, 0, NULL);
g_hash_table_insert(menu_frame_map, &self->window, self);
g_hash_table_insert(menu_frame_map, &self->text, self);
- if (entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
+ if ((entry->type == OB_MENU_ENTRY_TYPE_NORMAL) ||
+ (entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) {
self->icon = createWindow(self->window, 0, NULL);
g_hash_table_insert(menu_frame_map, &self->icon, self);
}
XDestroyWindow(obt_display, self->window);
g_hash_table_remove(menu_frame_map, &self->text);
g_hash_table_remove(menu_frame_map, &self->window);
- if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
+ if ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) ||
+ (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) {
XDestroyWindow(obt_display, self->icon);
g_hash_table_remove(menu_frame_map, &self->icon);
}
break;
}
- if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
- self->entry->data.normal.icon)
+ if (((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) &&
+ self->entry->data.normal.icon) ||
+ ((self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) &&
+ self->entry->data.submenu.icon))
{
RrAppearance *clear;
RrAppearanceClearTextures(clear);
clear->texture[0].type = RR_TEXTURE_IMAGE;
clear->texture[0].data.image.image =
- self->entry->data.normal.icon;
+ self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL ? self->entry->data.normal.icon : self->entry->data.submenu.icon;
clear->texture[0].data.image.alpha =
- self->entry->data.normal.icon_alpha;
+ self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL ? self->entry->data.normal.icon_alpha : self->entry->data.submenu.icon_alpha;
clear->surface.parent = item_a;
clear->surface.parentx = PADDING;
clear->surface.parenty = frame->item_margin.top;