[PATCH] Treat BTN_[0-2] as LMR buttons if necessary.

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 28 23:38:33 PDT 2008


Treat BTN_[0-2] as LMR buttons on devices that do not advertise BTN_LEFT,
BTN_MIDDLE, BTN_RIGHT (e.g. 3Dconnexion SpaceNavigator).

Otherwise, treat BTN_[0+n] as button 5+n. Note: This causes duplicate
mappings for BTN_0 + n and  BTN_SIDE + n.

This also fixes a bug where we could end up with negative button numbers after
trying to map BTN_0.

Signed-off-by: Peter Hutterer <peter.hutterer at redhat.com>
---
 src/evdev.c |   27 +++++++++++++++++++++++----
 src/evdev.h |    2 +-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index cc072d8..9ef2829 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -326,7 +326,7 @@ EvdevReadInput(InputInfoPtr pInfo)
                 /* Intentional fallthrough! */
 
             default:
-		button = EvdevUtilButtonEventToButtonNumber(ev.code);
+		button = EvdevUtilButtonEventToButtonNumber(pEvdev, ev.code);
 
 		/* Handle drag lock */
 		if (EvdevDragLockFilterEvent(pInfo, button, value))
@@ -1448,7 +1448,7 @@ _X_EXPORT XF86ModuleData evdevModuleData =
  * returns 0 on non-button event.
  */
 unsigned int
-EvdevUtilButtonEventToButtonNumber(int code)
+EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code)
 {
     unsigned int button = 0;
 
@@ -1465,6 +1465,21 @@ EvdevUtilButtonEventToButtonNumber(int code)
 	button = 2;
 	break;
 
+        /* Treat BTN_[0-2] as LMR buttons on devices that do not advertise
+           BTN_LEFT, BTN_MIDDLE, BTN_RIGHT.
+           Otherwise, treat BTN_[0+n] as button 5+n.
+           XXX: This causes duplicate mappings for BTN_0 + n and BTN_SIDE + n
+         */
+    case BTN_0:
+        button = (TestBit(BTN_LEFT, pEvdev->key_bitmask)) ?  8 : 1;
+        break;
+    case BTN_1:
+        button = (TestBit(BTN_MIDDLE, pEvdev->key_bitmask)) ?  9 : 2;
+        break;
+    case BTN_2:
+        button = (TestBit(BTN_RIGHT, pEvdev->key_bitmask)) ?  10 : 3;
+        break;
+
     case BTN_SIDE:
     case BTN_EXTRA:
     case BTN_FORWARD:
@@ -1475,8 +1490,12 @@ EvdevUtilButtonEventToButtonNumber(int code)
 
     default:
 	if ((code > BTN_TASK) && (code < KEY_OK)) {
-	    if (code < BTN_JOYSTICK)
-		button = (code - BTN_LEFT + 5);
+	    if (code < BTN_JOYSTICK) {
+                if (code < BTN_MOUSE)
+                    button = (code - BTN_0 + 5);
+                else
+                    button = (code - BTN_LEFT + 5);
+            }
 	}
     }
 
diff --git a/src/evdev.h b/src/evdev.h
index 7e1da15..5a97185 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -119,7 +119,7 @@ typedef struct {
     struct input_absinfo absinfo[ABS_MAX];
 } EvdevRec, *EvdevPtr;
 
-unsigned int EvdevUtilButtonEventToButtonNumber(int code);
+unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
 
 /* Middle Button emulation */
 int  EvdevMBEmuTimer(InputInfoPtr);
-- 
1.5.4.3





More information about the xorg mailing list