From 2b71048614be65eb9c4267224a0606bfcd86cc8a 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. * Update xt-mouse.el to use SET_ANY_EVENT_MOUSE (1003) so mouse movement is always reported. * Hook up mouse_get_xy to mouse-position so it works with xterm mouse. * (WIP) Properly handle mouse-movement events in all the possible prefixes, such as menu-bar or mode-line. --- lisp/menu-bar.el | 10 ++++++++++ lisp/xt-mouse.el | 10 +++++----- src/term.c | 28 ++++++++++++++++++---------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 9021be8eff..44de6e7c32 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2758,6 +2758,16 @@ tty-menu-navigation-map (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) + + ;; These are needed because xterm-mouse always sends events with + ;; special prefixes. + ;; + ;; TODO -- either make xterm-mouse not use the special prefixes or + ;; fix all "prefix-thingy mouse-movement is undefined" with + ;; special prefixes. + (define-key map [header-line mouse-movement] 'tty-menu-mouse-movement) + (define-key map [menu-bar mouse-movement] 'tty-menu-mouse-movement) + (define-key map [mode-line 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..ae6f85f1f7 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -339,7 +339,7 @@ xterm-mouse-tracking-enable-sequence position (<= 223), which can be reported in this basic mode. -\"\\e[?1002h\" \"Mouse motion mode\": Enables reports for mouse +\"\\e[?1003h\" \"Mouse motion mode\": Enables reports for mouse motion events during dragging operations. \"\\e[?1005h\" \"UTF-8 coordinate extension\": Enables an @@ -360,7 +360,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,7 +371,7 @@ xterm-mouse-tracking-enable-sequence position (<= 223), which can be reported in this basic mode. -\"\\e[?1002h\" \"Mouse motion mode\": Enables reports for mouse +\"\\e[?1003h\" \"Mouse motion mode\": Enables reports for mouse motion events during dragging operations. \"\\e[?1005h\" \"UTF-8 coordinate extension\": Enables an extension @@ -400,7 +400,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 +414,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..1196609047 100644 --- a/src/term.c +++ b/src/term.c @@ -2481,6 +2481,16 @@ term_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, *bar_window = Qnil; *part = scroll_bar_above_handle; + // xterm-mouse always stores the mouse positions in terminal + // parameters. Existing code path (GPM?) does not. + // + // TODO: Figure out the right way to unify these code paths. + if (true) + { + last_mouse_x = XFIXNUM (Fterminal_parameter (Qnil, intern ("xterm-mouse-x"))); + last_mouse_y = XFIXNUM (Fterminal_parameter (Qnil, intern ("xterm-mouse-y"))); + } + XSETINT (*x, last_mouse_x); XSETINT (*y, last_mouse_y); *timeptr = current_Time (); @@ -2804,16 +2814,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