On Thu, Aug 5, 2010 at 11:17 PM, Peter Hutterer <[email protected]> wrote: > Instead of a separate variables, keep just one array with all values. Keep > x/y for readability though, they just point to the first two spots in the > array. > > Aside from prettier function signatures, we can now call up priv->naxes once > instead of relying on magic state. > > Signed-off-by: Peter Hutterer <[email protected]>
Acked-by: Ping Cheng <[email protected]> > --- > src/wcmCommon.c | 157 > +++++++++++++++++++++++++++---------------------------- > 1 files changed, 77 insertions(+), 80 deletions(-) > > diff --git a/src/wcmCommon.c b/src/wcmCommon.c > index 5287bf5..c567bca 100644 > --- a/src/wcmCommon.c > +++ b/src/wcmCommon.c > @@ -42,7 +42,7 @@ static void commonDispatchDevice(WacomCommonPtr common, > unsigned int channel, > const WacomChannelPtr pChannel, int suppress); > static void resetSampleCounter(const WacomChannelPtr pChannel); > static void sendAButton(InputInfoPtr pInfo, int button, int mask, > - int rx, int ry, int rz, int v3, int v4, int v5); > + int naxes, int *valuators); > > /***************************************************************************** > * Utility functions > @@ -238,8 +238,7 @@ static void wcmSetScreen(InputInfoPtr pInfo, int v0, int > v1) > * previous one. > ****************************************************************************/ > > -static void wcmSendButtons(InputInfoPtr pInfo, int buttons, int rx, int ry, > - int rz, int v3, int v4, int v5) > +static void wcmSendButtons(InputInfoPtr pInfo, int buttons, int naxes, int > *valuators) > { > int button, mask; > WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; > @@ -257,7 +256,7 @@ static void wcmSendButtons(InputInfoPtr pInfo, int > buttons, int rx, int ry, > > if (buttons == 1) { > /* Button 1 pressed */ > - sendAButton(pInfo, 0, 1, rx, ry, rz, > v3, v4, v5); > + sendAButton(pInfo, 0, 1, naxes, > valuators); > } else { > /* send all pressed buttons down */ > for (button=2; > button<=WCM_MAX_BUTTONS; button++) > @@ -266,8 +265,7 @@ static void wcmSendButtons(InputInfoPtr pInfo, int > buttons, int rx, int ry, > if ( buttons & mask ) > { > /* set to the > configured button */ > - sendAButton(pInfo, > button-1, 1, rx, ry, > - rz, > v3, v4, v5); > + sendAButton(pInfo, > button-1, 1, naxes, valuators); > } > } > } > @@ -281,7 +279,7 @@ static void wcmSendButtons(InputInfoPtr pInfo, int > buttons, int rx, int ry, > { > /* set to the configured > buttons */ > sendAButton(pInfo, button-1, > mask & buttons, > - rx, ry, rz, v3, v4, > v5); > + naxes, valuators); > } > } > } > @@ -297,8 +295,8 @@ static void wcmSendButtons(InputInfoPtr pInfo, int > buttons, int rx, int ry, > if ((mask & priv->oldButtons) != (mask & > buttons) || (mask & buttons) ) > { > /* set to the configured button */ > - sendAButton(pInfo, button-1, 0, rx, > ry, > - rz, v3, v4, v5); > + sendAButton(pInfo, button-1, 0, > + naxes, valuators); > } > } > } > @@ -311,8 +309,8 @@ static void wcmSendButtons(InputInfoPtr pInfo, int > buttons, int rx, int ry, > if ((mask & priv->oldButtons) != (mask & buttons)) > { > /* set to the configured button */ > - sendAButton(pInfo, button-1, mask & buttons, > rx, ry, > - rz, v3, v4, v5); > + sendAButton(pInfo, button-1, mask & buttons, > + naxes, valuators); > } > } > } > @@ -378,7 +376,7 @@ static int countPresses(int keybtn, unsigned int* keys, > int size) > * Send one button event, called by wcmSendButtons > ****************************************************************************/ > static void sendAButton(InputInfoPtr pInfo, int button, int mask, > - int rx, int ry, int rz, int v3, int v4, int v5) > + int naxes, int *valuators) > { > WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; > #ifdef DEBUG > @@ -386,8 +384,6 @@ static void sendAButton(InputInfoPtr pInfo, int button, > int mask, > #endif > int i; > > - int naxes = priv->naxes; > - > if (!priv->button[button]) /* ignore this button event */ > return; > > @@ -400,8 +396,8 @@ static void sendAButton(InputInfoPtr pInfo, int button, > int mask, > if (!priv->keys[button][0]) > { > /* No button action configured, send button */ > - xf86PostButtonEvent(pInfo->dev, is_absolute(pInfo), > priv->button[button], (mask != 0), 0, naxes, > - rx, ry, rz, v3, v4, v5); > + xf86PostButtonEventP(pInfo->dev, is_absolute(pInfo), > priv->button[button], (mask != 0), 0, naxes, > + valuators); > return; > } > > @@ -422,7 +418,7 @@ static void sendAButton(InputInfoPtr pInfo, int button, > int mask, > xf86PostButtonEvent(pInfo->dev, > > is_absolute(pInfo), btn_no, > is_press, 0, naxes, > - rx, ry, rz, v3, > v4, v5); > + valuators); > } > break; > case AC_KEY: > @@ -441,13 +437,13 @@ static void sendAButton(InputInfoPtr pInfo, int button, > int mask, > * there's no reason to have a DBLCLICK */ > case AC_DBLCLICK: > xf86PostButtonEvent(pInfo->dev, > is_absolute(pInfo), > - 1,1,0,naxes, > rx,ry,rz,v3,v4,v5); > + 1,1,0,naxes,valuators); > xf86PostButtonEvent(pInfo->dev, > is_absolute(pInfo), > - > 1,0,0,naxes,rx,ry,rz,v3,v4,v5); > + 1,0,0,naxes,valuators); > xf86PostButtonEvent(pInfo->dev, > is_absolute(pInfo), > - 1,1,0,naxes, > rx,ry,rz,v3,v4,v5); > + 1,1,0,naxes,valuators); > xf86PostButtonEvent(pInfo->dev, > is_absolute(pInfo), > - > 1,0,0,naxes,rx,ry,rz,v3,v4,v5); > + 1,0,0,naxes,valuators); > break; > case AC_DISPLAYTOGGLE: > toggleDisplay(pInfo); > @@ -475,7 +471,7 @@ static void sendAButton(InputInfoPtr pInfo, int button, > int mask, > xf86PostButtonEvent(pInfo->dev, > > is_absolute(pInfo), btn_no, > 0, 0, naxes, > - rx, ry, rz, > v3, v4, v5); > + valuators); > } > break; > case AC_KEY: > @@ -578,10 +574,10 @@ static int getWheelButton(InputInfoPtr pInfo, const > WacomDeviceState* ds) > ****************************************************************************/ > > static void sendWheelStripEvents(InputInfoPtr pInfo, const WacomDeviceState* > ds, > - int x, int y, int z, int v3, int v4, int v5) > + int naxes, int *valuators) > { > WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; > - int fakeButton = 0, naxes = priv->naxes; > + int fakeButton = 0; > > DBG(10, priv, "\n"); > > @@ -596,10 +592,10 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, > const WacomDeviceState* ds, > case AC_BUTTON: > /* send both button on/off in the same event for pad */ > xf86PostButtonEvent(pInfo->dev, is_absolute(pInfo), fakeButton > & AC_CODE, > - 1,0,naxes,x,y,z,v3,v4,v5); > + 1,0,naxes,valuators); > > xf86PostButtonEvent(pInfo->dev, is_absolute(pInfo), fakeButton > & AC_CODE, > - 0,0,naxes,x,y,z,v3,v4,v5); > + 0,0,naxes,valuators); > break; > > case AC_KEY: > @@ -617,20 +613,20 @@ static void sendWheelStripEvents(InputInfoPtr pInfo, > const WacomDeviceState* ds, > * Send events common between pad and stylus/cursor/eraser. > ****************************************************************************/ > > -static void sendCommonEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, > int x, int y, int z, int v3, int v4, int v5) > +static void sendCommonEvents(InputInfoPtr pInfo, const WacomDeviceState* ds, > int naxes, int *valuators) > { > WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; > int buttons = ds->buttons; > > /* send button events when state changed or first time in prox and > button unpresses */ > if (priv->oldButtons != buttons || (!priv->oldProximity && !buttons)) > - wcmSendButtons(pInfo,buttons,x,y,z,v3,v4,v5); > + wcmSendButtons(pInfo, buttons, naxes, valuators); > > /* emulate wheel/strip events when defined */ > if ( ds->relwheel || ds->abswheel || > ( (ds->stripx - priv->oldStripX) && ds->stripx && > priv->oldStripX) || > ((ds->stripy - priv->oldStripY) && ds->stripy && > priv->oldStripY) ) > - sendWheelStripEvents(pInfo, ds, x, y, z, v3, v4, v5); > + sendWheelStripEvents(pInfo, ds, naxes, valuators); > } > > /* rotate x and y before post X inout events */ > @@ -705,15 +701,18 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > int id = ds->device_id; > int serial = (int)ds->serial_num; > int is_proximity = ds->proximity; > - int x = ds->x; > - int y = ds->y; > - int z = ds->pressure; > int buttons = ds->buttons; > int tx = ds->tiltx; > int ty = ds->tilty; > WacomDevicePtr priv = (WacomDevicePtr) pInfo->private; > int naxes = priv->naxes; > - int v3, v4, v5; > + int valuators[6]; > + int *x = &valuators[0]; > + int *y = &valuators[1]; > + > + *x = ds->x; > + *y = ds->y; > + valuators[2] = ds->pressure; > > if (priv->serial && serial != priv->serial) > { > @@ -726,8 +725,8 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > /* don't move the cursor when going out-prox */ > if (!ds->proximity) > { > - x = priv->oldX; > - y = priv->oldY; > + *x = priv->oldX; > + *y = priv->oldY; > } > > /* use tx and ty to report stripx and stripy */ > @@ -744,34 +743,34 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > (type == ERASER_ID) ? "eraser" : > (type == TOUCH_ID) ? "touch" : "pad", > priv->oldProximity ? "true" : "false", > - x, y, z, is_button ? "true" : "false", buttons, > + *x, *y, valuators[2], is_button ? "true" : "false", buttons, > tx, ty, ds->abswheel, ds->rotation, ds->throttle); > > if (ds->proximity) > - wcmRotateCoordinates(pInfo, &x, &y); > + wcmRotateCoordinates(pInfo, x, y); > > if (IsCursor(priv)) > { > - v3 = ds->rotation; > - v4 = ds->throttle; > + valuators[3] = ds->rotation; > + valuators[4] = ds->throttle; > } > else /* Intuos styli have tilt */ > { > - v3 = tx; > - v4 = ty; > + valuators[3] = tx; > + valuators[4] = ty; > } > - v5 = ds->abswheel; > + valuators[5] = ds->abswheel; > > DBG(6, priv, "%s prox=%d\tx=%d" > - "\ty=%d\tz=%d\tv3=%d\tv4=%d\tv5=%d\tid=%d" > + "\ty=%d\tz=%d\tv3=%d\tvaluators[4]=%d\tvaluators[5]=%d\tid=%d" > "\tserial=%u\tbutton=%s\tbuttons=%d\n", > is_absolute(pInfo) ? "abs" : "rel", > is_proximity, > - x, y, z, v3, v4, v5, id, serial, > + *x, *y, valuators[2], valuators[3], valuators[4], > valuators[5], id, serial, > is_button ? "true" : "false", buttons); > > - priv->currentX = x; > - priv->currentY = y; > + priv->currentX = *x; > + priv->currentY = *y; > > /* update the old records */ > if(!priv->oldProximity) > @@ -782,19 +781,19 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > > if (!is_absolute(pInfo)) > { > - x -= priv->oldX; > - y -= priv->oldY; > - z -= priv->oldZ; > + *x -= priv->oldX; > + *y -= priv->oldY; > + valuators[2] -= priv->oldZ; > if (IsCursor(priv)) > { > - v3 -= priv->oldRot; > - v4 -= priv->oldThrottle; > + valuators[3] -= priv->oldRot; > + valuators[4] -= priv->oldThrottle; > } else > { > - v3 -= priv->oldTiltX; > - v4 -= priv->oldTiltY; > + valuators[3] -= priv->oldTiltX; > + valuators[4] -= priv->oldTiltY; > } > - v5 -= priv->oldWheel; > + valuators[5] -= priv->oldWheel; > } > > if (type != PAD_ID) > @@ -806,31 +805,30 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > * screen and modify the axes before posting events */ > if(!(priv->flags & BUTTONS_ONLY_FLAG)) > { > - wcmSetScreen(pInfo, x, y); > + wcmSetScreen(pInfo, *x, *y); > } > > /* unify acceleration in both directions > * for relative mode to draw a circle > */ > if (!is_absolute(pInfo)) > - x *= priv->factorY / priv->factorX; > + *x *= priv->factorY / priv->factorX; > else > { > /* Padding virtual values */ > wcmVirtualTabletPadding(pInfo); > - x += priv->leftPadding; > - y += priv->topPadding; > + *x += priv->leftPadding; > + *y += priv->topPadding; > } > > /* don't emit proximity events if device does not > support proximity */ > if ((pInfo->dev->proximity && !priv->oldProximity)) > - xf86PostProximityEvent(pInfo->dev, 1, 0, > naxes, x, y, z, v3, v4, v5); > + xf86PostProximityEventP(pInfo->dev, 1, 0, > naxes, valuators); > > /* Move the cursor to where it should be before > sending button events */ > if(!(priv->flags & BUTTONS_ONLY_FLAG)) > { > - xf86PostMotionEvent(pInfo->dev, > is_absolute(pInfo), > - 0, naxes, x, y, z, v3, v4, v5); > + xf86PostMotionEventP(pInfo->dev, > is_absolute(pInfo), 0, naxes, valuators); > /* For relative events, reset the axes as > * we've already moved the device by the > * relative amount. Otherwise, a button > @@ -839,12 +837,12 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > */ > if (!is_absolute(pInfo)) > { > - x = y = z = 0; > - v3 = v4 = v5 = 0; > + *x = *y = valuators[2] = 0; > + valuators[3] = valuators[4] = > valuators[5] = 0; > } > } > > - sendCommonEvents(pInfo, ds, x, y, z, v3, v4, v5); > + sendCommonEvents(pInfo, ds, naxes, valuators); > } > else /* not in proximity */ > { > @@ -853,46 +851,45 @@ void wcmSendEvents(InputInfoPtr pInfo, const > WacomDeviceState* ds) > /* reports button up when the device has been > * down and becomes out of proximity */ > if (priv->oldButtons) > - wcmSendButtons(pInfo,buttons,x,y,z,v3,v4,v5); > + wcmSendButtons(pInfo,buttons,naxes,valuators); > > if (priv->oldProximity) > - > xf86PostProximityEvent(pInfo->dev,0,0,naxes,x,y,z,v3,v4,v5); > + > xf86PostProximityEventP(pInfo->dev,0,0,naxes,valuators); > } /* not in proximity */ > } > else > { > - if (v3 || v4 || v5 || buttons || ds->relwheel) > + if (valuators[3] || valuators[4] || valuators[5] || buttons > || ds->relwheel) > { > - x = 0; > - y = 0; > - if ( v3 || v4 || v5 ) > - wcmSetScreen(pInfo, x, y); > + *x = 0; > + *y = 0; > + if ( valuators[3] || valuators[4] || valuators[5] ) > + wcmSetScreen(pInfo, *x, *y); > } > > if (!priv->oldProximity && is_proximity) > - xf86PostProximityEvent(pInfo->dev, 1, 0, naxes, x, y, > z, v3, v4, v5); > + xf86PostProximityEventP(pInfo->dev, 1, 0, > naxes,valuators); > > - if (v3 || v4 || v5 || buttons || ds->relwheel) > + if (valuators[3] || valuators[4] || valuators[5] || buttons > || ds->relwheel) > { > - sendCommonEvents(pInfo, ds, x, y, z, v3, v4, v5); > + sendCommonEvents(pInfo, ds, naxes, valuators); > > /* xf86PostMotionEvent is only needed to post the > valuators > * It should NOT move the cursor. > */ > - if ( v3 || v4 || v5 ) > + if ( valuators[3] || valuators[4] || valuators[5] ) > { > - xf86PostMotionEvent(pInfo->dev, > is_absolute(pInfo), > - 0, naxes, x, y, z, v3, v4, v5); > + xf86PostMotionEventP(pInfo->dev, > is_absolute(pInfo), 0, naxes, valuators); > } > } > else > { > if (priv->oldButtons) > - wcmSendButtons(pInfo, buttons, > - x, y, z, v3, v4, v5); > + wcmSendButtons(pInfo, buttons, naxes, > + valuators); > } > if (priv->oldProximity && !is_proximity) > - xf86PostProximityEvent(pInfo->dev, 0, 0, naxes, x, y, > z, v3, v4, v5); > + xf86PostProximityEventP(pInfo->dev, 0, 0, naxes, > valuators); > } > priv->oldProximity = is_proximity; > priv->old_device_id = id; > -- > 1.7.2 > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Linuxwacom-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel > ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ Linuxwacom-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
