On Mon, Jun 25, 2012 at 6:26 PM, Peter Hutterer
<peter.hutte...@who-t.net> wrote:
> On Mon, Jun 25, 2012 at 03:39:58PM -0700, Jason Gerecke wrote:
>> Axes which aren't used by specific devices 'leak' some of the
>> settings of the prior axis while creating the necessary 'filler'
>> axis. This patch introduces an 'initFillerAxis' function that
>> provides a consistent filler axis and restructures calls as
>> necessary.
>>
>> Signed-off-by: Jason Gerecke <killert...@gmail.com>
>> ---
>>  src/xf86Wacom.c | 78 
>> +++++++++++++++++++++++++++++++++++----------------------
>>  1 file changed, 48 insertions(+), 30 deletions(-)
>>
>> diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
>> index 0190678..0f55fe1 100644
>> --- a/src/xf86Wacom.c
>> +++ b/src/xf86Wacom.c
>> @@ -149,6 +149,11 @@ static void wcmInitAxis(DeviceIntPtr dev, int axis, 
>> Atom label, int min, int max
>>       );
>>  }
>>
>> +static void wcmInitFillerAxis(DeviceIntPtr dev, int axis)
>> +{
>> +     wcmInitAxis(dev, axis, None, 0, 1, 1, 1, 1, Absolute);
>> +}
>> +
>
> tbh I think I'd prefer just setting the various min/max to defaults and
> calling a normal axis init. I think that'd make the code much more obivous.
> this goes for 3/3 as well, I find the the current code with the blocked
> min/max/etc assignments much easier to grok.
>
> especially because of:
>    wcmInitAxis(..., min, max, res, min_res, max_res, mode)
> vs:
>    wcmInitAxis(..., priv->topX, priv->bottomX, priv->resolX, 0, priv->resolX, 
> Absolute);
>
> the former documents itself, the latter just means one has to look up what
> the 0 stands for, why resolution is passed in twice, etc.
>
While I also like how the former is more self-documenting, I find the
verbosity of all those min/max/etc. statements to obfuscate what is
ultimately just a single function call. Additionally, repeatedly
defining default values seems error prone; it makes more sense to me
that you'd consolidate it into a single place that hides/handles the
implementation details. That might just be the Java side of me popping
out again though :D

I'd be interested in more viewpoints. Since maintaining this is on all
our shoulders, the last thing I want to do is make the code harder to
understand and work with!

Jason

---
Day xee-nee-svsh duu-'ushtlh-ts'it;
nuu-wee-ya' duu-xan' 'vm-nvshtlh-ts'it.
Huu-chan xuu naa~-gha.

> Cheers,
>  Peter
>
>>  static int
>>  wcmInitAxes(DeviceIntPtr pWcm)
>>  {
>> @@ -194,76 +199,81 @@ wcmInitAxes(DeviceIntPtr pWcm)
>>               label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE);
>>               /* pressure normalized to FILTER_PRESSURE_RES */
>>               max = FILTER_PRESSURE_RES;
>> +             wcmInitAxis(pInfo->dev, 2, label, min, max, res, min_res, 
>> max_res, mode);
>> +
>>       } else {
>>               /* The pad doesn't have a pressure axis, so initialise third
>>                * axis as unknown absolute axis on the pad. This way, we
>>                * can leave the strip/abswheel axes on later axes and don't
>>                * run the danger of clients misinterpreting the axis info
>>                */
>> -             label = None;
>> -             max = 1;
>> +             wcmInitFillerAxis(pInfo->dev, 2);
>>       }
>>
>> -     wcmInitAxis(pInfo->dev, 2, label, min, max, res, min_res, max_res, 
>> mode);
>> -
>>
>>       /* fourth valuator: tilt-x, cursor:z-rotation, pad:strip-x */
>> -     if (IsCursor(priv))
>> +     if (IsPen(priv))
>> +     {
>> +             label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X),
>> +             min = -64;
>> +             max = 63;
>> +             min_res = max_res = res = 1;
>> +             mode = Absolute;
>> +             wcmInitAxis(pInfo->dev, 3, label, min, max, res, min_res, 
>> max_res, mode);
>> +     }
>> +     else if (IsCursor(priv))
>>       {
>>               label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_RZ);
>>               min = MIN_ROTATION;
>>               max = MIN_ROTATION + MAX_ROTATION_RANGE - 1;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> -     } else if (IsPad(priv))
>> +             wcmInitAxis(pInfo->dev, 3, label, min, max, res, min_res, 
>> max_res, mode);
>> +     } else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP))
>>       {
>>               label = None; /* XXX: what is this axis? */
>>               min = 0;
>> -             max = 1; /* dummy value if !HasFeature(WCM_STRIP) */
>> +             max = common->wcmMaxStripX;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> -             if (TabletHasFeature(common, WCM_STRIP))
>> -                     max = common->wcmMaxStripX;
>> +             wcmInitAxis(pInfo->dev, 3, label, min, max, res, min_res, 
>> max_res, mode);
>>       } else
>>       {
>> -                     label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_X),
>> -                     min = -64;
>> -                     max = 63;
>> -                     min_res = max_res = res = 1;
>> -                     mode = Absolute;
>> +             wcmInitFillerAxis(pInfo->dev, 3);
>>       }
>>
>> -     wcmInitAxis(pInfo->dev, 3, label, min, max, res, min_res, max_res, 
>> mode);
>> -
>>
>>       /* fifth valuator: tilt-y, cursor:throttle, pad:strip-y */
>> -     if (IsCursor(priv))
>> +     if (IsPen(priv))
>> +     {
>> +             label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y);
>> +             min = -64;
>> +             max = 63;
>> +             min_res = max_res = res = 1;
>> +             mode = Absolute;
>> +             wcmInitAxis(pInfo->dev, 4, label, min, max, res, min_res, 
>> max_res, mode);
>> +     }
>> +     else if (IsCursor(priv))
>>       {
>>               label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_THROTTLE);
>>               min = -1023;
>>               max = 1023;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> -     } else if (IsPad(priv))
>> +             wcmInitAxis(pInfo->dev, 4, label, min, max, res, min_res, 
>> max_res, mode);
>> +     } else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP))
>>       {
>>               label = None; /* XXX: what is this axis? */
>>               min = 0;
>> -             max = 1; /* dummy value if !HasFeature(WCM_STRIP) */
>> +             max = common->wcmMaxStripY;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> -             if (TabletHasFeature(common, WCM_STRIP))
>> -                     max = common->wcmMaxStripY;
>> +             wcmInitAxis(pInfo->dev, 4, label, min, max, res, min_res, 
>> max_res, mode);
>>       } else
>>       {
>> -             label = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_TILT_Y);
>> -             min = -64;
>> -             max = 63;
>> -             min_res = max_res = res = 1;
>> -             mode = Absolute;
>> +             wcmInitFillerAxis(pInfo->dev, 4);
>>       }
>>
>> -     wcmInitAxis(pInfo->dev, 4, label, min, max, res, min_res, max_res, 
>> mode);
>> -
>>
>>       /* sixth valuator: airbrush: abs-wheel, artpen: rotation, 
>> pad:abs-wheel */
>>       if (IsStylus(priv))
>> @@ -273,6 +283,7 @@ wcmInitAxes(DeviceIntPtr pWcm)
>>               min = MIN_ROTATION;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> +             wcmInitAxis(pInfo->dev, 5, label, min, max, res, min_res, 
>> max_res, mode);
>>       } else if ((TabletHasFeature(common, WCM_RING)) && IsPad(priv))
>>       {
>>               /* Touch ring */
>> @@ -281,9 +292,12 @@ wcmInitAxes(DeviceIntPtr pWcm)
>>               max = MAX_PAD_RING;
>>               min_res = max_res = res = 1;
>>               mode = Absolute;
>> +             wcmInitAxis(pInfo->dev, 5, label, min, max, res, min_res, 
>> max_res, mode);
>> +     }
>> +     else
>> +     {
>> +             wcmInitFillerAxis(pInfo->dev, 5);
>>       }
>> -
>> -     wcmInitAxis(pInfo->dev, 5, label, min, max, res, min_res, max_res, 
>> mode);
>>
>>
>>       /* seventh valuator: abswheel2 */
>> @@ -298,6 +312,10 @@ wcmInitAxes(DeviceIntPtr pWcm)
>>
>>               wcmInitAxis(pInfo->dev, 6, label, min, max, res, min_res, 
>> max_res, mode);
>>       }
>> +     else
>> +     {
>> +             wcmInitFillerAxis(pInfo->dev, 6);
>> +     }
>>
>>       return TRUE;
>>  }
>> --
>> 1.7.11

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to