GNU bug report logs - #68796
xterm.c: Convert mouse-4/5/6/7 to wheel-up/down/left/right

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: wishlist; Reported by: Stefan Monnier <monnier@HIDDEN>; Keywords: patch; dated Mon, 29 Jan 2024 14:46:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 3 Mar 2024 16:23:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 03 11:23:20 2024
Received: from localhost ([127.0.0.1]:41015 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rgocR-0008AC-CI
	for submit <at> debbugs.gnu.org; Sun, 03 Mar 2024 11:23:20 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:23992)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rgocO-00089y-JR
 for 68796 <at> debbugs.gnu.org; Sun, 03 Mar 2024 11:23:18 -0500
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A123780A90;
 Sun,  3 Mar 2024 11:22:41 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1709482959;
 bh=lB4KMugO219+731pOueNyNlYHVTQ+OwCC7Lhszl3t04=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=XDHxVpYDFsODtwmtV4dDeQZFwo+mk6CCukL9xpizLRTZkn9hVD4fr/A4f5rl5JiMz
 IRuAEMKK4d3Pj9wYEjq1V15eSAvU6v8F/HvaoVX8wlR2PxklKNb73DiH937UEBe+YR
 P5uUPEqup4cO7VHKT3Wen9psZw4xu6aO/4l+iS6y/sdk6fnNpmA0x331MJC6LeZBpC
 SShzGiltydL/Z9xsL6ixoIRygreP9IZiZCn3995wugb1NYevBeJXQwdkU6d5VPCWwq
 Mc8Jbjkfui+h7dkeIumZR0Ox/CSCoJsVW2hrK4kE4Jx8R5wrYKQAdQUOHiMeA9duHQ
 cU50uK0HOtEyQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id ACE30806A3;
 Sun,  3 Mar 2024 11:22:39 -0500 (EST)
Received: from pastel (unknown [216.154.1.84])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7E7581202E4;
 Sun,  3 Mar 2024 11:22:39 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Po Lu <luangruo@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <jwvfry0gwvp.fsf-monnier+emacs@HIDDEN> (Stefan Monnier's message
 of "Sat, 10 Feb 2024 10:33:01 -0500")
Message-ID: <jwvsf17cmtb.fsf-monnier+emacs@HIDDEN>
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> <87r0hzfpd5.fsf@HIDDEN>
 <86cyt4vi9r.fsf@HIDDEN> <87y1bs1y9x.fsf@HIDDEN>
 <jwvwmrch0vy.fsf-monnier+emacs@HIDDEN>
 <jwvfry0gwvp.fsf-monnier+emacs@HIDDEN>
Date: Sun, 03 Mar 2024 11:22:39 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.118 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68796
Cc: Eli Zaretskii <eliz@HIDDEN>, 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ping?

I believe this patch should be much less controversial since it allows
users to get the old behavior back and still keeps the same semantics
for existing `mouse-wheel-*-event` variables in case some other code
still generates such events.  It's basically a half-way step between
what I proposed at first and the status quot.

But I'd like some confirmation that you think it's acceptable, and maybe
if you could comment on the FIXME included in there (I needed it for
clicks on the tab-bar, but I don't understand that code).


        Stefan


Stefan Monnier [2024-02-10 10:33:01] wrote:

>> 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
>
> From 0e94e1140a8ec72bd068648eb5ec1dc861f0884b Mon Sep 17 00:00:00 2001
> From: Stefan Monnier <monnier@HIDDEN>
> 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
>  ;; <EVENT-CODE> <X> <Y> in default mode, and
>  ;; <EVENT-CODE> ";" <X> ";" <Y> <"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);





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 10 Feb 2024 15:42:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 10 10:42:43 2024
Received: from localhost ([127.0.0.1]:49682 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYpV4-0005xX-8D
	for submit <at> debbugs.gnu.org; Sat, 10 Feb 2024 10:42:43 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:28987)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rYpV0-0005xB-Bq
 for 68796 <at> debbugs.gnu.org; Sat, 10 Feb 2024 10:42:39 -0500
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==
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)
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)
From: Stefan Monnier <monnier@HIDDEN>
To: Po Lu <luangruo@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <jwvwmrch0vy.fsf-monnier+emacs@HIDDEN> (Stefan Monnier's message
 of "Sat, 10 Feb 2024 09:22:02 -0500")
Message-ID: <jwvfry0gwvp.fsf-monnier+emacs@HIDDEN>
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> <87r0hzfpd5.fsf@HIDDEN>
 <86cyt4vi9r.fsf@HIDDEN> <87y1bs1y9x.fsf@HIDDEN>
 <jwvwmrch0vy.fsf-monnier+emacs@HIDDEN>
Date: Sat, 10 Feb 2024 10:33:01 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.013 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68796
Cc: Eli Zaretskii <eliz@HIDDEN>, 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
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 <monnier@HIDDEN>
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
 ;; <EVENT-CODE> <X> <Y> in default mode, and
 ;; <EVENT-CODE> ";" <X> ";" <Y> <"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


--=-=-=--





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 10 Feb 2024 14:22:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 10 09:22:28 2024
Received: from localhost ([127.0.0.1]:43872 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYoFQ-0002KZ-JV
	for submit <at> debbugs.gnu.org; Sat, 10 Feb 2024 09:22:28 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33087)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rYoFO-0002K9-IK
 for 68796 <at> debbugs.gnu.org; Sat, 10 Feb 2024 09:22:27 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 34791442CC3;
 Sat, 10 Feb 2024 09:22:05 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1707574923;
 bh=U3PieQLpGbahdazXdEz1t64NhRpLrPBrH/ipbA0o9RE=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=MF8r8IoJ7+PNWN7vXOfEDFZbEwpuhbf7m6w/ZgqJ/o5E6WwqCVMtAQlqCOBq5Iwst
 TtCM+ZnHvtKBbCMz6guaWZlmPf8pog3NCu5lxRgB7j4OfiGbARek+7B7ka4zylLXmw
 R9kllBVPpws9s2XUNWcu0s5qnlRCdk/lsNd4B3gwlnE9WAqPJ3BLlmucUcNFUlckdu
 tgzM21FwprfyP4R4FU6aeaP/U1uq01N/MCPCh5B06gBjVAMtbJ3blOVpSCCgwLjL9g
 zuOzeLiOEjUyrr8pFdt9wc5Vlhy5iMDgFpPCehXlpKOy23sFab0cG4SeRiLs1VQVvJ
 jPMsOvfqBok7w==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D24E7442CB4;
 Sat, 10 Feb 2024 09:22:03 -0500 (EST)
Received: from pastel (unknown [104.247.238.113])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A7A1F12021A;
 Sat, 10 Feb 2024 09:22:03 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Po Lu <luangruo@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <87y1bs1y9x.fsf@HIDDEN> (Po Lu's message of "Sat, 10 Feb 2024
 17:09:14 +0800")
Message-ID: <jwvwmrch0vy.fsf-monnier+emacs@HIDDEN>
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> <87r0hzfpd5.fsf@HIDDEN>
 <86cyt4vi9r.fsf@HIDDEN> <87y1bs1y9x.fsf@HIDDEN>
Date: Sat, 10 Feb 2024 09:22:02 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.013 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68796
Cc: Eli Zaretskii <eliz@HIDDEN>, 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Po Lu [2024-02-10 17:09:14] wrote:
> Eli Zaretskii <eliz@HIDDEN> writes:
>> Ping!  Can we make some progress here?
> I converted most of the Lisp code at my organization (where X servers
> are configured with the input extension disabled) to use wheel events
> under Emacs 30 and arranged for a modified version of Stefan's patch to
> be built.  Which was incidentally not straightforward to do cleanly, as
> the code in question assumed that events it received would be pairs of
> button press and release events, and was very much designed around that
> assumption.

Fascinating.  Is there any way I could get to peek at that code?
Also interested in the backstory about why your X11 servers are configured
without XInput2.

Maybe we should provide a better "reverse" story: with the current patch
users can recover their old `mouse-4/5/6/7` events by setting
`mouse-wheel-*-event` to nil, but then they lose mwheel-based scrolling
(plus a few other bindings, mostly one in completion-preview and one in
flymake), so the etc/NEWS entry should describe how to recover that
scrolling behavior.

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.

That would provide a smoother transition: users can set those new vars
to nil to recover the old behavior.

Another benefit is that the new var(s) could hold just the button
numbers (i.e. an integer) instead of a symbol, which should simplify the
remapping code (both in the `xterm.c` and the `xt-mouse.el` cases).


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 10 Feb 2024 09:19:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 10 04:19:51 2024
Received: from localhost ([127.0.0.1]:55136 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYjWZ-0000Vg-Ef
	for submit <at> debbugs.gnu.org; Sat, 10 Feb 2024 04:19:51 -0500
Received: from sonic312-23.consmr.mail.ne1.yahoo.com ([66.163.191.204]:40299)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <luangruo@HIDDEN>) id 1rYjWX-0000VL-AG
 for 68796 <at> debbugs.gnu.org; Sat, 10 Feb 2024 04:19:50 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1707556767; bh=QoP+3jO5W9G1VWaqcvh9AB/mAYlVNAtvyLZB66GUrnM=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To;
 b=fY5rgy03174+i96i0VzS6KofEJagUV3tWEFvfHnBvJjSB10LbZUSaTvlBsOx7EZPoXTA173qOO5g7MEDCMQrKove9CvhitjxpoPQiqWDowpzZfnO5h8/7+9mDPxGt9ySyPQ5bZB6Q+JPX/rYUX5WHloU1JkZ3I7egz4HhLcR9EMtgwCMZVw4CfhlhWXl8jQMbawiSwvgBx7vhiEnxQrpSio0TYVV7Nm7D27dvx3xVwVbpwK5pKZnhUR+H56Jagq5NpMUKcs+Qr3i6zAlzRojhDl5ByORY0wz+wa0ElV2g/HLOKF6RmqbDtnf0eof/OCoxAOVHyttLX8roNTenfz2KQ==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1707556767; bh=RElXFWg4zxdzP+xv5zbpOHGposaK7yFqt7PopmLQWcT=;
 h=X-Sonic-MF:From:To:Subject:Date:From:Subject;
 b=EEZB5sGsmL9Z2z7NPiWDefyBmo6zkeMB1oa24LtXs4NCIG8YjpKGD//BBSxaIm465tX3q5WdKabCrPRR6B5FXzkquK+PBRQsgZxRF3G+7xY1Ck0s3jmfKPPwctCO2o2MFuPuASG78dGdM0pDO8rar9j+NsOPZZECh7Ol+bkc/eL23ibRfVcmS3d/PYVHytVWdt6ZsFIrsiiGiLevFwgX9QMUbEv9CbIkBiaIAAY5vjdOFCwXsgBJ6Ne4+oMqEkpbYIPcqArdN29ZXZ0HzsEi540FcVC+QaGxb0Zmv219ALw6V01/B8q2mOvHC1hENGfnjTHOua5mvOnpcf5eOm51HQ==
X-YMail-OSG: w7_FydUVM1nvyxwyAUTqW33sQa3rhyLK43X.oBlKlrfoxiIX5gjRMhB1dI2V6GU
 smuZ0jL3iCckd_m9.q5SOseiPvTIyuh0bcgg5S9afIcO7L8qX6zADwV6tTt6bwbCVGga8ZHAoCm_
 QXcMObyPkOnykLklVuyoQUJdckM.yA3fIU6qFpDphMtrT9p2Aq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VNRENgd_BybSS4rZvqhKPQvdNyL1XEkbVM-
X-Sonic-MF: <luangruo@HIDDEN>
X-Sonic-ID: 416d25bc-a31a-4ce1-9e52-7b3599d46a1f
Received: from sonic.gate.mail.ne1.yahoo.com by
 sonic312.consmr.mail.ne1.yahoo.com with HTTP; Sat, 10 Feb 2024 09:19:27 +0000
Received: by hermes--production-sg3-6dc75bc8fb-qvr7d (Yahoo Inc. Hermes SMTP
 Server) with ESMTPA ID b89bdd9c87a11a1cb550996be7b5b701; 
 Sat, 10 Feb 2024 09:09:21 +0000 (UTC)
From: Po Lu <luangruo@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <86cyt4vi9r.fsf@HIDDEN> (Eli Zaretskii's message of "Sat, 10 Feb
 2024 10:24:32 +0200")
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> <87r0hzfpd5.fsf@HIDDEN>
 <86cyt4vi9r.fsf@HIDDEN>
Date: Sat, 10 Feb 2024 17:09:14 +0800
Message-ID: <87y1bs1y9x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Mailer: WebService/1.1.22077
 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo
Content-Length: 781
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68796
Cc: monnier@HIDDEN, 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

> Ping!  Can we make some progress here?

I converted most of the Lisp code at my organization (where X servers
are configured with the input extension disabled) to use wheel events
under Emacs 30 and arranged for a modified version of Stefan's patch to
be built.  Which was incidentally not straightforward to do cleanly, as
the code in question assumed that events it received would be pairs of
button press and release events, and was very much designed around that
assumption.

Unfortunately the holidays are in full swing, and conclusions from this
cannot be drawn until once enough experience accumulates some time after
they end.  To complicate matters, users at my site don't often work with
Emacs 30, except for a few early adopters.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 10 Feb 2024 08:55:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 10 03:55:21 2024
Received: from localhost ([127.0.0.1]:53639 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYj8r-0007sK-KW
	for submit <at> debbugs.gnu.org; Sat, 10 Feb 2024 03:55:21 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:57084)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rYj7h-0007mm-3y
 for 68796 <at> debbugs.gnu.org; Sat, 10 Feb 2024 03:54:09 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rYif4-0006Cz-TZ; Sat, 10 Feb 2024 03:24:34 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=pBpYAwAlSPEGRm4j9NhnVtNoi2o2recHUnDxNJfbuhg=; b=lQQRnstZafWs
 m8AYIqVQHZAteph3HaatMcY8KNmaa1S0rXwigTRDtU2OeHgB/iK/9p+5sOoE9Wl+EL/IuAs7h0qKc
 ShX08EUepqGL0oFbk4Njk+DUw2H0vxOXKFqi9XlOFy6tREMWHix3w4wOMB1K+FIXP9+HBeEWixZo1
 righz4UwgJ+jxk3z0D2IVqOh1nVALDmQuRRQ59U6LSfZKNeD1bFTf0Ff7QzBkyxH8LGnP+JqPQnVc
 r3uj/Qj35XPg3JyKaUOzVlQhOQS4yyJr38FRQXOCQ4pHcS33vbgoryZQXmeVNVHu0nOh6rELCn89I
 4ogCRkkiysDnBwyfyGHSeQ==;
Date: Sat, 10 Feb 2024 10:24:32 +0200
Message-Id: <86cyt4vi9r.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Po Lu <luangruo@HIDDEN>
In-Reply-To: <87r0hzfpd5.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> <87r0hzfpd5.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68796
Cc: monnier@HIDDEN, 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ping!  Can we make some progress here?

> Cc: 68796 <at> debbugs.gnu.org
> Date: Tue, 30 Jan 2024 11:53:58 +0800
> From:  Po Lu via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> Stefan Monnier <monnier@HIDDEN> writes:
> 
> > Hmm... so IIUC you're saying that even when `dpyinfo->supports_xi2` is
> > true, we may receive `mouse-4/5/6/7` events for wheel motions?
> > Yuck!
> 
> Yes, and as always other clients may send whatever they want, although
> Emacs is not obliged to handle those events correctly.
> 
> >> The correct test of event type is whether x_construct_mouse_click is
> >> being called from the XI_ButtonPress or XI_ButtonRelease label in
> >> handle_one_xevent.
> >
> > OK, that sounds fixable.  See additional patch below.
> 
> Thanks.  I'm short on time at the moment, but will get around to this.
> 
> 
> 
> 




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 30 Jan 2024 03:54:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 29 22:54:29 2024
Received: from localhost ([127.0.0.1]:34107 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rUfCf-0008BN-0T
	for submit <at> debbugs.gnu.org; Mon, 29 Jan 2024 22:54:29 -0500
Received: from sonic315-22.consmr.mail.ne1.yahoo.com ([66.163.190.148]:40139)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <luangruo@HIDDEN>) id 1rUfCb-0008B8-QO
 for 68796 <at> debbugs.gnu.org; Mon, 29 Jan 2024 22:54:27 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1706586851; bh=427KdDbdSrydUSORnNJ6hXC+DZtQVToHuwfA1w0TLIM=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To;
 b=ctps7cpFIDvMfWUtC8CHtcRUJGapEQyu2yMvZLDzA/NwsYncz3tAVXoU2/hpToihFHLQ0qCu1OHTS46RQhz612MzUBJNAsq686vPV61j1Q9Fz6UVnaPIGT4UG1V7it3Q9i2/IHYe+CVPk7MtPKI4+fB097vz55eEjFF9UZWptjzXd/nDfahgke0DKChme5V8HaTXenoc18bH5OQlpPN31HGhlJ0epwNiR0jyqV6Q3oeiclLLDzEn2uuM6ZanN4WTw3+/KRfNw1SRMQbUI/rxdqTB/7v6hiUTDPj1Cmc7t91S4wTDYjipvfztiQJiMBIoOR2qMacCfVl29iBdpmO6HA==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1706586851; bh=9kFG9PjtnATiMCkFiQRO45Yhit8BR0AJe+Yxr2y8bXz=;
 h=X-Sonic-MF:From:To:Subject:Date:From:Subject;
 b=oK6i7PeeH62xYn70hTl2HZsXkIBkjMBnSTGQlebNGpd6LfwMHNVpv0PqUaILq0e7MXvm4lBmgEAb4KpTUphbe0xMTPROO+YZ5qnz4Bkv380FZJOACoT1mbiyNFPav2lgTed1CkR1069XtjXq/Pa40gzHwcxFG+XATY65wNC/TqUkNtEWrPsNag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gbxCdejrtSJh724lyEzhe
 kuMXtXd64f94zYnXDiShV46xakDTFw5SsJXrJMk71DI2Q6n9mhvu8J9ux.VmTDgU0wS1Nb5zUvVd
 T.DSMwOwMC6HU2IIV.Tz7P8Lb0ASLuYa4ECvvmzfTH8gTSp4a5piREC.vDnjrNLcfvc5yg2M57GG
 Ouch67NHKKPaW_ek3vawfESf7xWNnspyJrijUe_HRc6OS0f4fQDBGemdmcPNv4a9Osylo949h9ka
 M0nGvXTqMf8Pmxydu7tvUsN9XdF5uBMhtR_sFtUliVnCCd4UTqL2sGve8aLqeNknrv9KU0SN1I2f
 C2DpCvnAHO9OspClH5diSYue0mUIFbMadSGQNvwhKRnsJSuz_Br1l1JlpZXsMDhcKew--
X-Sonic-MF: <luangruo@HIDDEN>
X-Sonic-ID: 3163baba-c965-4c31-a142-d8849268d9c1
Received: from sonic.gate.mail.ne1.yahoo.com by
 sonic315.consmr.mail.ne1.yahoo.com with HTTP; Tue, 30 Jan 2024 03:54:11 +0000
Received: by hermes--production-sg3-6dc75bc8fb-r5vvk (Yahoo Inc. Hermes SMTP
 Server) with ESMTPA ID 894b0a61197c296d3dd2f07d2395652a; 
 Tue, 30 Jan 2024 03:54:03 +0000 (UTC)
From: Po Lu <luangruo@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <jwv8r47czk4.fsf-monnier+emacs@HIDDEN> (Stefan Monnier's message
 of "Mon, 29 Jan 2024 22:32:29 -0500")
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
 <jwv8r47czk4.fsf-monnier+emacs@HIDDEN>
Date: Tue, 30 Jan 2024 11:53:58 +0800
Message-ID: <87r0hzfpd5.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Mailer: WebService/1.1.22046
 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo
Content-Length: 618
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68796
Cc: 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Stefan Monnier <monnier@HIDDEN> writes:

> Hmm... so IIUC you're saying that even when `dpyinfo->supports_xi2` is
> true, we may receive `mouse-4/5/6/7` events for wheel motions?
> Yuck!

Yes, and as always other clients may send whatever they want, although
Emacs is not obliged to handle those events correctly.

>> The correct test of event type is whether x_construct_mouse_click is
>> being called from the XI_ButtonPress or XI_ButtonRelease label in
>> handle_one_xevent.
>
> OK, that sounds fixable.  See additional patch below.

Thanks.  I'm short on time at the moment, but will get around to this.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 30 Jan 2024 03:32:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 29 22:32:50 2024
Received: from localhost ([127.0.0.1]:34093 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rUerh-0007WJ-Ha
	for submit <at> debbugs.gnu.org; Mon, 29 Jan 2024 22:32:50 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:46663)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rUere-0007W3-IP
 for 68796 <at> debbugs.gnu.org; Mon, 29 Jan 2024 22:32:47 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 85FBA100134;
 Mon, 29 Jan 2024 22:32:31 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1706585550;
 bh=RJ0LQpGjdoCsuxgbgxWRKsgbPbpL+nl8GuZpvmRo8a0=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Thr3tXD+qBBGoqYWnbzP3cmusJ2ceDSNDdw7kXLb1ONv5assiRbCwEOL+bPDBs2Ye
 nOXSBiCbE7bFZr6Q+E3tZXxkfRtvsIwYZjBuY/FLI20WGT+gkpkOc9QRq/gVp/Plm0
 pqv8RL0oOILkJ7eukJ++EtL7ROahfvlQi7T7BWqoKNlpIhkf0ptr+2dTe3oeCsB3SL
 iLX3+yxAclCA+qaA4iIwaW905k5ncIwjBerYtn0ltcemQzGlzQC22goSO+/K/xzabc
 zEerVyG8dmg6ECV57exTVUxx7SUv2EnNN0UgrZJW6UTO+Q9gEDiYwAvB/u05XMhl4R
 /UUE+RlSTFBMQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 3A21C10009E;
 Mon, 29 Jan 2024 22:32:30 -0500 (EST)
Received: from pastel (unknown [45.72.206.68])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 04BF1120403;
 Mon, 29 Jan 2024 22:32:29 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Po Lu <luangruo@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <871q9zh972.fsf@HIDDEN> (Po Lu's message of "Tue, 30 Jan 2024
 10:00:17 +0800")
Message-ID: <jwv8r47czk4.fsf-monnier+emacs@HIDDEN>
References: <jwvh6iwmc5u.fsf@HIDDEN> <871q9zh972.fsf@HIDDEN>
Date: Mon, 29 Jan 2024 22:32:29 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.116 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68796
Cc: 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

>> +  /* Convert pre-XInput2 wheel events represented as mouse-clicks.  */
>> +#ifdef HAVE_XINPUT2
>> +  if (!dpyinfo->supports_xi2)
>> +#endif
>
> dpyinfo->supports_xi2 is no guarantee that exclusively input extension
> events will be received, but only indicates that the X display supports
> the input extension.  There are several scenarios where it may be true
> while core events are still delivered to windows, such as a combination
> of GTK 3 and GDK_CORE_DEVICE_EVENTS=3D1's being enabled.

Hmm... so IIUC you're saying that even when `dpyinfo->supports_xi2` is
true, we may receive `mouse-4/5/6/7` events for wheel motions?
Yuck!

> The correct test of event type is whether x_construct_mouse_click is
> being called from the XI_ButtonPress or XI_ButtonRelease label in
> handle_one_xevent.

OK, that sounds fixable.  See additional patch below.

> Incidentally, servers with the input extension always assign buttons 4
> through 7 to wheel movement.

Interesting.

>> +      Lisp_Object base =3D base_mouse_symbol (result->code);
>> +      int wheel
>> +       /* BEWARE: `mouse-wheel-UP-event' corresponds to
>> +          `wheel-DOWN' events and vice versa!!  */
>> +        =3D BASE_EQ   (base, find_symbol_value (Qmouse_wheel_up_event))=
    ? 0
>> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_down_event))=
  ? 1
>> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_left_event))=
  ? 2
>> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_right_event)=
) ? 3
>> +          : -1;
>> +      if (wheel >=3D 0)
>> +        {
>> +          result->kind =3D (event->type !=3D ButtonRelease ? NO_EVENT
>> +		          : wheel & 2 ? HORIZ_WHEEL_EVENT : WHEEL_EVENT);
>> +          result->code =3D 0;         /* Not used.  */
>> +          result->modifiers &=3D ~(up_modifier || down_modifier);
>> +          result->modifiers |=3D wheel & 1 ? up_modifier : down_modifie=
r;
>> +        }
>> +    }
>
> Isn't this insufficient to completely supersede mouse events by wheel
> events, considering that such events will still be delivered as mouse
> button events to tab bars?

Hmm... indeed there was a crash here, which I just fixed in the
patch below.  But with that fix, I do see `wheel-up/down` events on the
tab-tab as well.  Am I missing something?

> Lastly, plenty of old code that binds just the button events will be
> broken,

Indeed.  But that should be a disappearing breed because such bindings
never worked under non-X11 GUIs and now they don't work either under X11
builds that use XInput2, which I expect is the vast majority of Emacs=E2=89=
=A529
builds in GNU/Linux distributions.

> and the code that keeps track of button-down and up events in
> read_key_sequence and friends will cease applying to X wheel events.

Hmm... the only code I can think of in `read_key_sequence` which cares
about button up/down is the code that drops the button down events and
the one that turns pairs into drag events.  Is that ever useful
currently with the `mouse-4/5/6/7` events?  No one has lamented this
under non-X11 builds so far nor under XInput2, so it seems unlikely to
be a problem.

> This area has given me a lot of grief over the years (as it has given
> you), so I'm reluctant to see any change there, as no matter how well
> the argument in favor of its safety is posed, some unforeseen problem
> invariably emerges afterwards.

There's no doubt that event representation is a delicate/nasty part of
Emacs code, but I think it's really a trade-off between possible
short-term pain and the longer term simplification of unifying all wheel
handling under `wheel-*` events.
Also, I think we *will* have go through that pain sooner or later.


        Stefan

--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=xterm-wheel-events.patch

diff --git a/src/keyboard.c b/src/keyboard.c
index 7c1822b3423..a881c3d6117 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 fcbe7a1ec4f..237b705b555 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -14548,7 +14548,7 @@ x_query_pointer (Display *dpy, Window w, Window *root_return,
 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;
@@ -14563,9 +14563,7 @@ x_construct_mouse_click (struct input_event *result,
 			  : down_modifier));
 
   /* Convert pre-XInput2 wheel events represented as mouse-clicks.  */
-#ifdef HAVE_XINPUT2
-  if (!dpyinfo->supports_xi2)
-#endif
+  if (!xi2)
     {
       Lisp_Object base = base_mouse_symbol (result->code);
       int wheel
@@ -21895,13 +21893,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;
@@ -21971,13 +21970,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;
@@ -23754,13 +23755,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;

--=-=-=--





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.

Message received at 68796 <at> debbugs.gnu.org:


Received: (at 68796) by debbugs.gnu.org; 30 Jan 2024 02:00:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 29 21:00:57 2024
Received: from localhost ([127.0.0.1]:34076 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rUdQm-0005Ew-Sh
	for submit <at> debbugs.gnu.org; Mon, 29 Jan 2024 21:00:57 -0500
Received: from sonic308-10.consmr.mail.ne1.yahoo.com ([66.163.187.33]:34144)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <luangruo@HIDDEN>) id 1rUdQk-0005Eh-Aa
 for 68796 <at> debbugs.gnu.org; Mon, 29 Jan 2024 21:00:55 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
 t=1706580038; bh=gzy5P9ZVUiwUTEQUotATTA8FXbVArI9Zq6zL2wtJhd0=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To;
 b=Ch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R9oR3UXZ_eZagrpdyO_fw0llTdqciSKOX
 dHu2le.0-
X-Sonic-MF: <luangruo@HIDDEN>
X-Sonic-ID: 1e8b4973-028e-4ca0-91f7-501408d63369
Received: from sonic.gate.mail.ne1.yahoo.com by
 sonic308.consmr.mail.ne1.yahoo.com with HTTP; Tue, 30 Jan 2024 02:00:38 +0000
Received: by hermes--production-sg3-6dc75bc8fb-dgkh5 (Yahoo Inc. Hermes SMTP
 Server) with ESMTPA ID f2e1ce3e8951fe762de0f19ab4da2102; 
 Tue, 30 Jan 2024 02:00:29 +0000 (UTC)
From: Po Lu <luangruo@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#68796: xterm.c: Convert mouse-4/5/6/7 to
 wheel-up/down/left/right
In-Reply-To: <jwvh6iwmc5u.fsf@HIDDEN> (Stefan Monnier's message of
 "Mon, 29 Jan 2024 09:45:01 -0500")
References: <jwvh6iwmc5u.fsf@HIDDEN>
Date: Tue, 30 Jan 2024 10:00:17 +0800
Message-ID: <871q9zh972.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Mailer: WebService/1.1.22046
 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo
Content-Length: 3194
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68796
Cc: 68796 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Stefan Monnier <monnier@HIDDEN> writes:

>>From 60e6903ae12546db93f149b1f184ffc7ccdc30c2 Mon Sep 17 00:00:00 2001
> From: Stefan Monnier <monnier@HIDDEN>
> Date: Mon, 29 Jan 2024 09:35:09 -0500
> Subject: [PATCH] xterm.c: 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 those variables in `xterm.c` to directly
> convert those events into the standard `wheel-up/down/left/right` events
> used everywhere else.
>
> This simplifies the work of packages which can now just bind their
> commands to `wheel-up/down/left/right`.

I'm still opposed to this for reasons I will try to communicate below.
First, there are several logic errors in this patch:

> +  /* Convert pre-XInput2 wheel events represented as mouse-clicks.  */
> +#ifdef HAVE_XINPUT2
> +  if (!dpyinfo->supports_xi2)
> +#endif

dpyinfo->supports_xi2 is no guarantee that exclusively input extension
events will be received, but only indicates that the X display supports
the input extension.  There are several scenarios where it may be true
while core events are still delivered to windows, such as a combination
of GTK 3 and GDK_CORE_DEVICE_EVENTS=1's being enabled.  The correct test
of event type is whether x_construct_mouse_click is being called from
the XI_ButtonPress or XI_ButtonRelease label in handle_one_xevent.

Incidentally, servers with the input extension always assign buttons 4
through 7 to wheel movement.

> +      Lisp_Object base = base_mouse_symbol (result->code);
> +      int wheel
> +       /* BEWARE: `mouse-wheel-UP-event' corresponds to
> +          `wheel-DOWN' events and vice versa!!  */
> +        = BASE_EQ   (base, find_symbol_value (Qmouse_wheel_up_event))    ? 0
> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_down_event))  ? 1
> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_left_event))  ? 2
> +          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_right_event)) ? 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;
> +        }
> +    }

Isn't this insufficient to completely supersede mouse events by wheel
events, considering that such events will still be delivered as mouse
button events to tab bars?

Lastly, plenty of old code that binds just the button events will be
broken, and the code that keeps track of button-down and up events in
read_key_sequence and friends will cease applying to X wheel events.

This area has given me a lot of grief over the years (as it has given
you), so I'm reluctant to see any change there, as no matter how well
the argument in favor of its safety is posed, some unforeseen problem
invariably emerges afterwards.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.
Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 29 Jan 2024 14:45:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 29 09:45:47 2024
Received: from localhost ([127.0.0.1]:59372 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rUStO-0008VB-GE
	for submit <at> debbugs.gnu.org; Mon, 29 Jan 2024 09:45:47 -0500
Received: from lists.gnu.org ([2001:470:142::17]:34822)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rUStM-0008Ux-4f
 for submit <at> debbugs.gnu.org; Mon, 29 Jan 2024 09:45:45 -0500
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 <monnier@HIDDEN>)
 id 1rUSt5-0000hZ-80
 for bug-gnu-emacs@HIDDEN; Mon, 29 Jan 2024 09:45:30 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1rUSt2-0000RM-C9
 for bug-gnu-emacs@HIDDEN; Mon, 29 Jan 2024 09:45:26 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3CCB4440976
 for <bug-gnu-emacs@HIDDEN>; Mon, 29 Jan 2024 09:45:22 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1706539517;
 bh=xixryesPc0jyKV6gaBPu7LC/WGmhuV5g0W2ImPSjdek=;
 h=From:To:Subject:Date:From;
 b=g75fjC/U61TWXGsEmjtHmxt1agHNFYBwC7/6jPpA7z58DBuLDMqaS3VLXU3ycHjXh
 uQoyMt+3W26rmNsX/NjOiXXzvjIQgk7712K0pZyuu0i70q4wD3igmznHUQES4bpHB1
 Z6aczg9Z59IZG9q/F/tz+k30KQ/9OMK98tij8/fkgAKN7+jdE5DivuCgV2mPka+mYK
 bZaravxRfRvClzQ4KYBljVELCbOAXFj/ob0+R6IpB994b/Kz9W2bhZXmOM2/bq4LBi
 GfCtP3iCGOylShyEPJHf2/t/lHFReOIjgCIYM5UbPCclXVB5tMwlzxRohaoKrzSq5N
 emYsgmRc2RjpQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C187C442415
 for <bug-gnu-emacs@HIDDEN>; Mon, 29 Jan 2024 09:45:17 -0500 (EST)
Received: from pastel (unknown [45.72.206.68])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A43BB120C8F
 for <bug-gnu-emacs@HIDDEN>; Mon, 29 Jan 2024 09:45:17 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: xterm.c: Convert mouse-4/5/6/7 to wheel-up/down/left/right
Date: Mon, 29 Jan 2024 09:45:01 -0500
Message-ID: <jwvh6iwmc5u.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.000 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Tags: patch

Following up on the `xt-mouse.el` patch (bug#68698), I now propose we do
the same for those `mouse-4/5/6/7` events generated by old-style X11 input.

IIUC Po Lu wasn't favorable to the idea, but maybe seeing the code
will make a convert?

Beside that, the patch has 2 remaining issues:
- Lack of corresponding updates to `etc/NEWS` and `doc/lispref/commands.texi`.
- Lack of testing for the left/right remapping.  This is *really*
  necessary because even after (re)reading the various parts of the code
  that handle horizontal scrolling, I'm still very much unsure if I got
  the direction right[left?], so if you have a mouse with a horizontal wheel,
  please compare the `wheel-left/right` events generated with and
  without building `--without-xinput2`.


        Stefan

 In GNU Emacs 30.0.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2024-01-25 built on pastel
Repository revision: 5945fab9af0b52cc55f06b2c7e911d51e34a9cdf
Repository branch: work
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure -C --enable-checking --enable-check-lisp-object-type --with-modules --with-cairo --with-tiff=ifavailable
 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign' --without-native-compilation
 PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0001-xterm.c-Map-old-style-wheel-buttons-to-actual-wheel-.patch

From 60e6903ae12546db93f149b1f184ffc7ccdc30c2 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@HIDDEN>
Date: Mon, 29 Jan 2024 09:35:09 -0500
Subject: [PATCH] xterm.c: 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 those variables in `xterm.c` to directly
convert those events into the standard `wheel-up/down/left/right` events
used everywhere else.

This simplifies the work of packages which can now just bind their
commands to `wheel-up/down/left/right`.

* src/keyboard.c (base_mouse_symbol): New function.
* src/keyboard.h (base_mouse_symbol): Declare.
* src/xterm.c (x_construct_mouse_click): Obey `mouse-wheel-*-event` vars.
(syms_of_xterm): Define the `mouse-wheel-*-event` symbols.

* lisp/completion-preview.el (completion-preview--mouse-map): Don't
bind to `mouse-wheel-*-event`s any more.
* lisp/edmacro.el (edmacro-fix-menu-commands): Remove special casing of
`mouse-wheel-*-event`s.
* lisp/mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Remove :set.
(mouse-wheel--setup-bindings): Don't bind to `mouse-wheel-*-event`s any more.
* lisp/progmodes/flymake.el (flymake--mode-line-counter-map): Don't
bind to `mouse-wheel-*-event`s any more if Emacs is recent enough.
---
 lisp/completion-preview.el | 10 +---------
 lisp/edmacro.el            |  8 +-------
 lisp/mwheel.el             | 31 +++++++++++--------------------
 lisp/progmodes/flymake.el  | 19 +++++++++----------
 src/fns.c                  |  1 +
 src/keyboard.c             |  9 +++++++++
 src/keyboard.h             |  2 +-
 src/xterm.c                | 31 +++++++++++++++++++++++++++++--
 8 files changed, 62 insertions(+), 49 deletions(-)

diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el
index 6fd60f3c416..6bbf1246a9a 100644
--- a/lisp/completion-preview.el
+++ b/lisp/completion-preview.el
@@ -52,8 +52,6 @@
 
 ;;; Code:
 
-(require 'mwheel)
-
 (defgroup completion-preview nil
   "In-buffer completion preview."
   :group 'completion)
@@ -135,14 +133,8 @@ completion-preview--mouse-map
   "<down-mouse-1>" #'completion-preview-insert
   "C-<down-mouse-1>" #'completion-at-point
   "<down-mouse-2>" #'completion-at-point
-  ;; BEWARE: `mouse-wheel-UP-event' corresponds to `wheel-DOWN' events
-  ;; and vice versa!!
   "<wheel-up>"     #'completion-preview-prev-candidate
-  "<wheel-down>"   #'completion-preview-next-candidate
-  (key-description (vector mouse-wheel-up-event))
-  #'completion-preview-next-candidate
-  (key-description (vector mouse-wheel-down-event))
-  #'completion-preview-prev-candidate)
+  "<wheel-down>"   #'completion-preview-next-candidate)
 
 (defvar-local completion-preview--overlay nil)
 
diff --git a/lisp/edmacro.el b/lisp/edmacro.el
index abfc380d154..a80fe973240 100644
--- a/lisp/edmacro.el
+++ b/lisp/edmacro.el
@@ -725,10 +725,6 @@ edmacro-fix-menu-commands
       (let (result)
         ;; Not preloaded in a --without-x build.
         (require 'mwheel)
-        (defvar mouse-wheel-down-event)
-        (defvar mouse-wheel-up-event)
-        (defvar mouse-wheel-right-event)
-        (defvar mouse-wheel-left-event)
 	;; Make a list of the elements.
 	(setq macro (append macro nil))
 	(dolist (ev macro)
@@ -744,9 +740,7 @@ edmacro-fix-menu-commands
 		;; info is recorded in macros to make this possible.
 		((or (mouse-event-p ev) (mouse-movement-p ev)
 		     (memq (event-basic-type ev)
-			   `( ,mouse-wheel-down-event ,mouse-wheel-up-event
-			      ,mouse-wheel-right-event ,mouse-wheel-left-event
-			      wheel-down wheel-up wheel-left wheel-right)))
+			   '(wheel-down wheel-up wheel-left wheel-right)))
 		 nil)
 		(noerror nil)
 		(t
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 66a1fa1a706..82a2c48fd5d 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -65,15 +65,13 @@ mouse-wheel-down-event
   (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-4)
   "Event used for scrolling down, beside `wheel-up', if any."
   :group 'mouse
-  :type 'symbol
-  :set #'mouse-wheel-change-button)
+  :type 'symbol)
 
 (defcustom mouse-wheel-up-event
   (if mouse-wheel-obey-old-style-wheel-buttons 'mouse-5)
   "Event used for scrolling up, beside `wheel-down', if any."
   :group 'mouse
-  :type 'symbol
-  :set #'mouse-wheel-change-button)
+  :type 'symbol)
 
 (defcustom mouse-wheel-click-event 'mouse-2
   "Event that should be temporarily inhibited after mouse scrolling.
@@ -464,25 +462,18 @@ mouse-wheel--setup-bindings
     (cond
      ;; Bindings for changing font size.
      ((and (consp binding) (eq (cdr binding) 'text-scale))
-      (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                           'wheel-down 'wheel-up))
-        (when event
-          (mouse-wheel--add-binding `[,(append (car binding) (list event))]
-                                    'mouse-wheel-text-scale))))
+      (dolist (event '(wheel-down wheel-up))
+        (mouse-wheel--add-binding `[,(append (car binding) (list event))]
+                                  'mouse-wheel-text-scale)))
      ((and (consp binding) (eq (cdr binding) 'global-text-scale))
-      (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                           'wheel-down 'wheel-up))
-        (when event
-          (mouse-wheel--add-binding `[,(append (car binding) (list event))]
-                                    'mouse-wheel-global-text-scale))))
+      (dolist (event '(wheel-down wheel-up))
+        (mouse-wheel--add-binding `[,(append (car binding) (list event))]
+                                  'mouse-wheel-global-text-scale)))
      ;; Bindings for scrolling.
      (t
-      (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                           mouse-wheel-left-event mouse-wheel-right-event
-                           'wheel-down 'wheel-up 'wheel-left 'wheel-right))
-        (when event
-          (dolist (key (mouse-wheel--create-scroll-keys binding event))
-            (mouse-wheel--add-binding key 'mwheel-scroll))))))))
+      (dolist (event '(wheel-down wheel-up wheel-left wheel-right))
+        (dolist (key (mouse-wheel--create-scroll-keys binding event))
+          (mouse-wheel--add-binding key 'mwheel-scroll)))))))
 
 (when mouse-wheel-mode
   (mouse-wheel--setup-bindings))
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 5974f076556..1411a669891 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -114,10 +114,6 @@
 (require 'thingatpt) ; end-of-thing
 (require 'warnings) ; warning-numeric-level, display-warning
 (require 'compile) ; for some faces
-;; We need the next `require' to avoid compiler warnings and run-time
-;; errors about mouse-wheel-up/down-event in builds --without-x, where
-;; mwheel is not preloaded.
-(require 'mwheel)
 ;; when-let*, if-let*, hash-table-keys, hash-table-values:
 (eval-when-compile (require 'subr-x))
 (require 'project)
@@ -1637,16 +1633,19 @@ flymake--mode-line-counter-scroll-next
 
 (defvar flymake--mode-line-counter-map
   (let ((map (make-sparse-keymap)))
-    ;; BEWARE: `mouse-wheel-UP-event' corresponds to `wheel-DOWN' events
-    ;; and vice versa!!
-    (define-key map (vector 'mode-line mouse-wheel-down-event)
-                #'flymake--mode-line-counter-scroll-prev)
     (define-key map [mode-line wheel-down]
                 #'flymake--mode-line-counter-scroll-next)
-    (define-key map (vector 'mode-line mouse-wheel-up-event)
-                #'flymake--mode-line-counter-scroll-next)
     (define-key map [mode-line wheel-up]
                 #'flymake--mode-line-counter-scroll-prev)
+    (when (< emacs-major-version 30)
+      (require 'mwheel)
+      (defvar mouse-wheel-down-event) (defvar mouse-wheel-up-event)
+      ;; BEWARE: `mouse-wheel-UP-event' corresponds to `wheel-DOWN' events
+      ;; and vice versa!!
+      (define-key map (vector 'mode-line mouse-wheel-down-event)
+                  #'flymake--mode-line-counter-scroll-prev)
+      (define-key map (vector 'mode-line mouse-wheel-up-event)
+                  #'flymake--mode-line-counter-scroll-next))
     map))
 
 (defun flymake--mode-line-counter-1 (type)
diff --git a/src/fns.c b/src/fns.c
index e4fa8157000..48d7b217cb6 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4855,6 +4855,7 @@ check_mutable_hash_table (Lisp_Object obj, struct Lisp_Hash_Table *h)
    HASH is a previously computed hash code of KEY.
    Value is the index of the entry in H matching KEY.  */
 
+/* FIXME: Callers shouldn't care about the return value!  */
 ptrdiff_t
 hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value,
 	  hash_hash_t hash)
diff --git a/src/keyboard.c b/src/keyboard.c
index 1f7253a7da1..7c1822b3423 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -7597,6 +7597,15 @@ modify_event_symbol (ptrdiff_t symbol_num, int modifiers, Lisp_Object symbol_kin
   /* Apply modifiers to that symbol.  */
   return apply_modifiers (modifiers, value);
 }
+
+Lisp_Object
+base_mouse_symbol (int button)
+{
+   return modify_event_symbol (button, 0,
+			       Qmouse_click, Vlispy_mouse_stem,
+			       NULL, &mouse_syms, ASIZE (mouse_syms));
+}
+
 
 /* Convert a list that represents an event type,
    such as (ctrl meta backspace), into the usual representation of that
diff --git a/src/keyboard.h b/src/keyboard.h
index 68e68bc2ae3..083b16e4896 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -456,7 +456,7 @@ #define EVENT_HEAD_KIND(event_head) \
 extern Lisp_Object read_char (int, Lisp_Object, Lisp_Object,
                               bool *, struct timespec *);
 extern int parse_solitary_modifier (Lisp_Object symbol);
-
+extern Lisp_Object base_mouse_symbol (int button);
 
 /* This is like Vthis_command, except that commands never set it.  */
 extern Lisp_Object real_this_command;
diff --git a/src/xterm.c b/src/xterm.c
index c8a43785564..fcbe7a1ec4f 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -14553,8 +14553,6 @@ x_construct_mouse_click (struct input_event *result,
   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 +14562,30 @@ x_construct_mouse_click (struct input_event *result,
 			  ? up_modifier
 			  : down_modifier));
 
+  /* Convert pre-XInput2 wheel events represented as mouse-clicks.  */
+#ifdef HAVE_XINPUT2
+  if (!dpyinfo->supports_xi2)
+#endif
+    {
+      Lisp_Object base = base_mouse_symbol (result->code);
+      int wheel
+       /* BEWARE: `mouse-wheel-UP-event' corresponds to
+          `wheel-DOWN' events and vice versa!!  */
+        = BASE_EQ   (base, find_symbol_value (Qmouse_wheel_up_event))    ? 0
+          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_down_event))  ? 1
+          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_left_event))  ? 2
+          : BASE_EQ (base, find_symbol_value (Qmouse_wheel_right_event)) ? 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.  */
@@ -32444,6 +32466,11 @@ syms_of_xterm (void)
   DEFSYM (Qexpose, "expose");
   DEFSYM (Qdont_save, "dont-save");
 
+  DEFSYM (Qmouse_wheel_down_event, "mouse-wheel-down-event");
+  DEFSYM (Qmouse_wheel_up_event, "mouse-wheel-up-event");
+  DEFSYM (Qmouse_wheel_left_event, "mouse-wheel-left-event");
+  DEFSYM (Qmouse_wheel_right_event, "mouse-wheel-right-event");
+
 #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


--=-=-=--





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#68796; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 3 Mar 2024 16:30:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.