make submenus not require the menu to exist when they are created, not until they are shown.
crash fix in client_menu
This commit is contained in:
parent
f7eb47dba4
commit
c34915ae8d
4 changed files with 32 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue