From 5e9b027807cc205dc9c4efbb8360ac4b20317682 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 31 Oct 2011 08:58:18 +1000 Subject: Replace 0/1 button values with enums BUTTON_PRESS is much harder to confuse with a button number than a simple 1. Signed-off-by: Peter Hutterer --- src/emuMB.c | 3 ++- src/emuThird.c | 19 ++++++++++--------- src/evdev.c | 5 +++-- src/evdev.h | 7 ++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/emuMB.c b/src/emuMB.c index b7a57b8..eb01495 100644 --- a/src/emuMB.c +++ b/src/emuMB.c @@ -191,7 +191,8 @@ EvdevMBEmuTimer(InputInfoPtr pInfo) pEvdev->emulateMB.pending = FALSE; if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) { - EvdevPostButtonEvent(pInfo, abs(id), (id >= 0)); + EvdevPostButtonEvent(pInfo, abs(id), + (id >= 0) ? BUTTON_PRESS : BUTTON_RELEASE); pEvdev->emulateMB.state = stateTab[pEvdev->emulateMB.state][4][2]; } else { diff --git a/src/emuThird.c b/src/emuThird.c index d89fd9e..7461767 100644 --- a/src/emuThird.c +++ b/src/emuThird.c @@ -58,7 +58,7 @@ enum EmulationState { }; static void -Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, int press) +Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act) { EvdevPtr pEvdev = pInfo->private; struct emulate3B *emu3B = &pEvdev->emulate3B; @@ -72,7 +72,8 @@ Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, int press) if (emu3B->flags & EVDEV_ABSOLUTE_EVENTS) absolute = Absolute; - xf86PostButtonEventP(pInfo->dev, absolute, button, press, 0, + xf86PostButtonEventP(pInfo->dev, absolute, button, + (act == BUTTON_PRESS) ? 1 : 0, 0, (absolute ? 2 : 0), emu3B->startpos); } @@ -92,7 +93,7 @@ Evdev3BEmuTimer(OsTimerPtr timer, CARD32 time, pointer arg) sigstate = xf86BlockSIGIO (); emu3B->state = EM3B_EMULATING; - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 1); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_PRESS); xf86UnblockSIGIO (sigstate); return 0; } @@ -145,14 +146,14 @@ Evdev3BEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press) switch (emu3B->state) { case EM3B_PENDING: - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); break; case EM3B_EMULATING: /* We're emulating and now the user pressed a different * button. Just release the emulating one, tell the user to * not do that and get on with life */ - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 0); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE); Evdev3BCancel(pInfo); break; default: @@ -171,11 +172,11 @@ Evdev3BEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press) switch(emu3B->state) { case EM3B_PENDING: - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); break; case EM3B_EMULATING: - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 0); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE); Evdev3BCancel(pInfo); ret = TRUE; break; @@ -237,7 +238,7 @@ Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals) if (cancel) { - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); } } @@ -262,7 +263,7 @@ Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy) if (abs(emu3B->delta[0]) > emu3B->threshold || abs(emu3B->delta[1]) > emu3B->threshold) { - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); } } diff --git a/src/evdev.c b/src/evdev.c index 13b1e10..4bb55f5 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -411,9 +411,10 @@ EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch, ValuatorMask *mask, * Interface for MB emulation since these need to post immediately. */ void -EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value) +EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act) { - xf86PostButtonEvent(pInfo->dev, Relative, button, value, 0, 0); + xf86PostButtonEvent(pInfo->dev, Relative, button, + (act == BUTTON_PRESS) ? 1 : 0, 0, 0); } void diff --git a/src/evdev.h b/src/evdev.h index 27e404c..5fd99ff 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -107,6 +107,11 @@ enum SlotState { SLOTSTATE_EMPTY, }; +enum ButtonAction { + BUTTON_RELEASE = 0, + BUTTON_PRESS = 1 +}; + /* axis specific data for wheel emulation */ typedef struct { int up_button; @@ -248,7 +253,7 @@ void EvdevQueueProximityEvent(InputInfoPtr pInfo, int value); void EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch, ValuatorMask *mask, uint16_t type); #endif -void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value); +void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act); void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count); void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v, int v[MAX_VALUATORS]); -- cgit v1.2.3