summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@redhat.com>2008-10-29 13:50:07 +1030
committerPeter Hutterer <peter.hutterer@redhat.com>2008-10-29 17:05:58 +1030
commit64554e4799a697d37dfd8be480f8eee636b9bea1 (patch)
tree3a118ee034db37e89287a1d55d9320535df50ec4
parentb77f9398570fb8eae1fcf50bc3c10c9c390c6bac (diff)
Treat BTN_[0-2] as LMR buttons if necessary.
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@redhat.com>
-rw-r--r--src/evdev.c27
-rw-r--r--src/evdev.h2
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);