[Xquartz-dev] [PATCH] improve translation of additional mouse buttons

Christopher Chavez chrischavez at gmx.us
Thu Jul 25 06:22:13 PDT 2019


Hello XQuartz-dev,

I noticed that XQuartz translates any button that isn't the left and
right mouse button to act as button 2. While this correctly handles the
middle mouse button, I believe it incorrectly handles additional buttons
that appear on some mice (not necessarily Apple-branded ones). These
mouse buttons normally appear as buttons 8 and higher under X11 on
recent Linux and BSD distributions.

This patch modifies the code translating the mouse buttons to continue
mapping the middle mouse button to 2, while mapping any additional
buttons to 8 and higher (skipping over buttons 4 to 7 as they are used
for scrolling). I have attached the patch, and have already opened a
merge request for it:

https://gitlab.freedesktop.org/xorg/xserver/merge_requests/239

I would appreciate any feedback or testing. One possible issue I might
need help with addressing is whether a maximum number of additional
buttons to handle should be set.

Thanks,

Christopher A. Chavez
-------------- next part --------------
From bef6d890f57b4750cc1afb9ad1407f440214c804 Mon Sep 17 00:00:00 2001
From: Christopher Chavez <chrischavez at gmx.us>
Date: Mon, 22 Jul 2019 13:52:37 +0000
Subject: [PATCH] XQuartz: translate additional mouse buttons

Old behavior was to translate the middle mouse button, as well as
every other button that isn't the left or right mouse button,
to act as the middle mouse button (2).

New behavior is to translate only the middle mouse button to 2,
and translate higher-numbered buttons to 8 and higher.
This allows additional mouse buttons to behave under XQuartz
more like they do by default under X11 on many modern Linux
and BSD distributions.

Signed-off-by: Christopher Chavez <chrischavez at gmx.us>
---
 hw/xquartz/X11Application.m | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 821e1c5a1..aa05e891d 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1473,7 +1473,8 @@ wait_for_mieq_init(void);
         goto handle_mouse;
 
     case NSOtherMouseDown:
-        ev_button = 2;
+        ev_button = [e buttonNumber] + 1;
+        ev_button = (ev_button == 3) ? 2 : (ev_button + 4);
         ev_type = ButtonPress;
         goto handle_mouse;
 
@@ -1488,7 +1489,8 @@ wait_for_mieq_init(void);
         goto handle_mouse;
 
     case NSOtherMouseUp:
-        ev_button = 2;
+        ev_button = [e buttonNumber] + 1;
+        ev_button = (ev_button == 3) ? 2 : (ev_button + 4);
         ev_type = ButtonRelease;
         goto handle_mouse;
 
@@ -1503,7 +1505,8 @@ wait_for_mieq_init(void);
         goto handle_mouse;
 
     case NSOtherMouseDragged:
-        ev_button = 2;
+        ev_button = [e buttonNumber] + 1;
+        ev_button = (ev_button == 3) ? 2 : (ev_button + 4);
         ev_type = MotionNotify;
         goto handle_mouse;
 
-- 
2.21.0



More information about the Xquartz-dev mailing list