From 588aa0790abd0bf6452843c0e3490482e90b3654 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 16 Apr 2010 17:58:20 +0200 Subject: [PATCH] Allow setting icons for submenus --- openbox/menu.c | 19 +++++++++++++++++-- openbox/menu.h | 13 +++++++++---- openbox/menuframe.c | 9 ++++++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/openbox/menu.c b/openbox/menu.c index 6c346e85..daea0b65 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -326,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; @@ -349,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); @@ -534,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: diff --git a/openbox/menu.h b/openbox/menu.h index c0cc199d..76cc238f 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -103,6 +103,10 @@ typedef enum } ObMenuEntryType; struct _ObNormalMenuEntry { + /* Icon stuff. If you set this, make sure you RrImageRef() it too. */ + RrImage *icon; + gint icon_alpha; + gchar *label; /*! The shortcut key that would be used to activate this menu entry */ gunichar shortcut; @@ -117,10 +121,6 @@ struct _ObNormalMenuEntry { /* List of ObActions */ GSList *actions; - /* Icon stuff. If you set this, make sure you RrImageRef() it too. */ - RrImage *icon; - gint icon_alpha; - /* Mask icon */ RrPixmapMask *mask; RrColor *mask_normal_color; @@ -132,8 +132,13 @@ struct _ObNormalMenuEntry { }; struct _ObSubmenuMenuEntry { + /* Icon stuff. If you set this, make sure you RrImageRef() it too. */ + RrImage *icon; + gint icon_alpha; + gchar *name; ObMenu *submenu; + guint show_from; }; diff --git a/openbox/menuframe.c b/openbox/menuframe.c index e6fc53ab..6110045c 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -181,7 +181,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); } @@ -209,7 +210,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); } @@ -522,7 +524,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) g_assert_not_reached(); } - 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)) && self->entry->data.normal.icon) { RrAppearance *clear; -- 2.45.2