+
+ g_hash_table_insert(menu_map, &entry->item, menu);
+}
+
+void menu_show(char *name, int x, int y, Client *client)
+{
+ Menu *self;
+
+ self = g_hash_table_lookup(menu_hash, name);
+ if (!self) {
+ g_warning("Attempted to show menu '%s' but it does not exist.",
+ name);
+ return;
+ }
+
+ if (self->invalid) {
+ if (self->update) {
+ self->update(self);
+ } else {
+ menu_render(self);
+ }
+ }
+
+ self->client = client;
+
+ if (self->show) {
+ self->show(self, x, y, client);
+ } else {
+ menu_control_show(self, x, y, client);
+ }
+}
+
+void menu_hide(Menu *self) {
+ if (self->shown) {
+ XUnmapWindow(ob_display, self->frame);
+ self->shown = FALSE;
+ }
+}
+
+MenuEntry *menu_find_entry(Menu *menu, Window win)
+{
+ GList *it;
+
+ for (it = menu->entries; it; it = it->next) {
+ MenuEntry *entry = it->data;
+ if (entry->item == win)
+ return entry;
+ }
+ return NULL;
+}
+
+void menu_entry_render(MenuEntry *self)
+{
+ Menu *menu = self->parent;
+ Appearance *a;
+
+ a = !self->enabled ? self->a_disabled :
+ (self->hilite && self->action ? self->a_hilite : self->a_item);
+
+ RECT_SET(a->area, 0, 0, menu->width,
+ menu->item_h);
+ RECT_SET(a->texture[0].position, menu->bullet_w,
+ 0, menu->width - 2 * menu->bullet_w,
+ menu->item_h);
+
+ XMoveResizeWindow(ob_display, self->item, 0, self->y,
+ menu->width, menu->item_h);
+ a->surface.data.planar.parent = menu->a_items;
+ a->surface.data.planar.parentx = 0;
+ a->surface.data.planar.parenty = self->y;
+
+ paint(self->item, a);
+}
+
+void menu_entry_fire(MenuEntry *self)
+{
+ Menu *m;
+
+ if (self->action) {
+ self->action->data.any.c = self->parent->client;
+ self->action->func(&self->action->data);
+
+ /* hide the whole thing */
+ m = self->parent;
+ while (m->parent) m = m->parent;
+ menu_hide(m);
+ }
+}
+
+/*
+ Default menu controller action for showing.
+*/
+
+void menu_control_show(Menu *self, int x, int y, Client *client) {
+ XMoveWindow(ob_display, self->frame, x, y);
+
+ if (!self->shown) {
+ stacking_raise_internal(self->frame);
+ XMapWindow(ob_display, self->frame);
+ self->shown = TRUE;
+ }