From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68796: xterm.c: Convert mouse-4/5/6/7 to wheel-up/down/left/right Date: Sat, 10 Feb 2024 10:33:01 -0500 Message-ID: References: <871q9zh972.fsf@yahoo.com> <87r0hzfpd5.fsf@yahoo.com> <86cyt4vi9r.fsf@gnu.org> <87y1bs1y9x.fsf@yahoo.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20934"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 68796@debbugs.gnu.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 10 16:42:54 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rYpVF-0005Bw-B3 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Feb 2024 16:42:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYpVA-0008Qi-9X; Sat, 10 Feb 2024 10:42:48 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYpV8-0008QX-UY for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2024 10:42:47 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rYpV8-0003eD-Lq for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2024 10:42:46 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rYpVN-0005ya-Uy for bug-gnu-emacs@gnu.org; Sat, 10 Feb 2024 10:43:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Feb 2024 15:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68796 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68796-submit@debbugs.gnu.org id=B68796.170757976322923 (code B ref 68796); Sat, 10 Feb 2024 15:43:01 +0000 Original-Received: (at 68796) by debbugs.gnu.org; 10 Feb 2024 15:42:43 +0000 Original-Received: from localhost ([127.0.0.1]:49682 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYpV4-0005xX-8D for submit@debbugs.gnu.org; Sat, 10 Feb 2024 10:42:43 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28987) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYpV0-0005xB-Bq for 68796@debbugs.gnu.org; Sat, 10 Feb 2024 10:42:39 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 32655442CCB; Sat, 10 Feb 2024 10:33:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1707579189; bh=JfHqg/t2J9oREE+9M3+jQwi4+g5fexMFeFuR1gfIvI0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=hhLBd06NWGP1KdXaUlbMMVqH61pTCvUKSn19v5ZmzEhmAZrzkR03Ah1mYi4PwSi83 flEZxynXBE4vOIWQNx2LEw+c/OR4MwVkPxIcLnJXI5cbT7Jyx7/rB/5feuhmPhWiiN 0rpZH7GUnGsuAUTELLnTPmURU5tB1RhG0WDxnJQc2cXa6x1xiv8Wa5YoXRa6v1hZ+2 DAksHyecre4XjLxS7GZ/xsWQHWOS+1vPLF9j6vfUREvcUBhb+qR1hyewI1iRNo5feM PDH8lhg6Nofpg7zTTMWEyfvsP7E59JOygrYw8bMf4JMVD6gI+QOniOYrFl7ZC8/tFo oWklXj1g3C2lA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5C6B7440CBC; Sat, 10 Feb 2024 10:33:09 -0500 (EST) Original-Received: from pastel (unknown [104.247.238.113]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2E7911202FC; Sat, 10 Feb 2024 10:33:09 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Sat, 10 Feb 2024 09:22:02 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279755 Archived-At: --=-=-= Content-Type: text/plain > Or maybe we should keep `mouse-wheel-*-event` untouched (tho, maybe mark > them obsolete) and instead introduce a new set of variables that control > the remapping of `mouse-4/5/6/7` to `wheel-*` events. See patch below. It would need etc/NEWS and doc changes, of course, and probably some warning-silencing in those packages using `mouse-wheel-*-event`s. Stefan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-mouse-wheel-buttons-Map-old-style-wheel-buttons-to-a.patch >From 0e94e1140a8ec72bd068648eb5ec1dc861f0884b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 29 Jan 2024 09:35:09 -0500 Subject: [PATCH] (mouse-wheel-buttons): Map old-style wheel buttons to actual wheel events Change the handling of the old X11 convention to use mouse-4/5/6/7 events to represent wheel events: instead of asking downstream packages to use the `mouse-wheel-*-event` variables to know which events represent wheel events, use new var `mouse-wheel-buttons` to directly convert those events into the standard `wheel-up/down/left/right` events used everywhere else. This will simplify the work of packages which can thus just bind their commands to `wheel-up/down/left/right`. * lisp/mouse.el (mouse-wheel-buttons): New custom variable. * src/keyboard.c (make_lispy_event): Adjust for "wheel-clicks" on the tab-bar. * src/xterm.c (x_construct_mouse_click): Add `xi2` argument and obey `mouse-wheel-buttons` variable. (handle_one_xevent): Adjust calls accordingly. (syms_of_xterm): Define the `mouse-wheel-buttons` and the `wheel-up/down/left/right`symbols. * lisp/xt-mouse.el: Don't require `mwheel` any more. (xterm-mouse--same-button-p): Delete function. (xterm-mouse--read-event-sequence): Use `mouse-wheel-buttons`. * lisp/mwheel.el (mouse-wheel-up-event, mouse-wheel-down-event) (mouse-wheel-left-event, mouse-wheel-right-event): Make obsolete. (mouse-wheel-obey-old-style-wheel-buttons): Delete variable. --- lisp/mouse.el | 13 ++++++++++++ lisp/mwheel.el | 21 ++++++++----------- lisp/xt-mouse.el | 20 ++++-------------- src/keyboard.c | 9 ++++++-- src/xterm.c | 53 +++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 75 insertions(+), 41 deletions(-) diff --git a/lisp/mouse.el b/lisp/mouse.el index d1b06c2040d..585891bf699 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -133,6 +133,19 @@ mouse-drag-mode-line-buffer :type 'boolean :version "29.1") +(defcustom mouse-wheel-buttons + '((4 . wheel-up) (5 . wheel-down) (6 . wheel-left) (7 . wheel-right)) + "Buttons to remap to wheel events. +This is an alist of (NUMBER . SYMBOL) used to remap old-style mouse wheel +events represented as mouse button events. It remaps mouse button event +NUMBER to the event SYMBOL. SYMBOL must be one of `wheel-up', `wheel-down', +`wheel-left', or `wheel-right'. +This is used only for events that come from sources known to generate such +events, such as X11 events when XInput2 is not used, or events coming from +a text terminal." + :type '(alist) + :version "30.1") + (defvar mouse--last-down nil) (defun mouse--down-1-maybe-follows-link (&optional _prompt) diff --git a/lisp/mwheel.el b/lisp/mwheel.el index 66a1fa1a706..9fc922eebc9 100644 --- a/lisp/mwheel.el +++ b/lisp/mwheel.el @@ -56,20 +56,17 @@ mouse-wheel-change-button (bound-and-true-p mouse-wheel-mode)) (mouse-wheel-mode 1))) -(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 text-terminals as well.") +(make-obsolete-variable 'mouse-wheel-up-event 'mouse-wheel-buttons "30.1") +(make-obsolete-variable 'mouse-wheel-down-event 'mouse-wheel-buttons "30.1") +(make-obsolete-variable 'mouse-wheel-left-event 'mouse-wheel-buttons "30.1") +(make-obsolete-variable 'mouse-wheel-right-event 'mouse-wheel-buttons "30.1") -(defcustom mouse-wheel-down-event - (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-4) +(defcustom mouse-wheel-down-event 'mouse-4 "Event used for scrolling down, beside `wheel-up', if any." :group 'mouse :type 'symbol :set #'mouse-wheel-change-button) - -(defcustom mouse-wheel-up-event - (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-5) +(defcustom mouse-wheel-up-event 'mouse-5 "Event used for scrolling up, beside `wheel-down', if any." :group 'mouse :type 'symbol @@ -223,12 +220,10 @@ mwheel-scroll-left-function (defvar mwheel-scroll-right-function 'scroll-right "Function that does the job of scrolling right.") -(defvar mouse-wheel-left-event - (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-6) +(defvar mouse-wheel-left-event 'mouse-6 "Event used for scrolling left, beside `wheel-left', if any.") -(defvar mouse-wheel-right-event - (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-7) +(defvar mouse-wheel-right-event 'mouse-7 "Event used for scrolling right, beside `wheel-right', if any.") (defun mouse-wheel--get-scroll-window (event) diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el index 081b8f32456..c27dee7e249 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -40,8 +40,6 @@ ;;; Code: -(require 'mwheel) - (defvar xterm-mouse-debug-buffer nil) (defun xterm-mouse-translate (_event) @@ -195,12 +193,6 @@ xterm-mouse--read-number-from-terminal (cons n c)) (cons (- (setq c (xterm-mouse--read-coordinate)) 32) c)))) -(defun xterm-mouse--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 ;; in default mode, and ;; ";" ";" <"M" or "m"> in extended mode. @@ -246,14 +238,10 @@ xterm-mouse--read-event-sequence (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--button-p mouse-wheel-down-event btn) "wheel-up") - ((xterm-mouse--button-p mouse-wheel-up-event btn) "wheel-down") - ((xterm-mouse--button-p mouse-wheel-left-event btn) "wheel-left") - ((xterm-mouse--button-p mouse-wheel-right-event btn) "wheel-right") - (t (format "mouse-%d" btn)))))))) + (let ((remap (alist-get btn mouse-wheel-buttons))) + (if remap + (symbol-name remap) + (format "mouse-%d" btn)))))))) (list sym (1- x) (1- y)))) (defun xterm-mouse--set-click-count (event click-count) diff --git a/src/keyboard.c b/src/keyboard.c index 1f7253a7da1..4c3e33762af 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -6628,8 +6628,13 @@ make_lispy_event (struct input_event *event) if (CONSP (event->arg)) return list5 (head, position, make_fixnum (double_click_count), - XCAR (event->arg), Fcons (XCAR (XCDR (event->arg)), - XCAR (XCDR (XCDR (event->arg))))); + XCAR (event->arg), + /* FIXME: I don't know what I'm doing here. */ + (CONSP (XCDR (event->arg)) + && CONSP (XCDR (XCDR (event->arg)))) + ? Fcons (XCAR (XCDR (event->arg)), + XCAR (XCDR (XCDR (event->arg)))) + : Qnil); else if (NUMBERP (event->arg)) return list4 (head, position, make_fixnum (double_click_count), event->arg); diff --git a/src/xterm.c b/src/xterm.c index c8a43785564..e75b64ed3d4 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -14543,18 +14543,19 @@ x_query_pointer (Display *dpy, Window w, Window *root_return, `x', `y', `x_root' and `y_root'. This function should not access any other fields in EVENT without also initializing the corresponding fields in `bv' under the XI_ButtonPress and - XI_ButtonRelease labels inside `handle_one_xevent'. */ + XI_ButtonRelease labels inside `handle_one_xevent'. + + XI2 indicates that this click comes from XInput2 rather than core + event. */ static Lisp_Object x_construct_mouse_click (struct input_event *result, const XButtonEvent *event, - struct frame *f) + struct frame *f, bool xi2) { int x = event->x; int y = event->y; - /* Make the event type NO_EVENT; we'll change that when we decide - otherwise. */ result->kind = MOUSE_CLICK_EVENT; result->code = event->button - Button1; result->timestamp = event->time; @@ -14564,6 +14565,29 @@ x_construct_mouse_click (struct input_event *result, ? up_modifier : down_modifier)); + /* Convert pre-XInput2 wheel events represented as mouse-clicks. */ + if (!xi2) + { + Lisp_Object base + = Fcdr_safe (Fassq (make_fixnum (result->code + 1), + Fsymbol_value (Qmouse_wheel_buttons))); + int wheel + = NILP (base) ? -1 + : BASE_EQ (base, Qwheel_down) ? 0 + : BASE_EQ (base, Qwheel_up) ? 1 + : BASE_EQ (base, Qwheel_left) ? 2 + : BASE_EQ (base, Qwheel_right) ? 3 + : -1; + if (wheel >= 0) + { + result->kind = (event->type != ButtonRelease ? NO_EVENT + : wheel & 2 ? HORIZ_WHEEL_EVENT : WHEEL_EVENT); + result->code = 0; /* Not used. */ + result->modifiers &= ~(up_modifier || down_modifier); + result->modifiers |= wheel & 1 ? up_modifier : down_modifier; + } + } + /* If result->window is not the frame's edit widget (which can happen with GTK+ scroll bars, for example), translate the coordinates so they appear at the correct position. */ @@ -21873,13 +21897,14 @@ handle_one_xevent (struct x_display_info *dpyinfo, && event->xbutton.time > ignore_next_mouse_click_timeout) { ignore_next_mouse_click_timeout = 0; - x_construct_mouse_click (&inev.ie, &event->xbutton, f); + x_construct_mouse_click (&inev.ie, &event->xbutton, + f, false); } if (event->type == ButtonRelease) ignore_next_mouse_click_timeout = 0; } else - x_construct_mouse_click (&inev.ie, &event->xbutton, f); + x_construct_mouse_click (&inev.ie, &event->xbutton, f, false); *finish = X_EVENT_DROP; goto OTHER; @@ -21949,13 +21974,15 @@ handle_one_xevent (struct x_display_info *dpyinfo, && event->xbutton.time > ignore_next_mouse_click_timeout) { ignore_next_mouse_click_timeout = 0; - x_construct_mouse_click (&inev.ie, &event->xbutton, f); + x_construct_mouse_click (&inev.ie, &event->xbutton, + f, false); } if (event->type == ButtonRelease) ignore_next_mouse_click_timeout = 0; } else - x_construct_mouse_click (&inev.ie, &event->xbutton, f); + x_construct_mouse_click (&inev.ie, &event->xbutton, + f, false); if (!NILP (tab_bar_arg)) inev.ie.arg = tab_bar_arg; @@ -23732,13 +23759,13 @@ handle_one_xevent (struct x_display_info *dpyinfo, && xev->time > ignore_next_mouse_click_timeout) { ignore_next_mouse_click_timeout = 0; - x_construct_mouse_click (&inev.ie, &bv, f); + x_construct_mouse_click (&inev.ie, &bv, f, true); } if (xev->evtype == XI_ButtonRelease) ignore_next_mouse_click_timeout = 0; } else - x_construct_mouse_click (&inev.ie, &bv, f); + x_construct_mouse_click (&inev.ie, &bv, f, true); if (!NILP (tab_bar_arg)) inev.ie.arg = tab_bar_arg; @@ -32444,6 +32471,12 @@ syms_of_xterm (void) DEFSYM (Qexpose, "expose"); DEFSYM (Qdont_save, "dont-save"); + DEFSYM (Qmouse_wheel_buttons, "mouse-wheel-buttons"); + DEFSYM (Qwheel_up, "wheel-up"); + DEFSYM (Qwheel_down, "wheel-down"); + DEFSYM (Qwheel_left, "wheel-left"); + DEFSYM (Qwheel_right, "wheel-right"); + #ifdef USE_GTK xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg"); staticpro (&xg_default_icon_file); -- 2.43.0 --=-=-=--