From: Dana Jansens Date: Thu, 28 Aug 2003 07:49:57 +0000 (+0000) Subject: make submenus not require the menu to exist when they are created, not until they... X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=c34915ae8d49f61426912ef332e8097be516bdd3;p=chaz%2Fopenbox make submenus not require the menu to exist when they are created, not until they are shown. crash fix in client_menu --- diff --git a/openbox/menu.c b/openbox/menu.c index 324b3629..d742b972 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -253,6 +253,8 @@ static void menu_entry_free(ObMenuEntry *self) } break; case OB_MENU_ENTRY_TYPE_SUBMENU: + g_free(self->data.submenu.name); + break; case OB_MENU_ENTRY_TYPE_SEPARATOR: break; } @@ -296,14 +298,13 @@ void menu_add_normal(gchar *name, gint id, gchar *label, GSList *actions) void menu_add_submenu(gchar *name, gint id, gchar *submenu) { - ObMenu *self, *sub; + ObMenu *self; ObMenuEntry *e; if (!(self = menu_from_name(name))) return; - if (!(sub = menu_from_name(submenu))) return; e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_SUBMENU, id); - e->data.submenu.submenu = sub; + e->data.submenu.name = g_strdup(submenu); self->entries = g_list_append(self->entries, e); } @@ -359,3 +360,15 @@ ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id) } return ret; } + +void menu_find_submenus(ObMenu *self) +{ + GList *it; + + for (it = self->entries; it; it = g_list_next(it)) { + ObMenuEntry *e = it->data; + + if (e->type == OB_MENU_ENTRY_TYPE_SUBMENU) + e->data.submenu.submenu = menu_from_name(e->data.submenu.name); + } +} diff --git a/openbox/menu.h b/openbox/menu.h index c4c9deea..c91be82b 100644 --- a/openbox/menu.h +++ b/openbox/menu.h @@ -62,6 +62,7 @@ struct _ObNormalMenuEntry { }; struct _ObSubmenuMenuEntry { + gchar *name; ObMenu *submenu; }; @@ -107,4 +108,6 @@ void menu_add_separator(gchar *name, gint id); ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id); +void menu_find_submenus(ObMenu *self); + #endif diff --git a/openbox/menuframe.c b/openbox/menuframe.c index ea7f254c..8ffd27ad 100644 --- a/openbox/menuframe.c +++ b/openbox/menuframe.c @@ -170,6 +170,7 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) { RrAppearance *item_a, *text_a; gint th; /* temp */ + ObMenu *sub; item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && !self->entry->data.normal.enabled) ? @@ -205,8 +206,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self) text_a->texture[0].data.text.string = self->entry->data.normal.label; break; case OB_MENU_ENTRY_TYPE_SUBMENU: - text_a->texture[0].data.text.string = - self->entry->data.submenu.submenu->title; + sub = self->entry->data.submenu.submenu; + text_a->texture[0].data.text.string = sub ? sub->title : ""; break; case OB_MENU_ENTRY_TYPE_SEPARATOR: break; @@ -265,6 +266,7 @@ static void menu_frame_render(ObMenuFrame *self) gint tw, th; /* temps */ GList *it; gboolean has_icon = FALSE, has_bullet = FALSE; + ObMenu *sub; XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->bwidth); XSetWindowBorder(ob_display, self->window, @@ -315,8 +317,8 @@ static void menu_frame_render(ObMenuFrame *self) /* XXX has_icon = TRUE; */ break; case OB_MENU_ENTRY_TYPE_SUBMENU: - text_a->texture[0].data.text.string = - e->entry->data.submenu.submenu->title; + sub = e->entry->data.submenu.submenu; + text_a->texture[0].data.text.string = sub ? sub->title : ""; RrMinsize(text_a, &tw, &th); has_bullet = TRUE; @@ -378,6 +380,8 @@ static void menu_frame_update(ObMenuFrame *self) { GList *mit, *fit; + menu_find_submenus(self->menu); + self->selected = NULL; for (mit = self->menu->entries, fit = self->entries; mit && fit; @@ -538,6 +542,8 @@ void menu_entry_frame_show_submenu(ObMenuEntryFrame *self) { ObMenuFrame *f; + if (!self->entry->data.submenu.submenu) return; + f = menu_frame_new(self->entry->data.submenu.submenu, self->frame->client); menu_frame_move(f, diff --git a/plugins/menu/client_menu.c b/plugins/menu/client_menu.c index 32277047..696387df 100644 --- a/plugins/menu/client_menu.c +++ b/plugins/menu/client_menu.c @@ -83,6 +83,9 @@ static void layer_update(ObMenuFrame *frame, gpointer data) e->data.normal.enabled = !!frame->client; } + if (!frame->client) + return; + e = menu_find_entry_id(menu, LAYER_TOP); e->data.normal.enabled = !frame->client->above;