From: Mikael Magnusson Date: Mon, 28 Apr 2008 22:25:20 +0000 (+0200) Subject: XXX TODO BLAG ETC Allow icons also for submenus X-Git-Tag: mikabox-3.4.7.2~27^2~1 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=6d8ae6cf119b91ad8af96b65044acf0671991077;p=mikachu%2Fopenbox.git XXX TODO BLAG ETC Allow icons also for submenus This has some code that should be "refactored" a bit. --- diff --git a/openbox/menu.c b/openbox/menu.c index 390f9dde..5e1d1a47 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -266,33 +266,32 @@ static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, 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) { @@ -300,7 +299,7 @@ static void parse_menu_item(xmlNodePtr node, gpointer data) } g_free(icon); } - #endif +#endif g_free(label); } } @@ -326,6 +325,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_parse_attr_string(node, "id", &name)) goto parse_menu_fail; @@ -349,8 +350,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_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); diff --git a/openbox/menu.h b/openbox/menu.h index 43efd413..2f1fce12 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -114,7 +114,7 @@ struct _ObNormalMenuEntry { /* List of ObActions */ GSList *actions; - + /* Icon stuff. If you set this, make sure you RrImageRef() it too. */ RrImage *icon; gint icon_alpha; @@ -132,6 +132,11 @@ struct _ObNormalMenuEntry { 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; }; diff --git a/openbox/menuframe.c b/openbox/menuframe.c index e41907cd..e317cd16 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -153,7 +153,8 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry, 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); } @@ -181,7 +182,8 @@ static void menu_entry_frame_free(ObMenuEntryFrame *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); } @@ -470,8 +472,10 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) 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; @@ -486,9 +490,9 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) 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;