all messages for Emacs-related lists mirrored at yhetil.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: Mon, 12 Oct 2020 14:30:38 -0700	[thread overview]
Message-ID: <8a6b6ce3f194ccf418709fe46ce0f1bb@finder.org> (raw)
In-Reply-To: <83362j4i58.fsf@gnu.org>

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

On 2020-10-12 7:45 am, Eli Zaretskii wrote:
>> Date: Sun, 11 Oct 2020 20:25:13 -0700
>> From: Jared Finder <jared@finder.org>
>> Cc: emacs-devel@gnu.org
>> 
>> -(defun menu-bar-open-mouse (event)
>> +(defun menu-bar-open-mouse (position)
>>    "Open the menu bar for the menu item clicked on by the mouse.
>> -EVENT should be a mouse down or click event.
>> +POSITION should be a list of the form returned by `mouse-position'.
>> 
>>  Also see `menu-bar-open', which this calls.
>>  This command is to be used when you click the mouse in the menubar."
>> -  (interactive "e")
>> -  (let* ((x-position (car (posn-x-y (event-start event))))
>> +  (interactive (list (mouse-position)))
>> +  (let* ((x-position (cadr position))
> 
> I'd prefer not to lose the "e" interactive spec and the form of the
> argument here.  If the problem is the conversion of window-relative to
> frame-relative coordinates, that is easy, and the ELisp manual has an
> example of how to do that in the node "Accessing Mouse".
> 
> Or is there some problem to use this here?

Thanks, I investigated further and I have an improved patch attached.  
In addition to keeping the same interactive spec, it also is logically 
independent of my changes to enable xterm-mouse based menu interaction.  
I also attached repro.el, which I used to help understand the behavior 
of xterm-mouse.

The manual is not clear of the format of a posn for clicks outside a 
window, such as on the menu bar or tab bar. From the behavior I see, 
posn-window will return nil and posn-x-y will return (x . y) in frame 
coordinates. I rely on that in this patch. If this is accurate, I can 
update the manual.

   -- MJF

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fixing-bug-where-the-wrong-menu-would-be-triggered-b.patch --]
[-- Type: text/x-diff; name=0001-Fixing-bug-where-the-wrong-menu-would-be-triggered-b.patch, Size: 2406 bytes --]

From c0ed41e742fe65573a14eaa02ebba9687b8cfc5b Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Sun, 11 Oct 2020 20:16:00 -0700
Subject: [PATCH] Fixing bug where the wrong menu would be triggered by mouse.

For layouts such as the following, clicking the "l" in Tools with the
right window focused would trigger the File menu, not the Tools menu.
This is because the event would have window coordinate (1 . 0).
Similarly, clicking the "p" in Help would trigger the Edit menu.

Example Emacs frame:
+--------------------------------------------------------+
|File Edit Options Buffers Tools Help                    |
|;; This buffer is for text$|;; This buffer is for text $|
|;; To create a file, visit$|;; To create a file, visit $|
|                           |                            |
|                           |                            |
|-UUU:----F1  *scratch*     |-UUU:----F1  *scratch*      |
|                                                        |
+--------------------------------------------------------+
---
 lisp/menu-bar.el | 6 ++++++
 lisp/xt-mouse.el | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 22fae028d3..3df72ea0f0 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -2669,6 +2669,12 @@ menu-bar-open-mouse
 Also see `menu-bar-open', which this calls.
 This command is to be used when you click the mouse in the menubar."
   (interactive "e")
+  ;; This only should be bound to clicks on the menu-bar, outside of
+  ;; any window.
+  (let ((window (posn-window (event-start event))))
+    (when window
+      (error "Event is inside window %s" window)))
+
   (let* ((x-position (car (posn-x-y (event-start event))))
          (menu-bar-item-cons (menu-bar-item-at-x x-position)))
     (menu-bar-open nil
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el
index e838219960..be261cebab 100644
--- a/lisp/xt-mouse.el
+++ b/lisp/xt-mouse.el
@@ -267,7 +267,7 @@ xterm-mouse-event
                                                     (eq y 1)))
                                            'tab-bar
                                          'menu-bar))
-                             (nthcdr 2 (posn-at-x-y x y)))))
+                             (nthcdr 2 (posn-at-x-y x y (selected-frame))))))
              (event (list type posn)))
         (setcar (nthcdr 3 posn) timestamp)
 
-- 
2.20.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: repro.el --]
[-- Type: text/x-lisp; name=repro.el, Size: 1380 bytes --]

;; This file exists to help understand xterm-mouse's bug. It is *not*
;; dependent on xterm-mouse-mode being enabled.
;;
;; Try running (test-xterm-coord-x) both with and without the text
;; marked "From patch:" enabled.

(defun test-xterm-coord-x ()
  (let (l0 ; menu bar
	l1 ; first row
	)
    (dotimes (x (frame-width))
      (push (posn-x-y (xterm-coords-to-posn x 0)) l0)
      (push (posn-x-y (xterm-coords-to-posn x 1)) l1))
    (list (mapcar 'car (nreverse l0))
	  (mapcar 'car (nreverse l1)))))

(defun test-xterm-coord-w ()
  (let (l0 ; menu bar
	l1 ; first row
	)
    (dotimes (x (frame-width))
      (push (posn-window (xterm-coords-to-posn x 0)) l0)
      (push (posn-window (xterm-coords-to-posn x 1)) l1))
    (list (nreverse l0) (nreverse l1))))
	    

(defun xterm-coords-to-posn (x y)
  "posn creation parts of `xterm-mouse-event'."
  (let* ((w (window-at x y))
	 (ltrb (window-edges w))
	 (left (nth 0 ltrb))
	 (top (nth 1 ltrb))
	 (posn (if w
		   (posn-at-x-y (- x left) (- y top) w t)
                 (append (list nil (if (and tab-bar-mode
					    (or (not menu-bar-mode)
						;; The tab-bar is on the
						;; second row below menu-bar
						(eq y 1)))
				       'tab-bar
				     'menu-bar))
			 (nthcdr 2 (posn-at-x-y x y ;From patch: (selected-frame)
                                                ))))))
    (setcar (nthcdr 3 posn) -1)
    posn))

  reply	other threads:[~2020-10-12 21:30 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.
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. [this message]
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

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

  git send-email \
    --in-reply-to=8a6b6ce3f194ccf418709fe46ce0f1bb@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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.