diff options
| author | Eli Zaretskii | 2013-09-23 16:15:29 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-09-23 16:15:29 +0300 |
| commit | df78230943690aa2d95e22f947615c09d2c676e8 (patch) | |
| tree | b5f532ce7ffe84cdb4a177cfab3ef0bcc433673b | |
| parent | 7ace926507379e836df263c4a0310eed285181c6 (diff) | |
| download | emacs-df78230943690aa2d95e22f947615c09d2c676e8.tar.gz emacs-df78230943690aa2d95e22f947615c09d2c676e8.zip | |
Use overriding-terminal-local-map for menu navigation.
| -rw-r--r-- | lisp/menu-bar.el | 48 | ||||
| -rw-r--r-- | src/term.c | 67 |
2 files changed, 87 insertions, 28 deletions
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 0da430140d7..5cc79b9358e 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el | |||
| @@ -2255,6 +2255,54 @@ If nil, the current mouse position is used." | |||
| 2255 | (popup-menu-normalize-position (event-end position))) | 2255 | (popup-menu-normalize-position (event-end position))) |
| 2256 | (t position))) | 2256 | (t position))) |
| 2257 | 2257 | ||
| 2258 | (defvar tty-menu-navigation-map | ||
| 2259 | (let ((map (make-sparse-keymap))) | ||
| 2260 | ;; The tty-menu-* are just symbols interpreted by term.c, they are | ||
| 2261 | ;; not real commands. | ||
| 2262 | (define-key map [t] 'tty-menu-exit) | ||
| 2263 | (substitute-key-definition 'forward-char 'tty-menu-next-menu | ||
| 2264 | map (current-global-map)) | ||
| 2265 | (substitute-key-definition 'backward-char 'tty-menu-prev-menu | ||
| 2266 | map (current-global-map)) | ||
| 2267 | ;; The following two will need to be revised if we ever support | ||
| 2268 | ;; a right-to-left menu bar. | ||
| 2269 | (substitute-key-definition 'right-char 'tty-menu-next-menu | ||
| 2270 | map (current-global-map)) | ||
| 2271 | (substitute-key-definition 'left-char 'tty-menu-prev-menu | ||
| 2272 | map (current-global-map)) | ||
| 2273 | (substitute-key-definition 'next-line 'tty-menu-next-item | ||
| 2274 | map (current-global-map)) | ||
| 2275 | (substitute-key-definition 'previous-line 'tty-menu-prev-item | ||
| 2276 | map (current-global-map)) | ||
| 2277 | (substitute-key-definition 'newline 'tty-menu-select | ||
| 2278 | map (current-global-map)) | ||
| 2279 | (substitute-key-definition 'newline-and-indent 'tty-menu-select | ||
| 2280 | map (current-global-map)) | ||
| 2281 | (define-key map [?\C-r] 'tty-menu-select) | ||
| 2282 | (define-key map [?\C-j] 'tty-menu-select) | ||
| 2283 | (define-key map [return] 'tty-menu-select) | ||
| 2284 | (define-key map [linefeed] 'tty-menu-select) | ||
| 2285 | (define-key map [down-mouse-1] 'tty-menu-select) | ||
| 2286 | (define-key map [drag-mouse-1] 'tty-menu-select) | ||
| 2287 | (define-key map [mode-line drag-mouse-1] 'tty-menu-select) | ||
| 2288 | (define-key map [mode-line down-mouse-1] 'tty-menu-select) | ||
| 2289 | (define-key map [header-line mouse-1] 'tty-menu-select) | ||
| 2290 | (define-key map [header-line drag-mouse-1] 'tty-menu-select) | ||
| 2291 | (define-key map [header-line down-mouse-1] 'tty-menu-select) | ||
| 2292 | (define-key map [mode-line mouse-1] 'tty-menu-ignore) | ||
| 2293 | (define-key map [mode-line mouse-2] 'tty-menu-ignore) | ||
| 2294 | (define-key map [mode-line mouse-3] 'tty-menu-ignore) | ||
| 2295 | (define-key map [mode-line C-mouse-1] 'tty-menu-ignore) | ||
| 2296 | (define-key map [mode-line C-mouse-2] 'tty-menu-ignore) | ||
| 2297 | (define-key map [mode-line C-mouse-3] 'tty-menu-ignore) | ||
| 2298 | (define-key map [mouse-1] 'tty-menu-ignore) | ||
| 2299 | (define-key map [C-mouse-1] 'tty-menu-ignore) | ||
| 2300 | (define-key map [C-mouse-2] 'tty-menu-ignore) | ||
| 2301 | (define-key map [C-mouse-3] 'tty-menu-ignore) | ||
| 2302 | map) | ||
| 2303 | "Keymap used while processing TTY menus.") | ||
| 2304 | |||
| 2305 | |||
| 2258 | ;; FIXME: Make this a defcustom! | 2306 | ;; FIXME: Make this a defcustom! |
| 2259 | (defvar tty-menu-open-use-tmm nil | 2307 | (defvar tty-menu-open-use-tmm nil |
| 2260 | "If non-nil, menu-bar-open on a TTY will invoke `tmm-menubar'.") | 2308 | "If non-nil, menu-bar-open on a TTY will invoke `tmm-menubar'.") |
diff --git a/src/term.c b/src/term.c index 26fa64da62d..4da5fd13905 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -2815,8 +2815,10 @@ static int menu_help_paneno, menu_help_itemno; | |||
| 2815 | 2815 | ||
| 2816 | static int menu_x, menu_y; | 2816 | static int menu_x, menu_y; |
| 2817 | 2817 | ||
| 2818 | static Lisp_Object Qright_char, Qleft_char, Qforward_char, Qbackward_char; | 2818 | static Lisp_Object Qtty_menu_navigation_map, Qtty_menu_exit; |
| 2819 | static Lisp_Object Qnext_line, Qprevious_line, Qnewline; | 2819 | static Lisp_Object Qtty_menu_prev_item, Qtty_menu_next_item; |
| 2820 | static Lisp_Object Qtty_menu_next_menu, Qtty_menu_prev_menu; | ||
| 2821 | static Lisp_Object Qtty_menu_select, Qtty_menu_ignore; | ||
| 2820 | 2822 | ||
| 2821 | typedef struct tty_menu_struct | 2823 | typedef struct tty_menu_struct |
| 2822 | { | 2824 | { |
| @@ -3158,7 +3160,8 @@ screen_update (struct frame *f, struct glyph_matrix *mtx) | |||
| 3158 | 3160 | ||
| 3159 | Value is -1 if C-g was pressed, zero otherwise. */ | 3161 | Value is -1 if C-g was pressed, zero otherwise. */ |
| 3160 | static int | 3162 | static int |
| 3161 | read_menu_input (struct frame *sf, int *x, int *y, bool *first_time) | 3163 | read_menu_input (struct frame *sf, int *x, int *y, int min_y, int max_y, |
| 3164 | bool *first_time) | ||
| 3162 | { | 3165 | { |
| 3163 | Lisp_Object c; | 3166 | Lisp_Object c; |
| 3164 | 3167 | ||
| @@ -3184,19 +3187,25 @@ read_menu_input (struct frame *sf, int *x, int *y, bool *first_time) | |||
| 3184 | cmd = read_menu_command (); | 3187 | cmd = read_menu_command (); |
| 3185 | } while NILP (cmd); | 3188 | } while NILP (cmd); |
| 3186 | 3189 | ||
| 3187 | if (EQ (cmd, Qt)) | 3190 | if (EQ (cmd, Qt) || EQ (cmd, Qtty_menu_exit)) |
| 3188 | return -1; | 3191 | return -1; |
| 3189 | if (EQ (cmd, Qright_char) || EQ (cmd, Qforward_char)) | 3192 | if (EQ (cmd, Qtty_menu_next_menu)) |
| 3190 | *x += 1; | 3193 | *x += 1; |
| 3191 | else if (EQ (cmd, Qleft_char) || EQ (cmd, Qbackward_char)) | 3194 | else if (EQ (cmd, Qtty_menu_prev_menu)) |
| 3192 | *x -= 1; | 3195 | *x -= 1; |
| 3193 | else if (EQ (cmd, Qnext_line)) | 3196 | else if (EQ (cmd, Qtty_menu_next_item)) |
| 3194 | *y += 1; | 3197 | { |
| 3195 | else if (EQ (cmd, Qprevious_line)) | 3198 | if (*y < max_y) |
| 3196 | *y -= 1; | 3199 | *y += 1; |
| 3197 | else if (EQ (cmd, Qnewline)) | 3200 | } |
| 3201 | else if (EQ (cmd, Qtty_menu_prev_item)) | ||
| 3202 | { | ||
| 3203 | if (*y > min_y) | ||
| 3204 | *y -= 1; | ||
| 3205 | } | ||
| 3206 | else if (EQ (cmd, Qtty_menu_select)) | ||
| 3198 | st = 1; | 3207 | st = 1; |
| 3199 | else | 3208 | else if (!EQ (cmd, Qtty_menu_ignore)) |
| 3200 | { | 3209 | { |
| 3201 | usable_input = 0; | 3210 | usable_input = 0; |
| 3202 | st = -1; | 3211 | st = -1; |
| @@ -3359,9 +3368,10 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, | |||
| 3359 | { | 3368 | { |
| 3360 | int mouse_button_count = 3; /* FIXME */ | 3369 | int mouse_button_count = 3; /* FIXME */ |
| 3361 | int input_status; | 3370 | int input_status; |
| 3371 | int min_y = state[0].y, max_y = min_y + state[0].menu->count - 1; | ||
| 3362 | 3372 | ||
| 3363 | if (!mouse_visible) mouse_on (); | 3373 | if (!mouse_visible) mouse_on (); |
| 3364 | input_status = read_menu_input (sf, &x, &y, &first_time); | 3374 | input_status = read_menu_input (sf, &x, &y, min_y, max_y, &first_time); |
| 3365 | if (input_status) | 3375 | if (input_status) |
| 3366 | { | 3376 | { |
| 3367 | if (input_status == -1) | 3377 | if (input_status == -1) |
| @@ -3737,19 +3747,19 @@ tty_menu_show (struct frame *f, int x, int y, int for_click, int keymaps, | |||
| 3737 | uly = dispheight - height; | 3747 | uly = dispheight - height; |
| 3738 | } | 3748 | } |
| 3739 | 3749 | ||
| 3740 | if (FRAME_HAS_MINIBUF_P (f) && uly+height > dispheight - 1) | 3750 | if (FRAME_HAS_MINIBUF_P (f) && uly+height > dispheight - 2) |
| 3741 | { | 3751 | { |
| 3742 | /* Move the menu away of the echo area, to avoid overwriting the | 3752 | /* Move the menu away of the echo area, to avoid overwriting the |
| 3743 | menu with help echo messages or vice versa. */ | 3753 | menu with help echo messages or vice versa. */ |
| 3744 | if (BUFFERP (echo_area_buffer[0]) && WINDOWP (echo_area_window)) | 3754 | if (BUFFERP (echo_area_buffer[0]) && WINDOWP (echo_area_window)) |
| 3745 | { | 3755 | { |
| 3746 | y -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window)); | 3756 | y -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window)) + 1; |
| 3747 | uly -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window)); | 3757 | uly -= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window)) + 1; |
| 3748 | } | 3758 | } |
| 3749 | else | 3759 | else |
| 3750 | { | 3760 | { |
| 3751 | y--; | 3761 | y -= 2; |
| 3752 | uly--; | 3762 | uly -= 2; |
| 3753 | } | 3763 | } |
| 3754 | } | 3764 | } |
| 3755 | 3765 | ||
| @@ -3774,9 +3784,9 @@ tty_menu_show (struct frame *f, int x, int y, int for_click, int keymaps, | |||
| 3774 | 3784 | ||
| 3775 | record_unwind_protect (tty_pop_down_menu, make_save_ptr (menu)); | 3785 | record_unwind_protect (tty_pop_down_menu, make_save_ptr (menu)); |
| 3776 | 3786 | ||
| 3777 | /* Help display under X won't work because XMenuActivate contains | 3787 | tty_menu_help_frame = f; /* FIXME: This seems unused. */ |
| 3778 | a loop that doesn't give Emacs a chance to process it. FIXME. */ | 3788 | specbind (Qoverriding_terminal_local_map, |
| 3779 | tty_menu_help_frame = f; | 3789 | Fsymbol_value (Qtty_menu_navigation_map)); |
| 3780 | status = tty_menu_activate (menu, &pane, &selidx, x, y, &datap, | 3790 | status = tty_menu_activate (menu, &pane, &selidx, x, y, &datap, |
| 3781 | tty_menu_help_callback); | 3791 | tty_menu_help_callback); |
| 3782 | entry = pane_prefix = Qnil; | 3792 | entry = pane_prefix = Qnil; |
| @@ -4609,11 +4619,12 @@ bigger, or it may make it blink, or it may do nothing at all. */); | |||
| 4609 | encode_terminal_src = NULL; | 4619 | encode_terminal_src = NULL; |
| 4610 | encode_terminal_dst = NULL; | 4620 | encode_terminal_dst = NULL; |
| 4611 | 4621 | ||
| 4612 | DEFSYM (Qright_char, "right-char"); | 4622 | DEFSYM (Qtty_menu_next_item, "tty-menu-next-item"); |
| 4613 | DEFSYM (Qleft_char, "left-char"); | 4623 | DEFSYM (Qtty_menu_prev_item, "tty-menu-prev-item"); |
| 4614 | DEFSYM (Qforward_char, "forward-char"); | 4624 | DEFSYM (Qtty_menu_next_menu, "tty-menu-next-menu"); |
| 4615 | DEFSYM (Qbackward_char, "backward-char"); | 4625 | DEFSYM (Qtty_menu_prev_menu, "tty-menu-prev-menu"); |
| 4616 | DEFSYM (Qprevious_line, "previous-line"); | 4626 | DEFSYM (Qtty_menu_select, "tty-menu-select"); |
| 4617 | DEFSYM (Qnext_line, "next-line"); | 4627 | DEFSYM (Qtty_menu_ignore, "tty-menu-ignore"); |
| 4618 | DEFSYM (Qnewline, "newline"); | 4628 | DEFSYM (Qtty_menu_exit, "tty-menu-exit"); |
| 4629 | DEFSYM (Qtty_menu_navigation_map, "tty-menu-navigation-map"); | ||
| 4619 | } | 4630 | } |