From: Jared Finder via "Emacs development discussions." <emacs-devel@gnu.org>
To: emacs-devel@gnu.org
Subject: Making TTY menus more visual
Date: Thu, 01 Oct 2020 23:16:49 -0700 [thread overview]
Message-ID: <087df85a965fac6555a755c1bbebf1ea@finder.org> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 733 bytes --]
Hi lovely developers, I'm a long time Emacs user, first time Emacs patch
submitter. :)
Right now in Emacs on a TTY, clicking on the menu bar with the mouse
pops up menu navigation through tmm.el. I think it would make more
sense for mouse clicks to pop up visual menus via menu-bar-open-mouse by
default.
But I get why that's not the current default. These visual menus
currently behave very poorly with a mouse on a Linux TTY: Clicking
<mouse-1> anywhere selects the currently selected item, not the item you
clicked on. I have a prototype fix for this that I've been working on.
If you think it makes sense, I can finish it up. I've attached the
changes in case you want to take a look.
Let me know your thoughts.
-- MJF
[-- Attachment #1.2: Type: text/html, Size: 965 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Adding-mouse-controls-to-menu-bar.el.patch --]
[-- Type: text/x-diff; name=0001-Adding-mouse-controls-to-menu-bar.el.patch, Size: 4392 bytes --]
From 9972ca4995e2e43cfaff9b550f2b73c72ae76bb6 Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Sat, 19 Sep 2020 00:43:29 -0700
Subject: [PATCH 1/2] Adding mouse controls to menu-bar.el.
---
| 12 +++++++++
lisp/tmm.el | 64 ++++++++++++++++++++++++++++--------------------
2 files changed, 50 insertions(+), 26 deletions(-)
--git a/lisp/menu-bar.el b/lisp/menu-bar.el
index d3e434aec9..9021be8eff 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -2660,6 +2660,18 @@ menu-bar-open
(global-set-key [f10] 'menu-bar-open)
+(defun menu-bar-open-mouse (event)
+ "Mosue-triggered version of `menu-bar-open'.
+This command is to be used when you click the mouse in the menubar."
+ (interactive "e")
+ (require 'tmm) ; Possibly have tmm depend on menu-bar instead?
+ (let* ((x-position (car (posn-x-y (event-start event))))
+ (menu-bar-item-cons (tmm-menubar-item-at-x x-position)))
+ (menu-bar-open nil
+ (if menu-bar-item-cons
+ (cdr menu-bar-item-cons)
+ 0))))
+
(defun buffer-menu-open ()
"Start key navigation of the buffer menu.
This is the keyboard interface to \\[mouse-buffer-menu]."
diff --git a/lisp/tmm.el b/lisp/tmm.el
index 1e18c8b4ae..710295c776 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -59,6 +59,40 @@ tmm-menubar-keymap
(tmm-get-keybind [menu-bar]))
`(keymap ,@(nreverse menu-bar) ,@menu-end)))
+(defun tmm-menubar-item-at-x (x-position)
+ "Return a cons of the form (KEY . X) for the item clicked on.
+
+If nothing is clicked on, returns nil."
+ (let ((column 0)
+ (menu-bar (tmm-menubar-keymap))
+ prev-key
+ prev-column
+ found)
+ (catch 'done
+ (map-keymap
+ (lambda (key binding)
+ (when (> column x-position)
+ (setq found t)
+ (throw 'done nil))
+ (setq prev-key key)
+ (pcase binding
+ ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item.
+ `(menu-item ,name ,_cmd ;Extended menu item.
+ . ,(and props
+ (guard (let ((visible
+ (plist-get props :visible)))
+ (or (null visible)
+ (eval visible)))))))
+ (setq prev-column column
+ column (+ column (length name) 1)))))
+ menu-bar)
+ ;; Check the last menu item.
+ (when (> column x-position)
+ (setq found t)))
+ (if found
+ (cons prev-key prev-column)
+ nil)))
+
;;;###autoload (define-key global-map "\M-`" 'tmm-menubar)
;;;###autoload (define-key global-map [menu-bar mouse-1] 'tmm-menubar-mouse)
@@ -74,33 +108,11 @@ tmm-menubar
`tty-menu-open-use-tmm' to a non-nil value."
(interactive)
(run-hooks 'menu-bar-update-hook)
- ;; Obey menu-bar-final-items; put those items last.
(let ((menu-bar (tmm-menubar-keymap))
- menu-bar-item)
- (if x-position
- (let ((column 0)
- prev-key)
- (catch 'done
- (map-keymap
- (lambda (key binding)
- (when (> column x-position)
- (setq menu-bar-item prev-key)
- (throw 'done nil))
- (setq prev-key key)
- (pcase binding
- ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item.
- `(menu-item ,name ,_cmd ;Extended menu item.
- . ,(and props
- (guard (let ((visible
- (plist-get props :visible)))
- (or (null visible)
- (eval visible)))))))
- (setq column (+ column (length name) 1)))))
- menu-bar)
- ;; Check the last menu item.
- (when (> column x-position)
- (setq menu-bar-item prev-key)))))
- (tmm-prompt menu-bar nil menu-bar-item)))
+ (menu-bar-item-cons (tmm-menubar-item-at-x x-position)))
+ (tmm-prompt menu-bar
+ nil
+ (and menu-bar-item-cons (car menu-bar-item-cons)))))
;;;###autoload
(defun tmm-menubar-mouse (event)
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-WIP-Adding-mouse-navigation-of-tty-menus.patch --]
[-- Type: text/x-diff; name=0002-WIP-Adding-mouse-navigation-of-tty-menus.patch, Size: 2408 bytes --]
From 756c297535ed10534973e84387419ea7d728938e Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Thu, 1 Oct 2020 00:48:19 -0700
Subject: [PATCH 2/2] WIP: Adding mouse navigation of tty menus.
---
src/term.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/term.c b/src/term.c
index 3677644845..8167763e84 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3101,7 +3101,27 @@ read_menu_input (struct frame *sf, int *x, int *y, int min_y, int max_y,
st = MI_SCROLL_BACK;
}
else if (EQ (cmd, Qtty_menu_select))
- st = MI_ITEM_SELECTED;
+ {
+ // Remaining to do:
+ // * Add new symbol "tty-menu-mouse-select-or-dismiss", bind to mouse buttons.
+ // * If click is in visible menu act as if tty-menu-select, otherwise act as if tty-menu-exit.
+ // * Ensure logic works with any menu popup position.
+ Lisp_Object posn_x_y = CALLN (Ffuncall, intern ("posn-x-y"),
+ CALLN (Ffuncall, intern ("event-start"), last_nonmenu_event));
+ int mouse_x = XFIXNUM (Fcar (posn_x_y));
+ int mouse_y = XFIXNUM (Fcdr (posn_x_y));
+ message ("In read_menu_input: tty_menu_select w/ mouse_x=%d, mouse_y=%d, min_y=%d, max_y=%d",
+ mouse_x, mouse_y, min_y, max_y);
+
+ // Unclear offset -- need to figure this out. Perhaps due to menu-bar?
+ mouse_y++;
+ if (mouse_y >= min_y && mouse_y <= max_y)
+ {
+ *y = mouse_y;
+ }
+
+ st = MI_ITEM_SELECTED;
+ }
else if (!EQ (cmd, Qtty_menu_ignore))
usable_input = 0;
if (usable_input)
@@ -3224,6 +3244,9 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
int max_y = min (min_y + state[0].menu->count, FRAME_TOTAL_LINES (sf) - 1) - 1;
input_status = read_menu_input (sf, &x, &y, min_y, max_y, &first_time);
+
+ message("In tty_menu_activate: read_menu_input --> input_status=%d, x=%d, y=%d, first_time=%d",
+ input_status, x, y, first_time);
if (input_status)
{
leave = 1;
@@ -3369,6 +3392,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
clear_input_pending ();
SAFE_FREE ();
Vinhibit_redisplay = prev_inhibit_redisplay;
+ message ("Returning result=%d", result);
return result;
}
--
2.20.1
next reply other threads:[~2020-10-02 6:16 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 6:16 Jared Finder via Emacs development discussions. [this message]
2020-10-02 7:31 ` Making TTY menus more visual 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.
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=087df85a965fac6555a755c1bbebf1ea@finder.org \
--to=emacs-devel@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).