On Wed, Dec 21, 2011 at 9:27 PM, Peter Hutterer
wrote:
> On Wed, Dec 21, 2011 at 03:28:54PM -0800, Jason Gerecke wrote:
>> Replaces sendWheelStripEvents and getWheelButton with several
>> small functions to reduce unnecessary code duplication.
>>
>> As a side-effect, it is now possible for the driver to handle
>> simultaneous scrolls on multiple axes. Previously, getWheelButton
>> would go through all the axes but was limited to returning a
>> single button/action.
>>
>> Signed-off-by: Jason Gerecke
>
> Reviewed-by: Peter Hutterer
>
> thank you!
>
> Cheers,
> Peter
>
>> ---
>> Changes from v3:
>> * Move to head of patchset
>> * Add tests for getScrollDelta and getWheelButton
>> * Fix bugs in getScrollDelta doc (wrap is max, not max+1)
>> * Fix bugs in getScrollDelta implementation
>> * log2(0) is undef; caused problems with current or old == 0
>> * wrap now properly handled with AXIS_BITWISE
>>
>> src/wcmCommon.c | 177
>> +--
>> src/xf86WacomDefs.h | 2 +
>> test/wacom-tests.c | 84
>> 3 files changed, 200 insertions(+), 63 deletions(-)
>>
>> diff --git a/src/wcmCommon.c b/src/wcmCommon.c
>> index e85c6d8..e6eb958 100644
>> --- a/src/wcmCommon.c
>> +++ b/src/wcmCommon.c
>> @@ -317,73 +317,106 @@ static void sendAButton(InputInfoPtr pInfo, int
>> button, int mask,
>> first_val, num_val, valuators);
>> }
>>
>> -/*
>> - * getWheelButton --
>> - * Get the wheel button to be sent for the current device state.
>> -
>> /
>> -
>> -static int getWheelButton(InputInfoPtr pInfo, const WacomDeviceState* ds,
>> - unsigned int **fakeKey)
>> +/**
>> + * Get the distance an axis was scrolled. This function is aware
>> + * of the different ways different scrolling axes work and strives
>> + * to produce a common representation of relative change.
>> + *
>> + * @param current Current value of the axis
>> + * @param old Previous value of the axis
>> + * @param wrap Maximum value before wraparound occurs (0 if axis does
>> not wrap)
>> + * @param flags Flags defining axis attributes: AXIS_INVERT and
>> AXIS_BITWISE
>> + * @return Relative change in axis value
>> + */
>> +static int getScrollDelta(int current, int old, int wrap, int flags)
>> {
>> - WacomDevicePtr priv = (WacomDevicePtr) pInfo->private;
>> - int fakeButton = 0, value = 0;
>> + int delta;
>>
>> - /* emulate events for relative wheel */
>> - if ( ds->relwheel )
>> + if (flags & AXIS_BITWISE)
>> {
>> - value = ds->relwheel;
>> - fakeButton = (value > 0) ? priv->relup : priv->reldn;
>> - *fakeKey = (value > 0) ? priv->wheel_keys[0+1] :
>> priv->wheel_keys[1+1];
>> + current = (int)log2((current << 1) | 0x01);
>> + old = (int)log2((old << 1) | 0x01);
>> + wrap = (int)log2((wrap << 1) | 0x01);
>> }
>>
>> - /* emulate events for absolute wheel when it is a touch ring (on pad)
>> */
>> - if ( (ds->abswheel != priv->oldWheel) && IsPad(priv) &&
>> - (priv->oldProximity == ds->proximity))
>> + delta = current - old;
>> +
>> + if (flags & AXIS_INVERT)
>> + delta = -delta;
>> +
>> + if (wrap != 0)
>> {
>> + /* Wraparound detection. If the distance old..current
>> + * is larger than the old..current considering the
>> + * wraparound, assume wraparound and readjust */
>> int wrap_delta;
>> - value = priv->oldWheel - ds->abswheel;
>>
>> - /* Wraparound detection. If the distance oldvalue..value is
>> - * larger than the oldvalue..value considering the
>> - * wraparound, assume wraparound and readjust */
>> - if (value < 0)
>> - wrap_delta = ((MAX_PAD_RING + 1) + priv->oldWheel) -
>> ds->abswheel;
>> + if (delta < 0)
>> + wrap_delta = (wrap + 1) + delta;
>> else
>> - wrap_delta = priv->oldWheel - ((MAX_PAD_RING + 1) +
>> ds->abswheel);
>> + wrap_delta = -((wrap + 1) - delta);
>>
>> - DBG(12, priv, "wrap detection for %d (old %d): %d (wrap %d)\n",
>> - ds->abswheel, priv->oldWheel, value, wrap_delta);
>> + if (abs(wrap_delta) < abs(delta))
>> + delta = wrap_delta;
>> + }
>>
>> - if (abs(wrap_delta) < abs(value))
>> - value = wrap_delta;
>> + return delta;
>> +}
>>
>> - fakeButton = (value > 0) ? priv->wheelup : priv->wheeldn;
>> - *fakeKey = (value > 0) ? priv->wheel_keys[2+1] :
>> priv->wheel_keys[3+1];
>> - }
>> +/**
>> + * Get the scroll button/action to send