all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#68698: 30.0.50; Making xt-mouse emit `wheel-up/down`
@ 2024-01-24 20:31 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-01-25  2:25 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-24 20:31 UTC (permalink / raw)
  To: 68698

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

Package: Emacs
Version: 30.0.50


Currently, wheel-up/down events are generated in most setups instead
of the old mouse-4/5.  There are still two exceptions:
- X11 builds not using XInput2.
- text terminals.
The attached patch intends to fix the second bullet.
Text terminals themselves only give us info equivalent to `mouse-4/5`
and don't actually tell us that it's a wheel movement, but we can still
turn those things into `wheel-up/down`.

This is related to bug#49803.

The second step would be to do something similar for the non-XInput2 X11
build: make it generate `wheel-up/down` events according to
`mouse-wheel-down/up-event` settings.  Then packages like
`completion-preview` and `mwheel` won't need to pay attention to the
(confusingly named) `mouse-wheel-down/up-event` vars any more.


        Stefan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xtmouse.patch --]
[-- Type: text/x-diff, Size: 2782 bytes --]

diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 53042085bf6..66a1fa1a706 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -59,7 +59,7 @@ mouse-wheel-change-button
 (defvar mouse-wheel-obey-old-style-wheel-buttons t
   "If non-nil, treat mouse-4/5/6/7 events as mouse wheel events.
 These are the event names used historically in X11 before XInput2.
-They are sometimes generated by things like `xterm-mouse-mode' as well.")
+They are sometimes generated by things like text-terminals as well.")
 
 (defcustom mouse-wheel-down-event
   (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-4)
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el
index cd00467f14f..fcc0db1d9eb 100644
--- a/lisp/xt-mouse.el
+++ b/lisp/xt-mouse.el
@@ -40,6 +40,8 @@
 
 ;;; Code:
 
+(require 'mwheel)
+
 (defvar xterm-mouse-debug-buffer nil)
 
 (defun xterm-mouse-translate (_event)
@@ -193,6 +195,12 @@ xterm-mouse--read-number-from-terminal
           (cons n c))
       (cons (- (setq c (xterm-mouse--read-coordinate)) 32) c))))
 
+(defun xterm-mouse--same-button-p (event btn)
+  (and (symbolp event)
+       (string-prefix-p "mouse-" (symbol-name event))
+       (eq btn (car (read-from-string (symbol-name event)
+                                      (length "mouse-"))))))
+
 ;; XTerm reports mouse events as
 ;; <EVENT-CODE> <X> <Y> in default mode, and
 ;; <EVENT-CODE> ";" <X> ";" <Y> <"M" or "m"> in extended mode.
@@ -231,12 +239,24 @@ xterm-mouse--read-event-sequence
              ;; event: assume, that the last button was button 1.
              (t 1)))
        (sym (if move 'mouse-movement
-              (intern (concat (if ctrl "C-" "")
-                              (if meta "M-" "")
-                              (if shift "S-" "")
-                              (if down "down-" "")
-                              "mouse-"
-                              (number-to-string btn))))))
+             (intern
+              (concat
+               (if ctrl "C-" "")
+               (if meta "M-" "")
+               (if shift "S-" "")
+               (if down "down-" "")
+               (cond
+                ;; BEWARE: `mouse-wheel-UP-event' corresponds to
+                ;; `wheel-DOWN' events and vice versa!!
+                ((xterm-mouse--same-button-p mouse-wheel-down-event btn)
+                 "wheel-up")
+                ((xterm-mouse--same-button-p mouse-wheel-up-event btn)
+                 "wheel-down")
+                ((xterm-mouse--same-button-p mouse-wheel-left-event btn)
+                 "wheel-left")
+                ((xterm-mouse--same-button-p mouse-wheel-right-event btn)
+                 "wheel-right")
+                (t (format "mouse-%d" btn))))))))
     (list sym (1- x) (1- y))))
 
 (defun xterm-mouse--set-click-count (event click-count)

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

end of thread, other threads:[~2024-01-28 23:52 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-24 20:31 bug#68698: 30.0.50; Making xt-mouse emit `wheel-up/down` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25  2:25 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25 13:47   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25 14:16     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25 15:41       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-26  1:59         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-26  2:30           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-25  7:30 ` Eli Zaretskii
2024-01-26  1:41   ` Jared Finder via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-26  2:26     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-26  5:02       ` Jared Finder via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-26  7:56       ` Eli Zaretskii
2024-01-26 13:04         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-28 23:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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.