On Fri, Oct 21, 2011 at 06:37:25PM -0700, Jason Gerecke wrote:
> Touch strips as well as the first touch ring are set up to emulate
> mouse wheel events by default. This patch duplicates this behavior
> for the second touch ring, so that it behaves in an identical manner.
> 
> Signed-off-by: Jason Gerecke <killert...@gmail.com>
> ---
>  src/wcmCommon.c         |   29 +++++++++++++++++++++++++++--
>  src/wcmConfig.c         |    2 ++
>  src/wcmValidateDevice.c |    4 ++--
>  src/wcmXCommand.c       |   18 ++++++++++++++----
>  src/xf86WacomDefs.h     |    8 +++++---
>  tools/xsetwacom.c       |   20 ++++++++++++++++++++
>  6 files changed, 70 insertions(+), 11 deletions(-)
> 
> diff --git a/src/wcmCommon.c b/src/wcmCommon.c
> index f6ddf8a..a6c55b9 100644
> --- a/src/wcmCommon.c
> +++ b/src/wcmCommon.c
> @@ -363,6 +363,31 @@ static int getWheelButton(InputInfoPtr pInfo, const 
> WacomDeviceState* ds,
>               *fakeKey = (value > 0) ? priv->wheel_keys[2+1] : 
> priv->wheel_keys[3+1];
>       }
>  
> +     /* emulate events for 2nd absolute wheel when it is a touch ring (on 
> pad) */
> +     if ( (ds->abswheel2 != priv->oldWheel2) && IsPad(priv) &&
> +         (priv->oldProximity == ds->proximity))
> +     {
> +             int wrap_delta;
> +             value = priv->oldWheel2 - ds->abswheel2;
> +
> +             /* 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->oldWheel2) - 
> ds->abswheel2;
> +             else
> +                     wrap_delta = priv->oldWheel2 - ((MAX_PAD_RING + 1) + 
> ds->abswheel2);
> +
> +             DBG(12, priv, "wrap detection for %d (old %d): %d (wrap %d)\n",
> +                 ds->abswheel2, priv->oldWheel2, value, wrap_delta);
> +
> +             if (abs(wrap_delta) < abs(value))
> +                     value = wrap_delta;
> +
> +             fakeButton = (value > 0) ? priv->wheel2up : priv->wheel2dn;
> +             *fakeKey = (value > 0) ? priv->wheel_keys[4+1] : 
> priv->wheel_keys[5+1];
> +     }
> +

this needs to be in a function that's called with the different
abswheel/oldWheel structs as parameters. Copying code is evil.


>       /* emulate events for left strip */
>       if ( ds->stripx != priv->oldStripX )
>       {
> @@ -439,7 +464,7 @@ static void sendCommonEvents(InputInfoPtr pInfo, const 
> WacomDeviceState* ds,
>               wcmSendButtons(pInfo,buttons, first_val, num_vals, valuators);
>  
>       /* emulate wheel/strip events when defined */
> -     if ( ds->relwheel || (ds->abswheel != priv->oldWheel) ||
> +     if ( ds->relwheel || (ds->abswheel != priv->oldWheel) || (ds->abswheel2 
> != priv->oldWheel2) ||
>               ( (ds->stripx - priv->oldStripX) && ds->stripx && 
> priv->oldStripX) || 
>                       ((ds->stripy - priv->oldStripY) && ds->stripy && 
> priv->oldStripY) )
>               sendWheelStripEvents(pInfo, ds, first_val, num_vals, valuators);
> @@ -540,7 +565,7 @@ wcmSendPadEvents(InputInfoPtr pInfo, const 
> WacomDeviceState* ds,
>               if (valuators[i])
>                       break;
>       if (i < num_vals || ds->buttons || ds->relwheel ||
> -         (ds->abswheel != priv->oldWheel))
> +         (ds->abswheel != priv->oldWheel) || (ds->abswheel2 != 
> priv->oldWheel2))
>       {
>               sendCommonEvents(pInfo, ds, first_val, num_vals, valuators);
>  
> diff --git a/src/wcmConfig.c b/src/wcmConfig.c
> index 94b188d..567c3e7 100644
> --- a/src/wcmConfig.c
> +++ b/src/wcmConfig.c
> @@ -80,6 +80,8 @@ static int wcmAllocate(InputInfoPtr pInfo)
>        * later in wcmParseOptions, when we have IsPad() available */
>       priv->wheelup = 0;                      /* Default absolute wheel up 
> event */
>       priv->wheeldn = 0;                      /* Default absolute wheel down 
> event */
> +     priv->wheel2up = 0;                     /* Default absolute wheel2 up 
> event */
> +     priv->wheel2dn = 0;                     /* Default absolute wheel2 down 
> event */
>       priv->striplup = 4;                     /* Default left strip up event 
> */
>       priv->stripldn = 5;                     /* Default left strip down 
> event */
>       priv->striprup = 4;                     /* Default right strip up event 
> */
> diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c
> index 34cae91..bde010c 100644
> --- a/src/wcmValidateDevice.c
> +++ b/src/wcmValidateDevice.c
> @@ -713,8 +713,8 @@ Bool wcmParseOptions(InputInfoPtr pInfo, Bool is_primary, 
> Bool is_dependent)
>        */
>       if (IsPad(priv))
>       {
> -             priv->wheelup = 4;
> -             priv->wheeldn = 5;
> +             priv->wheelup = priv->wheel2up = 4;
> +             priv->wheeldn = priv->wheel2dn = 5;
>               set_absolute(pInfo, TRUE);
>       }
>  
> diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c
> index 82f9b80..f5c90e4 100644
> --- a/src/wcmXCommand.c
> +++ b/src/wcmXCommand.c
> @@ -237,7 +237,7 @@ void InitWcmDeviceProperties(InputInfoPtr pInfo)
>       if (IsPad(priv) || IsCursor(priv))
>       {
>               memset(values, 0, sizeof(values));
> -             prop_wheel_buttons = InitWcmAtom(pInfo->dev, 
> WACOM_PROP_WHEELBUTTONS, XA_ATOM, 32, 4, values);
> +             prop_wheel_buttons = InitWcmAtom(pInfo->dev, 
> WACOM_PROP_WHEELBUTTONS, XA_ATOM, 32, 6, values);
>       }
>  
>       values[0] = common->vendor_id;
> @@ -456,6 +456,8 @@ struct wheel_strip_update_t {
>       int *dn1;
>       int *up2;
>       int *dn2;
> +     int *up3;
> +     int *dn3;
>  
>       /* for CARD32 values, points to atom array of atoms to be
>        * monitored.*/
> @@ -477,7 +479,7 @@ static int wcmSetWheelOrStripProperty(DeviceIntPtr dev, 
> Atom property,
>               CARD32 *v32;
>       } values;
>  
> -     if (prop->size != 4)
> +     if (prop->size != 6)
>               return BadValue;
>  
>       /* see wcmSetPropertyButtonActions for how this works. The wheel is
> @@ -492,7 +494,9 @@ static int wcmSetWheelOrStripProperty(DeviceIntPtr dev, 
> Atom property,
>                       if (values.v8[0] > WCM_MAX_MOUSE_BUTTONS ||
>                           values.v8[1] > WCM_MAX_MOUSE_BUTTONS ||
>                           values.v8[2] > WCM_MAX_MOUSE_BUTTONS ||
> -                         values.v8[3] > WCM_MAX_MOUSE_BUTTONS)
> +                         values.v8[3] > WCM_MAX_MOUSE_BUTTONS ||
> +                         values.v8[4] > WCM_MAX_MOUSE_BUTTONS ||
> +                         values.v8[5] > WCM_MAX_MOUSE_BUTTONS)
>                               return BadValue;
>  
>                       if (!checkonly) {
> @@ -500,6 +504,8 @@ static int wcmSetWheelOrStripProperty(DeviceIntPtr dev, 
> Atom property,
>                               *wsup->dn1 = values.v8[1];
>                               *wsup->up2 = values.v8[2];
>                               *wsup->dn2 = values.v8[3];
> +                             *wsup->up3 = values.v8[4];
> +                             *wsup->dn3 = values.v8[5];
>                       }
>                       break;
>               case 32:
> @@ -534,10 +540,12 @@ static int wcmSetWheelProperty(DeviceIntPtr dev, Atom 
> property,
>               .dn1 = &priv->reldn,
>               .up2 = &priv->wheelup,
>               .dn2 = &priv->wheeldn,
> +             .up3 = &priv->wheel2up,
> +             .dn3 = &priv->wheel2dn,
>  
>               .handlers = priv->wheel_actions,
>               .keys     = priv->wheel_keys,
> -             .skeys    = 4,
> +             .skeys    = 6,
>       };
>  
>       return wcmSetWheelOrStripProperty(dev, property, prop, checkonly, 
> &wsup);
> @@ -554,6 +562,8 @@ static int wcmSetStripProperty(DeviceIntPtr dev, Atom 
> property,
>               .dn1 = &priv->stripldn,
>               .up2 = &priv->striprup,
>               .dn2 = &priv->striprdn,
> +             .up3 = NULL,
> +             .dn3 = NULL,
>  
>               .handlers = priv->strip_actions,
>               .keys     = priv->strip_keys,
> diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
> index 72c2bd5..c370baa 100644
> --- a/src/xf86WacomDefs.h
> +++ b/src/xf86WacomDefs.h
> @@ -236,10 +236,12 @@ struct _WacomDeviceRec
>       int reldn;
>       int wheelup;
>       int wheeldn;
> +     int wheel2up;
> +     int wheel2dn;
>       /* keystrokes assigned to wheel events (default is the buttons above).
> -      * Order is relup, reldwn, wheelup, wheeldn. Like 'keys', this array
> -      * is one-indexed */
> -     unsigned wheel_keys[4+1][256];
> +      * Order is relup, reldwn, wheelup, wheeldn, wheel2up, wheel2dn.
> +      * Like 'keys', this array is one-indexed */
> +     unsigned wheel_keys[6+1][256];
>  
>       int striplup;
>       int stripldn;
> diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
> index 99ca974..b8b3437 100644
> --- a/tools/xsetwacom.c
> +++ b/tools/xsetwacom.c
> @@ -301,6 +301,26 @@ static param_t parameters[] =
>               .get_func = get_map,
>       },
>       {
> +             .name = "AbsWheel2Up",
> +             .desc = "X11 event to which absolute wheel up should be mapped. 
> ",
> +             .prop_name = WACOM_PROP_WHEELBUTTONS,
> +             .prop_format = 8,
> +             .prop_offset = 4,
> +             .arg_count = 0,
> +             .set_func = map_actions,
> +             .get_func = get_map,
> +     },
> +     {
> +             .name = "AbsWheel2Down",
> +             .desc = "X11 event to which absolute wheel down should be 
> mapped. ",
> +             .prop_name = WACOM_PROP_WHEELBUTTONS,
> +             .prop_format = 8,
> +             .prop_offset = 5,
> +             .arg_count = 0,
> +             .set_func = map_actions,
> +             .get_func = get_map,
> +     },

come to think of it, we should really rename that to cw/ccw or so. Up down
on a wheel is rather ambiguous. For the scope of this patch you can leave it
though.

Cheers,
  Peter
> +     {
>               .name = "StripLeftUp",
>               .desc = "X11 event to which left strip up should be mapped. ",
>               .prop_name = WACOM_PROP_STRIPBUTTONS,
> -- 
> 1.7.6


------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to