all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Making TTY menus more visual
@ 2020-10-02  6:16 Jared Finder via Emacs development discussions.
  2020-10-02  7:31 ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Jared Finder via Emacs development discussions. @ 2020-10-02  6:16 UTC (permalink / raw)
  To: emacs-devel


[-- 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.

---
 lisp/menu-bar.el | 12 +++++++++
 lisp/tmm.el      | 64 ++++++++++++++++++++++++++++--------------------
 2 files changed, 50 insertions(+), 26 deletions(-)

diff --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


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2020-10-31  8:05 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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.
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.

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.