Improved menu behaviour

Make 'left' key in a menu close it's visible child menu and move to the parent
  properly.
Make clicking on a menu item in a menu close any of its grandchildren and
  remove focus from its children, effectively focusing the menu item you
  clicked on.
This commit is contained in:
Dana Jansens 2010-01-06 17:30:42 -05:00
parent 8ed0970b65
commit f3285a3d0b
2 changed files with 25 additions and 16 deletions

View file

@ -1700,8 +1700,13 @@ static gboolean event_handle_menu_keyboard(XEvent *ev)
else if (ob_keycode_match(keycode, OB_KEY_LEFT)) { else if (ob_keycode_match(keycode, OB_KEY_LEFT)) {
/* Left goes to the parent menu */ /* Left goes to the parent menu */
if (frame->parent) if (frame->parent) {
/* remove focus from the child */
menu_frame_select(frame, NULL, TRUE); menu_frame_select(frame, NULL, TRUE);
/* and put it in the parent */
menu_frame_select(frame->parent, frame->parent->selected,
TRUE);
}
ret = TRUE; ret = TRUE;
} }

View file

@ -1153,15 +1153,13 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry,
ObMenuEntryFrame *old = self->selected; ObMenuEntryFrame *old = self->selected;
ObMenuFrame *oldchild = self->child; ObMenuFrame *oldchild = self->child;
ObMenuEntryFrame *oldchild_entry = self->child_entry; ObMenuEntryFrame *oldchild_entry = self->child_entry;
ObMenuEntryFrame *temp;
/* if the user selected a separator, ignore it and reselect what we had /* if the user selected a separator, ignore it and reselect what we had
selected before */ selected before */
if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
entry = old; entry = old;
if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU || if (old == entry && (old->entry->type != OB_MENU_ENTRY_TYPE_SUBMENU))
old == oldchild_entry))
return; return;
/* if the user left this menu but we have a submenu open, move the /* if the user left this menu but we have a submenu open, move the
@ -1203,18 +1201,24 @@ void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry,
if (self->selected) { if (self->selected) {
menu_entry_frame_render(self->selected); menu_entry_frame_render(self->selected);
/* only show if the submenu isn't already showing */ if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
if (oldchild_entry != self->selected && /* only show if the submenu isn't already showing */
self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) if (oldchild_entry != self->selected) {
{ if (immediate || config_submenu_hide_delay == 0)
if (immediate || config_submenu_hide_delay == 0) menu_entry_frame_show_submenu(self->selected);
menu_entry_frame_show_submenu(self->selected); else if (config_submenu_hide_delay > 0)
else if (config_submenu_hide_delay > 0) ob_main_loop_timeout_add(ob_main_loop,
ob_main_loop_timeout_add(ob_main_loop, config_submenu_show_delay * 1000,
config_submenu_show_delay * 1000, submenu_show_timeout,
submenu_show_timeout, self->selected, g_direct_equal,
self->selected, g_direct_equal, NULL);
NULL); }
/* hide the grandchildren of this menu. and move the cursor to
the current menu */
else if (immediate && self->child && self->child->child) {
menu_frame_hide(self->child->child);
menu_frame_select(self->child, NULL, TRUE);
}
} }
} }
} }