[PATCH xf86-input-synaptics 07/10] Add touch valuator mask to hw state structure

Peter Hutterer peter.hutterer at who-t.net
Thu Feb 9 06:27:15 PST 2012


On Wed, Feb 08, 2012 at 06:35:16PM -0800, Chase Douglas wrote:
> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>  src/synaptics.c    |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  src/synapticsstr.h |    1 +
>  src/synproto.h     |    5 +++
>  3 files changed, 82 insertions(+), 2 deletions(-)
> 
> diff --git a/src/synaptics.c b/src/synaptics.c
> index c0398fb..b01be59 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -1151,6 +1151,8 @@ DeviceInit(DeviceIntPtr dev)
>  #ifdef HAVE_MULTITOUCH
>      if (priv->has_touch)
>      {
> +        priv->num_slots = priv->max_touches ? : 10;

whoah, didn't know that was legal. is this gcc or std C?
either way, I'd rather not do that because of this behaviour:

    int a = 12;
    a = (a > 10) ? : 10;
    → a is now 1
    
Not quite what one would expect.

> +
>          /* x/y + whatever other MT axes we found */
>          if (!InitTouchClassDeviceStruct(dev, priv->max_touches,
>                                          XIDependentTouch, 2 + priv->num_mt_axes))
> @@ -1158,6 +1160,7 @@ DeviceInit(DeviceIntPtr dev)
>              xf86IDrvMsg(pInfo, X_ERROR,
>                          "failed to initialize touch class device\n");
>              priv->has_touch = 0;
> +            priv->num_slots = 0;
>              goto no_touch;
>          }
>  
> @@ -2836,12 +2839,64 @@ CalculateScalingCoeffs(SynapticsPrivate *priv)
>  struct SynapticsHwState *
>  SynapticsHwStateAlloc(SynapticsPrivate *priv)
>  {
> -    return calloc(1, sizeof(struct SynapticsHwState));
> +    struct SynapticsHwState *hw;
> +#ifdef HAVE_MULTITOUCH
> +    int num_vals;
> +    int i = 0;
> +#endif

> +
> +    hw = calloc(1, sizeof(struct SynapticsHwState));
> +    if (!hw)
> +        goto fail;
> +
> +#ifndef HAVE_MULTITOUCH
> +    return hw;
> +
> +fail:
> +#else
> +    hw->num_mt_mask = priv->num_slots;
> +    hw->mt_mask = malloc(hw->num_mt_mask * sizeof(ValuatorMask *));
> +    if (!hw->mt_mask)
> +        goto fail;
> +
> +    num_vals = 2; /* x and y */
> +    num_vals += 2; /* scroll axes */
> +    num_vals += priv->num_mt_axes;
> +
> +    for (; i < hw->num_mt_mask; i++)
> +    {
> +        hw->mt_mask[i] = valuator_mask_new(num_vals);
> +        if (!hw->mt_mask[i])
> +            break;
> +    }
> +
> +    if (i < hw->num_mt_mask)
> +        goto fail;
> +
> +    return hw;
> +
> +fail:
> +    for (i--; i >= 0; i--)
> +        valuator_mask_free(&hw->mt_mask[i]);
> +    if (hw)
> +        free(hw->mt_mask);
> +    free(hw);
> +#endif

split this else block into a separate function please

Cheers,
  Peter

> +
> +    return NULL;
>  }
>  
>  void
>  SynapticsHwStateFree(struct SynapticsHwState *hw)
>  {
> +#ifdef HAVE_MULTITOUCH
> +    int i;
> +
> +    for (i = 0; i < hw->num_mt_mask; i++)
> +        valuator_mask_free(&hw->mt_mask[i]);
> +    free(hw->mt_mask);
> +#endif
> +
>      free(hw);
>  }
>  
> @@ -2849,5 +2904,24 @@ void
>  SynapticsCopyHwState(struct SynapticsHwState *dst,
>                       const struct SynapticsHwState *src)
>  {
> -    *dst = *src;
> +#ifdef HAVE_MULTITOUCH
> +    int i;
> +#endif
> +
> +    dst->millis = src->millis;
> +    dst->x = src->x;
> +    dst->y = src->y;
> +    dst->z = src->z;
> +    dst->numFingers = src->numFingers;
> +    dst->fingerWidth = src->fingerWidth;
> +    dst->left = src->left;
> +    dst->right = src->right;
> +    dst->up = src->up;
> +    dst->down = src->down;
> +    memcpy(dst->multi, src->multi, sizeof(dst->multi));
> +    dst->middle = src->middle;
> +#ifdef HAVE_MULTITOUCH
> +    for (i = 0; i < dst->num_mt_mask && i < src->num_mt_mask; i++)
> +        valuator_mask_copy(dst->mt_mask[i], src->mt_mask[i]);
> +#endif
>  }
> diff --git a/src/synapticsstr.h b/src/synapticsstr.h
> index a903269..1c8342c 100644
> --- a/src/synapticsstr.h
> +++ b/src/synapticsstr.h
> @@ -281,6 +281,7 @@ typedef struct _SynapticsPrivateRec
>      int max_touches;                    /* Number of touches supported */
>      int num_mt_axes;                    /* Number of multitouch axes other than X, Y */
>      SynapticsTouchAxisRec *touch_axes;  /* Touch axis information other than X, Y */
> +    int num_slots;                      /* Number of touch slots allocated */
>  #endif
>  } SynapticsPrivate;
>  
> diff --git a/src/synproto.h b/src/synproto.h
> index b2afda6..02bc732 100644
> --- a/src/synproto.h
> +++ b/src/synproto.h
> @@ -53,6 +53,11 @@ struct SynapticsHwState {
>  
>      Bool multi[8];
>      Bool middle;		/* Some ALPS touchpads have a middle button */
> +
> +#ifdef HAVE_MULTITOUCH
> +    int num_mt_mask;
> +    ValuatorMask **mt_mask;
> +#endif
>  };
>  
>  struct CommData {
> -- 
> 1.7.8.3
> 


More information about the xorg-devel mailing list