From a8831a847059a448dda1d4502d5b8f486b6bf0e5 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Sat, 3 Oct 2020 14:46:30 -0700 Subject: [PATCH 2/2] Making TTY menus work with xterm-mouse-mode. * xt-mouse.el uses SET_ANY_EVENT_MOUSE (1003) so mouse movement can be reported even if no buttons are pressed. * xt-mouse.el now respects track-mouse. It previously did not need to since mouse movement was only reported if a mouse button was pressed. * Hook up mouse_get_xy to mouse-position so it works with xterm mouse. * tty-navigation-map handles all the different prefixes mouse events can have, such as menu-bar or mode-line. --- lisp/menu-bar.el | 64 +++++++++++++++++++++++++----------------------- lisp/xt-mouse.el | 20 +++++++++------ src/term.c | 18 ++++++-------- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 4a0a27415b..df27b6d456 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2753,6 +2753,16 @@ mouse-buffer-menu-keymap (menu-bar-buffer-vector item))))) km)) +(defun menu-bar-define-mouse-key (map key def) + "Like `define-key', but adds all possible prefixes for the mouse." + (define-key map (vector key) def) + (mapc (lambda (prefix) (define-key map (vector prefix key) def)) + ;; This list only needs to contain special window areas that + ;; are rendered in TTYs. No need for *-scroll-bar, *-fringe, or + ;; *-divider. + '(tab-line header-line menu-bar tab-bar mode-line vertical-line + left-margin right-margin))) + (defvar tty-menu-navigation-map (let ((map (make-sparse-keymap))) ;; The next line is disabled because it breaks interpretation of @@ -2787,39 +2797,33 @@ tty-menu-navigation-map (define-key map [?\C-j] 'tty-menu-select) (define-key map [return] 'tty-menu-select) (define-key map [linefeed] 'tty-menu-select) - (define-key map [mouse-1] 'tty-menu-select) - (define-key map [drag-mouse-1] 'tty-menu-select) - (define-key map [mouse-2] 'tty-menu-select) - (define-key map [drag-mouse-2] 'tty-menu-select) - (define-key map [mouse-3] 'tty-menu-select) - (define-key map [drag-mouse-3] 'tty-menu-select) - (define-key map [wheel-down] 'tty-menu-next-item) - (define-key map [wheel-up] 'tty-menu-prev-item) - (define-key map [wheel-left] 'tty-menu-prev-menu) - (define-key map [wheel-right] 'tty-menu-next-menu) - ;; The following 4 bindings are for those whose text-mode mouse + (menu-bar-define-mouse-key map 'mouse-1 'tty-menu-select) + (menu-bar-define-mouse-key map 'drag-mouse-1 'tty-menu-select) + (menu-bar-define-mouse-key map 'mouse-2 'tty-menu-select) + (menu-bar-define-mouse-key map 'drag-mouse-2 'tty-menu-select) + (menu-bar-define-mouse-key map 'mouse-3 'tty-menu-select) + (menu-bar-define-mouse-key map 'drag-mouse-3 'tty-menu-select) + (menu-bar-define-mouse-key map 'wheel-down 'tty-menu-next-item) + (menu-bar-define-mouse-key map 'wheel-up 'tty-menu-prev-item) + (menu-bar-define-mouse-key map 'wheel-left 'tty-menu-prev-menu) + (menu-bar-define-mouse-key map 'wheel-right 'tty-menu-next-menu) + ;; The following 6 bindings are for those whose text-mode mouse ;; lack the wheel. - (define-key map [S-mouse-1] 'tty-menu-next-item) - (define-key map [S-drag-mouse-1] 'tty-menu-next-item) - (define-key map [S-mouse-2] 'tty-menu-prev-item) - (define-key map [S-drag-mouse-2] 'tty-menu-prev-item) - (define-key map [S-mouse-3] 'tty-menu-prev-item) - (define-key map [S-drag-mouse-3] 'tty-menu-prev-item) - (define-key map [header-line mouse-1] 'tty-menu-select) - (define-key map [header-line drag-mouse-1] 'tty-menu-select) + (menu-bar-define-mouse-key map 'S-mouse-1 'tty-menu-next-item) + (menu-bar-define-mouse-key map 'S-drag-mouse-1 'tty-menu-next-item) + (menu-bar-define-mouse-key map 'S-mouse-2 'tty-menu-prev-item) + (menu-bar-define-mouse-key map 'S-drag-mouse-2 'tty-menu-prev-item) + (menu-bar-define-mouse-key map 'S-mouse-3 'tty-menu-prev-item) + (menu-bar-define-mouse-key map 'S-drag-mouse-3 'tty-menu-prev-item) ;; The down-mouse events must be bound to tty-menu-ignore, so that ;; only releasing the mouse button pops up the menu. - (define-key map [mode-line down-mouse-1] 'tty-menu-ignore) - (define-key map [mode-line down-mouse-2] 'tty-menu-ignore) - (define-key map [mode-line down-mouse-3] 'tty-menu-ignore) - (define-key map [mode-line C-down-mouse-1] 'tty-menu-ignore) - (define-key map [mode-line C-down-mouse-2] 'tty-menu-ignore) - (define-key map [mode-line C-down-mouse-3] 'tty-menu-ignore) - (define-key map [down-mouse-1] 'tty-menu-ignore) - (define-key map [C-down-mouse-1] 'tty-menu-ignore) - (define-key map [C-down-mouse-2] 'tty-menu-ignore) - (define-key map [C-down-mouse-3] 'tty-menu-ignore) - (define-key map [mouse-movement] 'tty-menu-mouse-movement) + (menu-bar-define-mouse-key map 'down-mouse-1 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'down-mouse-2 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'down-mouse-3 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'C-down-mouse-1 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'C-down-mouse-2 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'C-down-mouse-3 'tty-menu-ignore) + (menu-bar-define-mouse-key map 'mouse-movement 'tty-menu-mouse-movement) map) "Keymap used while processing TTY menus.") diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el index 362d29b943..5410aafb3b 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -76,7 +76,11 @@ xterm-mouse-translate-1 ;; to guard against that. (copy-sequence event)) vec) - (is-move vec) + (is-move + (if track-mouse vec + ;; Mouse movement events are currently supposed to be + ;; suppressed. Return no event. + [])) (t (let* ((down (terminal-parameter nil 'xterm-mouse-last-down)) (down-data (nth 1 down)) @@ -339,8 +343,8 @@ xterm-mouse-tracking-enable-sequence position (<= 223), which can be reported in this basic mode. -\"\\e[?1002h\" \"Mouse motion mode\": Enables reports for mouse - motion events during dragging operations. +\"\\e[?1003h\" \"Mouse motion mode\": Enables reports for mouse + motion events. \"\\e[?1005h\" \"UTF-8 coordinate extension\": Enables an extension to the basic mouse mode, which uses UTF-8 @@ -360,7 +364,7 @@ xterm-mouse-tracking-enable-sequence (apply #'concat (xterm-mouse--tracking-sequence ?h))) (defconst xterm-mouse-tracking-enable-sequence - "\e[?1000h\e[?1002h\e[?1005h\e[?1006h" + "\e[?1000h\e[?1003h\e[?1005h\e[?1006h" "Control sequence to enable xterm mouse tracking. Enables basic mouse tracking, mouse motion events and finally extended tracking on terminals that support it. The following @@ -371,8 +375,8 @@ xterm-mouse-tracking-enable-sequence position (<= 223), which can be reported in this basic mode. -\"\\e[?1002h\" \"Mouse motion mode\": Enables reports for mouse - motion events during dragging operations. +\"\\e[?1003h\" \"Mouse motion mode\": Enables reports for mouse + motion events. \"\\e[?1005h\" \"UTF-8 coordinate extension\": Enables an extension to the basic mouse mode, which uses UTF-8 @@ -400,7 +404,7 @@ xterm-mouse-tracking-disable-sequence (apply #'concat (nreverse (xterm-mouse--tracking-sequence ?l)))) (defconst xterm-mouse-tracking-disable-sequence - "\e[?1006l\e[?1005l\e[?1002l\e[?1000l" + "\e[?1006l\e[?1005l\e[?1003l\e[?1000l" "Reset the modes set by `xterm-mouse-tracking-enable-sequence'.") (make-obsolete-variable @@ -414,7 +418,7 @@ xterm-mouse--tracking-sequence enable, ?l to disable)." (mapcar (lambda (code) (format "\e[?%d%c" code suffix)) - `(1000 1002 ,@(when xterm-mouse-utf-8 '(1005)) 1006))) + `(1000 1003 ,@(when xterm-mouse-utf-8 '(1005)) 1006))) (defun turn-on-xterm-mouse-tracking-on-terminal (&optional terminal) "Enable xterm mouse tracking on TERMINAL." diff --git a/src/term.c b/src/term.c index 3677644845..564d55be5b 100644 --- a/src/term.c +++ b/src/term.c @@ -2804,16 +2804,14 @@ tty_menu_calc_size (tty_menu *menu, int *width, int *height) static void mouse_get_xy (int *x, int *y) { - struct frame *sf = SELECTED_FRAME (); - Lisp_Object lmx = Qnil, lmy = Qnil, lisp_dummy; - enum scroll_bar_part part_dummy; - Time time_dummy; - - if (FRAME_TERMINAL (sf)->mouse_position_hook) - (*FRAME_TERMINAL (sf)->mouse_position_hook) (&sf, -1, - &lisp_dummy, &part_dummy, - &lmx, &lmy, - &time_dummy); + Lisp_Object lmx = Qnil, lmy = Qnil, mouse_position = Fmouse_position (); + + if (EQ (selected_frame, XCAR(mouse_position))) + { + lmx = XCAR (XCDR (mouse_position)); + lmy = XCDR (XCDR (mouse_position)); + } + if (!NILP (lmx)) { *x = XFIXNUM (lmx); -- 2.20.1