aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Salch <emeraldd.chris@gmail.com>2008-08-04 20:19:47 -0500
committerPeter Hutterer <peter.hutterer@who-t.net>2008-08-06 16:36:51 +0930
commit40e1474d84c09d93197ac5db34a88e654386e68f (patch)
treef782fa7dbcc08cde80feb68b9a0c3ab8b90850e9 /src
parentActually close the fd on DEVICE_CLOSE (bug#16948) (diff)
downloadxf86-input-evdev-40e1474d84c09d93197ac5db34a88e654386e68f.tar.gz
xf86-input-evdev-40e1474d84c09d93197ac5db34a88e654386e68f.tar.bz2
xf86-input-evdev-40e1474d84c09d93197ac5db34a88e654386e68f.zip
Adding a function to map button events to button numbers.
Remove code duplication, let the mapping function hand us the actual button event to be passed up to the server. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/emuMB.c10
-rw-r--r--src/evdev.c85
-rw-r--r--src/evdev.h3
3 files changed, 60 insertions, 38 deletions
diff --git a/src/emuMB.c b/src/emuMB.c
index 07d8989..1992654 100644
--- a/src/emuMB.c
+++ b/src/emuMB.c
@@ -212,14 +212,14 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
/**
* Emulate a middle button on button press.
*
- * @param code Evdev event code (BTN_LEFT or BTN_RIGHT)
+ * @param code button number (1 for left, 3 for right)
* @param press TRUE if press, FALSE if release.
*
* @return TRUE if event was swallowed by middle mouse button emulation, FALSE
* otherwise.
*/
BOOL
-EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int code, BOOL press)
+EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
{
EvdevPtr pEvdev = pInfo->private;
int id;
@@ -230,14 +230,14 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int code, BOOL press)
return ret;
/* don't care about other buttons */
- if (code != BTN_LEFT && code != BTN_RIGHT)
+ if (button != 1 && button != 3)
return ret;
btstate = &pEvdev->emulateMB.buttonstate;
if (press)
- *btstate |= (code == BTN_LEFT) ? 0x1 : 0x2;
+ *btstate |= (button == 1) ? 0x1 : 0x2;
else
- *btstate &= (code == BTN_LEFT) ? ~0x1 : ~0x2;
+ *btstate &= (button == 1) ? ~0x1 : ~0x2;
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
{
diff --git a/src/evdev.c b/src/evdev.c
index 670cbb2..9c15d5b 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -191,6 +191,7 @@ EvdevReadInput(InputInfoPtr pInfo)
int len, value;
int dx, dy;
unsigned int abs;
+ unsigned int button;
EvdevPtr pEvdev = pInfo->private;
dx = 0;
@@ -257,29 +258,6 @@ EvdevReadInput(InputInfoPtr pInfo)
break;
switch (ev.code) {
- /* swap here, pretend we're an X-conformant device. */
- case BTN_LEFT:
- if (!EvdevMBEmuFilterEvent(pInfo, ev.code, value))
- xf86PostButtonEvent(pInfo->dev, 0, 1, value, 0, 0);
- break;
- case BTN_RIGHT:
- if (!EvdevMBEmuFilterEvent(pInfo, ev.code, value))
- xf86PostButtonEvent(pInfo->dev, 0, 3, value, 0, 0);
- break;
- case BTN_MIDDLE:
- EvdevMBEmuEnable(pInfo, FALSE);
- xf86PostButtonEvent(pInfo->dev, 0, 2, value, 0, 0);
- break;
-
- case BTN_SIDE:
- case BTN_EXTRA:
- case BTN_FORWARD:
- case BTN_BACK:
- case BTN_TASK:
- xf86PostButtonEvent(pInfo->dev, 0, ev.code - BTN_LEFT + 5,
- value, 0, 0);
- break;
-
case BTN_TOUCH:
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
@@ -293,17 +271,15 @@ EvdevReadInput(InputInfoPtr pInfo)
break;
default:
- if (ev.code > BTN_TASK && ev.code < KEY_OK) {
- /* Some fancy mice with a lot of buttons generate
- * button events between BTN_TASK and BTN_JOYSTICK */
- if (ev.code < BTN_JOYSTICK)
- xf86PostButtonEvent(pInfo->dev, 0,
- ev.code - BTN_LEFT + 5,
- value, 0, 0);
- break;
- }
+ button = EvdevUtilButtonEventToButtonNumber(ev.code);
- PostKbdEvent(pInfo, &ev, value);
+ if (EvdevMBEmuFilterEvent(pInfo, button, value))
+ break;
+
+ if (button)
+ xf86PostButtonEvent(pInfo->dev, 0, button, value, 0, 0);
+ else
+ PostKbdEvent(pInfo, &ev, value);
break;
}
break;
@@ -1216,3 +1192,46 @@ _X_EXPORT XF86ModuleData evdevModuleData =
EvdevPlug,
EvdevUnplug
};
+
+
+/* Return an index value for a given button event code
+ * returns 0 on non-button event.
+ */
+unsigned int
+EvdevUtilButtonEventToButtonNumber(int code)
+{
+ unsigned int 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..56983c2 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -80,6 +80,9 @@ void EvdevMBEmuBlockHandler(pointer, struct timeval**, pointer);
void EvdevMBEmuPreInit(InputInfoPtr);
void EvdevMBEmuFinalize(InputInfoPtr);
void EvdevMBEmuEnable(InputInfoPtr, BOOL);
+
+unsigned int EvdevUtilButtonEventToButtonNumber(int code);
+
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
Atom EvdevMBEmuInitProperty(DeviceIntPtr, char*);
Atom EvdevMBEmuInitPropertyTimeout(DeviceIntPtr, char*);