- self = g_new0(Menu, 1);
- self->obwin.type = Window_Menu;
- self->label = g_strdup(label);
- self->name = g_strdup(name);
- self->parent = parent;
- self->open_submenu = NULL;
-
- self->entries = NULL;
- self->shown = FALSE;
- self->invalid = TRUE;
-
- /* default controllers */
- self->show = show;
- self->hide = NULL;
- self->update = update;
- self->mouseover = NULL;
- self->selected = NULL;
-
- self->plugin = NULL;
- self->plugin_data = NULL;
-
- attrib.override_redirect = TRUE;
- attrib.event_mask = FRAME_EVENTMASK;
- self->frame = createWindow(ob_root, CWOverrideRedirect|CWEventMask, &attrib);
- attrib.event_mask = TITLE_EVENTMASK;
- self->title = createWindow(self->frame, CWEventMask, &attrib);
- self->items = createWindow(self->frame, 0, &attrib);
-
- XSetWindowBorderWidth(ob_display, self->frame, ob_rr_theme->bwidth);
- XSetWindowBackground(ob_display, self->frame, ob_rr_theme->b_color->pixel);
- XSetWindowBorderWidth(ob_display, self->title, ob_rr_theme->bwidth);
- XSetWindowBorder(ob_display, self->frame, ob_rr_theme->b_color->pixel);
- XSetWindowBorder(ob_display, self->title, ob_rr_theme->b_color->pixel);
-
- XMapWindow(ob_display, self->title);
- XMapWindow(ob_display, self->items);
-
- self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
- self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
-
- g_hash_table_insert(window_map, &self->frame, self);
- g_hash_table_insert(window_map, &self->title, self);
- g_hash_table_insert(window_map, &self->items, self);
- g_hash_table_insert(menu_hash, g_strdup(name), self);
-
- stacking_add(MENU_AS_WINDOW(self));
- stacking_raise(MENU_AS_WINDOW(self));
+ menu_frame_hide_all();
+
+ /* clear the pipe menus when showing a new menu */
+ menu_clear_pipe_caches();
+
+ frame = menu_frame_new(self, 0, client);
+ if (!menu_frame_show_topmenu(frame, x, y, mouse))
+ menu_frame_free(frame);
+ else {
+ if (!mouse) {
+ /* select the first entry if it's not a submenu and we opened
+ * the menu with the keyboard, and skip all headers */
+ GList *it = frame->entries;
+ while (it) {
+ ObMenuEntryFrame *e = it->data;
+ if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
+ menu_frame_select(frame, e, FALSE);
+ break;
+ } else if (e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
+ it = g_list_next(it);
+ else
+ break;
+ }
+ }
+
+ /* reset the hide timer */
+ if (!mouse)
+ menu_can_hide = TRUE;
+ else {
+ menu_can_hide = FALSE;
+ ob_main_loop_timeout_add(ob_main_loop,
+ config_menu_hide_delay * 1000,
+ menu_hide_delay_func,
+ NULL, g_direct_equal, NULL);
+ }
+ }
+}