unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jared Finder via "Emacs development discussions." <emacs-devel@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Making TTY menus more visual
Date: Sat, 03 Oct 2020 15:28:23 -0700	[thread overview]
Message-ID: <72bbff31bcf46be917c9e8d8236cad75@finder.org> (raw)
In-Reply-To: <85afa5c0a0a789c6047e92f6ecfa9fcc@finder.org>

[-- Attachment #1: Type: text/plain, Size: 2092 bytes --]

On 2020-10-03 12:26 pm, Jared Finder wrote:
> On 2020-10-03 1:50 am, Eli Zaretskii wrote:
>>> Date: Fri, 02 Oct 2020 17:16:55 -0700
>>> From: Jared Finder <jared@finder.org>
>>> Cc: emacs-devel@gnu.org
>>> 
>>> Also, a user may click outside of the popped up menu, which they
>>> would expect to dismiss the menu. (this is patch 002 in the root of
>>> the thread, not yet complete)
>> 
>> This should already work; it does in the MS-Windows build when Emacs
>> is invoked with -nw.  Please tell more why you think any changes there
>> are needed.  Perhaps you could take me through the code there and
>> explain what is missing and why.  (And why do you call posn-x-y in the
>> patch when X and Y are already known and used by that code? is that
>> because mouse_get_xy does not yet support xterm-mouse? if so, that
>> support should be added via the terminal's mouse_position_hook.)
> 
> From injecting debug logs into read_menu_input, I can observe that
> tty-menu-mouse-movement is never received so the highlighted item
> never changes except due to keyboard input. And from tracing
> xterm-mouse--read-event-sequence, it appears that Emacs normally does
> not receive xterm mouse motion events unless a button is pressed.
> 
> This appears to be due to xt-mouse sending event code 1002 instead of
> 1003 (see
> https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking).
> 
> Just sending 1003 instead doesn't just work, but I do see mouse events
> now coming through. Let me do some more investigation here and I will
> get back to you.

It wasn't that much more work to get xterm-mouse to work. I've attached 
an updated patch.

I have just one question, corresponding to the remaining TODO:

Now there are newly emitted events for mouse-movement that are not 
handled such as "<mode-line> <mouse-movement>" or "<vertical-line> 
<mouse-movement>". It'd be easy enough to bind all of these to ignore 
and further update tty-menu-navigation-map to have more cases, but is 
that the right solution? I'm surprised that only xterm-mouse would run 
into this case.

   -- MJF

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Making-TTY-menus-work-with-xterm-mouse-mode.patch --]
[-- Type: text/x-diff; name=0002-Making-TTY-menus-work-with-xterm-mouse-mode.patch, Size: 5208 bytes --]

From 2b71048614be65eb9c4267224a0606bfcd86cc8a Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
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


  reply	other threads:[~2020-10-03 22:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02  6:16 Making TTY menus more visual Jared Finder via Emacs development discussions.
2020-10-02  7:31 ` Eli Zaretskii
2020-10-03  0:16   ` Jared Finder via Emacs development discussions.
2020-10-03  8:50     ` Eli Zaretskii
2020-10-03 19:26       ` Jared Finder via Emacs development discussions.
2020-10-03 22:28         ` Jared Finder via Emacs development discussions. [this message]
2020-10-03 23:25           ` Jared Finder via Emacs development discussions.
2020-10-04  6:43           ` Eli Zaretskii
2020-10-04  9:04             ` Eli Zaretskii
2020-10-05  5:36               ` Jared Finder via Emacs development discussions.
2020-10-05  6:45                 ` Eli Zaretskii
2020-10-08  6:39                   ` Jared Finder via Emacs development discussions.
2020-10-08  8:15                     ` Eli Zaretskii
2020-10-09  5:17                       ` Jared Finder via Emacs development discussions.
2020-10-09 15:02                         ` Eli Zaretskii
2020-10-10  5:20                           ` Jared Finder via Emacs development discussions.
2020-10-10  7:28                             ` Eli Zaretskii
2020-10-12  3:25                               ` Jared Finder via Emacs development discussions.
2020-10-12 14:45                                 ` Eli Zaretskii
2020-10-12 21:30                                   ` Jared Finder via Emacs development discussions.
2020-10-13 14:33                                     ` Eli Zaretskii
2020-10-14  1:59                                       ` Jared Finder via Emacs development discussions.
2020-10-15 13:34                                         ` Eli Zaretskii
2020-10-16  6:51                                           ` Eli Zaretskii
2020-10-16 16:18                                             ` Jared Finder via Emacs development discussions.
2020-10-24 10:31                                     ` Eli Zaretskii
2020-10-25  0:27                                       ` Jared Finder via Emacs development discussions.
2020-10-31  8:05                                         ` Eli Zaretskii
2020-10-24 10:25                               ` Eli Zaretskii
2020-10-04  6:22         ` Eli Zaretskii
2020-10-04  6:24         ` Eli Zaretskii
2020-10-04 22:15           ` Jared Finder via Emacs development discussions.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72bbff31bcf46be917c9e8d8236cad75@finder.org \
    --to=emacs-devel@gnu.org \
    --cc=eliz@gnu.org \
    --cc=jared@finder.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).