From bfb2eb87fac877617066105525d0afa88bfbc051 Mon Sep 17 00:00:00 2001 From: Chris Salch Date: Mon, 4 Aug 2008 20:19:47 -0500 Subject: [PATCH] Adding a function to map button events to button numbers --- src/evdev.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/evdev.h | 1 + 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 670cbb2..b149459 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1216,3 +1216,45 @@ _X_EXPORT XF86ModuleData evdevModuleData = EvdevPlug, EvdevUnplug }; + + +/* Return an index value for a given button event code + * returns -1 on invalid value. + */ +unsigned char +EvdevUtilButtonEventToButtonNumber(int code) +{ + unsigned char button = 0; + switch(code) { + case BTN_LEFT: + button = 1; + break; + + case BTN_RIGHT: + button = 3; + break; + + case BTN_MIDDLE: + button = 2; + break; + + case BTN_SIDE: + case BTN_EXTRA: + case BTN_FORWARD: + case BTN_BACK: + case BTN_TASK: + button = (code - BTN_LEFT + 5); + break; + + default: + if ((code > BTN_TASK) && (code < KEY_OK)) { + if (code < BTN_JOYSTICK) + button = (code - BTN_LEFT + 5); + } + } + + if (button > 32) + return 0; + + return button; +} diff --git a/src/evdev.h b/src/evdev.h index bc79287..692e381 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -86,4 +86,5 @@ Atom EvdevMBEmuInitPropertyTimeout(DeviceIntPtr, char*); BOOL EvdevMBEmuSetProperty(DeviceIntPtr, Atom, XIPropertyValuePtr); #endif +unsigned char EvdevUtilButtonEventToButtonNumber(int code); #endif -- 1.5.6.3