From: jared--- via "Emacs development discussions." <emacs-devel@gnu.org>
To: emacs-devel@gnu.org
Subject: Additional xterm-mouse cleanup
Date: Wed, 27 Jan 2021 22:32:21 -0800 [thread overview]
Message-ID: <fcdfa21db8bb72533b6af7c50c499012@finder.org> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 620 bytes --]
I've got four small patches for my continued work to make xterm-mouse
function better. #1 also makes Linux terminal function keys behave
better when running help-for-help and #2 and #3 both improve GPM-based
mouse behavior too.
I'd like feedback in particular on patch #4, which is small but in a
sensitive location -- it's one additional code line in read_key_sequence
along the input-decode-map path. I considered instead putting the change
as part of the other cleanup right after replay_sequence, but ultimately
thought that would be riskier and serve no additional purpose.
Let me know your thoughts.
-- MJF
[-- Attachment #1.2: Type: text/html, Size: 835 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-behavior-for-make-help-screen.patch --]
[-- Type: text/x-diff; name=0001-Improve-behavior-for-make-help-screen.patch, Size: 3188 bytes --]
From 77a23c82f46b22ff3d7644bb31c51e0e319f0312 Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Thu, 3 Dec 2020 22:42:05 -0800
Subject: [PATCH 1/4] Improve behavior for `make-help-screen'
* lisp/help-macro.el (make-help-screen): Don't read just the ESC in a
terminal escape sequence. Allow mouse wheel scroll of the help window.
---
lisp/help-macro.el | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/lisp/help-macro.el b/lisp/help-macro.el
index 791b10a878..15c17fdbdd 100644
--- a/lisp/help-macro.el
+++ b/lisp/help-macro.el
@@ -119,9 +119,16 @@ make-help-screen
(let ((minor-mode-map-alist nil))
(setcdr local-map ,helped-map)
(define-key local-map [t] 'undefined)
- ;; Make the scroll bar keep working normally.
- (define-key local-map [vertical-scroll-bar]
- (lookup-key global-map [vertical-scroll-bar]))
+ ;; Make scrolling commands keep working normally.
+ (dolist (key '(;; Clicks in the scrollbar
+ [vertical-scroll-bar]
+ ;; Mouse wheel events
+ [mouse-4] [mouse-5] [down-mouse-4]
+ [down-mouse-5]))
+ (define-key local-map key (lookup-key global-map key)))
+ ;; Make terminal escape sequences be fully read as
+ ;; well.
+ (define-key local-map "\e" nil)
(if three-step-help
(progn
(setq key (let ((overriding-local-map local-map))
@@ -148,8 +155,12 @@ make-help-screen
(help-mode)
(setq new-minor-mode-map-alist minor-mode-map-alist))
(goto-char (point-min))
- (while (or (memq char (append help-event-list
- (cons help-char '(?? ?\C-v ?\s ?\177 delete backspace vertical-scroll-bar ?\M-v))))
+ (while (or (memq (event-basic-type char)
+ (append help-event-list
+ (list help-char ?? ?\C-v ?\s ?\177
+ 'delete 'backspace
+ 'vertical-scroll-bar
+ 'mouse-4 'mouse-5 ?\M-v)))
(eq (car-safe char) 'switch-frame)
(equal key "\M-v"))
(condition-case nil
@@ -171,9 +182,11 @@ make-help-screen
"" ", or SPACE or DEL to scroll")))
char (aref key 0)))
- ;; If this is a scroll bar command, just run it.
- (when (eq char 'vertical-scroll-bar)
- (command-execute (lookup-key local-map key) nil key))))
+ ;; If this is a scroll bar or scroll wheel
+ ;; command, just run it.
+ (when (memq (event-basic-type char)
+ '(vertical-scroll-bar mouse-4 mouse-5))
+ (command-execute (lookup-key local-map key) nil key))))
;; We don't need the prompt any more.
(message "")
;; Mouse clicks are not part of the help feature,
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-lisp-tab-line.el-tab-line-new-tab-Use-tty-menus-when.patch --]
[-- Type: text/x-diff; name=0002-lisp-tab-line.el-tab-line-new-tab-Use-tty-menus-when.patch, Size: 1036 bytes --]
From d2ee448ffa70ddb02645f5397b727ae2b90e20ed Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Mon, 7 Dec 2020 22:44:32 -0800
Subject: [PATCH 2/4] * lisp/tab-line.el (tab-line-new-tab): Use tty menus when
supported.
---
lisp/tab-line.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 2726947a4c..9209f2d46e 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -651,7 +651,9 @@ tab-line-new-tab
(if (functionp tab-line-new-tab-choice)
(funcall tab-line-new-tab-choice)
(let ((tab-line-tabs-buffer-groups mouse-buffer-menu-mode-groups))
- (if (and (listp mouse-event) window-system) ; (display-popup-menus-p)
+ (if (and (listp mouse-event)
+ (display-popup-menus-p)
+ (not tty-menu-open-use-tmm))
(mouse-buffer-menu mouse-event) ; like (buffer-menu-open)
;; tty menu doesn't support mouse clicks, so use tmm
(tmm-prompt (mouse-buffer-menu-keymap))))))
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Support-mouse-autoselect-window-for-GPM-and-xterm-mo.patch --]
[-- Type: text/x-diff; name=0003-Support-mouse-autoselect-window-for-GPM-and-xterm-mo.patch, Size: 2567 bytes --]
From 3f4fe8dc4c1961dfa185a47c5256bf9103c90ff8 Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Sat, 23 Jan 2021 16:53:43 -0800
Subject: [PATCH 3/4] Support 'mouse-autoselect-window' for GPM and xterm mouse
* src/dispnew.c (update_mouse_position): Generate SELECT_WINDOW_EVENT.
---
src/dispnew.c | 32 ++++++++++++++++++++++++++++++--
src/w32term.c | 1 +
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/dispnew.c b/src/dispnew.c
index e603c67136..5dc4ac24db 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3335,11 +3335,39 @@ update_frame_with_menu (struct frame *f, int row, int col)
int
update_mouse_position (struct frame *f, int x, int y)
{
+ int event_count = 0;
+
previous_help_echo_string = help_echo_string;
help_echo_string = Qnil;
note_mouse_highlight (f, x, y);
+ /* When the mouse moves over a new window, generate a
+ SELECT_WINDOW_EVENT. */
+ if (!NILP (Vmouse_autoselect_window))
+ {
+ static Lisp_Object last_mouse_window;
+ Lisp_Object window = window_from_coordinates (f, x, y, 0, 0, 0);
+
+ /* Window will be selected only when it is not selected now and
+ last mouse movement event was not in it. Minibuffer window
+ will be selected only when it is active. */
+ if (WINDOWP (window)
+ && !EQ (window, last_mouse_window)
+ && !EQ (window, selected_window))
+ {
+ struct input_event event;
+ EVENT_INIT (event);
+ event.kind = SELECT_WINDOW_EVENT;
+ event.frame_or_window = window;
+ kbd_buffer_store_event (&event);
+ ++event_count;
+ }
+
+ /* Remember the last window where we saw the mouse. */
+ last_mouse_window = window;
+ }
+
/* If the contents of the global variable help_echo_string
has changed, generate a HELP_EVENT. */
if (!NILP (help_echo_string)
@@ -3350,10 +3378,10 @@ update_mouse_position (struct frame *f, int x, int y)
gen_help_event (help_echo_string, frame, help_echo_window,
help_echo_object, help_echo_pos);
- return 1;
+ ++event_count;
}
- return 0;
+ return event_count;
}
DEFUN ("display--update-for-mouse-movement", Fdisplay__update_for_mouse_movement,
diff --git a/src/w32term.c b/src/w32term.c
index 109aa58d73..041f2ec31f 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -5068,6 +5068,7 @@ w32_read_socket (struct terminal *terminal,
break;
case WM_MOUSEMOVE:
+ /* FIXME: Combine this logic with update_mouse_position. */
/* Ignore non-movement. */
{
int x = LOWORD (msg.msg.lParam);
--
2.20.1
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-Echo-area-stays-visible-when-moving-xterm-mouse.patch --]
[-- Type: text/x-diff; name=0004-Echo-area-stays-visible-when-moving-xterm-mouse.patch, Size: 1517 bytes --]
From caad79ddc94f4646eb68d7a7bbbbad83cfc46edc Mon Sep 17 00:00:00 2001
From: Jared Finder <jared@finder.org>
Date: Sat, 23 Jan 2021 19:31:02 -0800
Subject: [PATCH 4/4] Echo area stays visible when moving xterm mouse
The function read_char normally clears the active echo area after
reading any event. When xterm-mouse-mode is active the event can get
discarded when input-decode-map is applied (example: a mouse movement
escape sequence with 'track-mouse' set to nil) in which case the echo
area should stay unchanged. Other translation keymaps are not
intended to ever discard events so the restoring is only done for
input-decode-map.
* src/keyboard.c (read_key_sequence): Restore the last displayed echo
area whenever a transformation is applied by input-decode-map.
---
src/keyboard.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/keyboard.c b/src/keyboard.c
index 9ee4c4f6d6..f6bdadbed6 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -9955,6 +9955,14 @@ read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt,
if (done)
{
mock_input = diff + max (t, mock_input);
+
+ /* By this point the echo area was cleared by calls to
+ read_char. However, we may have completely thrown
+ out the input (for example if decoding a mouse move
+ event but `track-mouse' is nil) in which case the
+ echo area should be restored to its pristene
+ state. */
+ echo_area_buffer[0] = echo_area_buffer[1];
goto replay_sequence;
}
}
--
2.20.1
next reply other threads:[~2021-01-28 6:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-28 6:32 jared--- via Emacs development discussions. [this message]
2021-01-28 14:25 ` Additional xterm-mouse cleanup Stefan Monnier
2021-02-02 8:24 ` jared--- via Emacs development discussions.
2021-02-02 14:37 ` Stefan Monnier
2021-02-04 6:54 ` jared--- via Emacs development discussions.
2021-02-15 1:02 ` Jared Finder via Emacs development discussions.
2021-02-25 3:56 ` Stefan Monnier
2021-02-25 6:08 ` Jared Finder via Emacs development discussions.
2021-02-25 13:52 ` Stefan Monnier
2021-01-30 9:38 ` Eli Zaretskii
2021-02-02 8:28 ` jared--- via Emacs development discussions.
2021-02-02 15:08 ` Eli Zaretskii
2021-02-04 6:57 ` jared--- via Emacs development discussions.
2021-02-04 15:04 ` Eli Zaretskii
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=fcdfa21db8bb72533b6af7c50c499012@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 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.