From 860f92bac27717e7dac7c21848aad773c9fcd651 Mon Sep 17 00:00:00 2001 From: Chris Salch Date: Mon, 4 Aug 2008 20:38:24 -0500 Subject: [PATCH] Possible cleanup of evdev.c to avoid code duplication --- src/evdev.c | 51 ++++++++++++++++----------------------------------- 1 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index b149459..5243ec0 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 char 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: @@ -291,19 +269,22 @@ EvdevReadInput(InputInfoPtr pInfo) case BTN_TOOL_LENS: pEvdev->tool = value ? ev.code : 0; break; + + case BTN_LEFT: + case BTN_RIGHT: + case BTN_MIDDLE: + if (EvdevMBEmuFilterEvent(pInfo, ev.code, value)) + 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; - } - - PostKbdEvent(pInfo, &ev, value); + button = EvdevUtilButtonEventToButtonNumber(ev.code); + if (button) + /* Add filter logic not requiring explicit button events + here to avoid doing this conversion over and over + again. */ + xf86PostButtonEvent(pInfo->dev, 0, button, value, 0, 0); + else + PostKbdEvent(pInfo, &ev, value); break; } break; @@ -1219,7 +1200,7 @@ _X_EXPORT XF86ModuleData evdevModuleData = /* Return an index value for a given button event code - * returns -1 on invalid value. + * returns 0 on non-button event. */ unsigned char EvdevUtilButtonEventToButtonNumber(int code) -- 1.5.6.3