From dfc666dd754491a9c986fbd19179b354acde30b9 Mon Sep 17 00:00:00 2001 From: Miciah Dashiel Butler Masters Date: Wed, 19 Jan 2011 03:52:08 +0000 Subject: [PATCH] Factor try_menu out of send_kbd_event Try to make the code a little clearer by pulling try_menu out of send_kbd_event. try_menu calls the BFU code and tells send_kbd_event whether the BFU code did something with the event (i.e. opened a menu) or whether the event still needs to be handled. --- src/viewer/text/view.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/viewer/text/view.c b/src/viewer/text/view.c index 33d13c72d..1fb25a8f0 100644 --- a/src/viewer/text/view.c +++ b/src/viewer/text/view.c @@ -1474,6 +1474,31 @@ try_typeahead(struct session *ses, struct document_view *doc_view, term_send_event(ses->tab->term, ev); } +/** See whether the BFU (in particular the menu system) is interested in + * the event. */ +static enum frame_event_status +try_menu(struct session *ses, struct term_event *ev) +{ + struct window *win; + + get_kbd_modifier(ev) &= ~KBD_MOD_ALT; + activate_bfu_technology(ses, -1); + win = ses->tab->term->windows.next; + win->handler(win, ev); + if (ses->tab->term->windows.next == win) { + deselect_mainmenu(win->term, win->data); + print_screen_status(ses); + } + if (!tabs_are_on_top(ses->tab->term)) { + /* The event opened a menu; we're done. */ + return FRAME_EVENT_OK; + } + /* Otherwise, the event still needs to be handled. */ + get_kbd_modifier(ev) |= KBD_MOD_ALT; + + return FRAME_EVENT_IGNORED; +} + /** @returns the session if event cleanup should be done or NULL if no * cleanup is needed. */ static struct session * @@ -1515,22 +1540,10 @@ quit: /* Ctrl-Alt-F should not open the File menu like Alt-f does. */ if (check_kbd_modifier(ev, KBD_MOD_ALT)) { - struct window *win; - - get_kbd_modifier(ev) &= ~KBD_MOD_ALT; - activate_bfu_technology(ses, -1); - win = ses->tab->term->windows.next; - win->handler(win, ev); - if (ses->tab->term->windows.next == win) { - deselect_mainmenu(win->term, win->data); - print_screen_status(ses); - } - if (!tabs_are_on_top(ses->tab->term)) { - /* The event opened a menu; we're done. */ + if (try_menu(ses, ev) != FRAME_EVENT_IGNORED) { + /* The BFU ate the key! */ return NULL; } - /* Otherwise, the event still needs to be handled. */ - get_kbd_modifier(ev) |= KBD_MOD_ALT; if (doc_view && get_opt_int("document.browse.accesskey"