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

Chase Douglas chase.douglas at canonical.com
Thu Feb 9 18:24:51 PST 2012


Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/synaptics.c    |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/synapticsstr.h |    1 +
 src/synproto.h     |    5 +++
 3 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/src/synaptics.c b/src/synaptics.c
index 8adaff4..3931081 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -1148,6 +1148,8 @@ DeviceInit(DeviceIntPtr dev)
 #ifdef HAVE_MULTITOUCH
     if (priv->has_touch)
     {
+        priv->num_slots = priv->max_touches ? priv->max_touches : 10;
+
         /* x/y + whatever other MT axes we found */
         if (!InitTouchClassDeviceStruct(dev, priv->max_touches,
                                         XIDependentTouch, 2 + priv->num_mt_axes))
@@ -1155,6 +1157,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;
         }
 
@@ -2830,15 +2833,71 @@ CalculateScalingCoeffs(SynapticsPrivate *priv)
     }
 }
 
+#ifdef HAVE_MULTITOUCH
+static int
+HwStateAllocTouch(struct SynapticsHwState *hw, SynapticsPrivate *priv)
+{
+    int num_vals;
+    int i = 0;
+
+    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])
+            goto fail;
+    }
+
+    return Success;
+
+fail:
+    for (i--; i >= 0; i--)
+        valuator_mask_free(&hw->mt_mask[i]);
+    free(hw->mt_mask);
+    hw->mt_mask = NULL;
+    return BadAlloc;
+}
+#endif
+
 struct SynapticsHwState *
 SynapticsHwStateAlloc(SynapticsPrivate *priv)
 {
-    return calloc(1, sizeof(struct SynapticsHwState));
+    struct SynapticsHwState *hw;
+
+    hw = calloc(1, sizeof(struct SynapticsHwState));
+    if (!hw)
+        return NULL;
+
+#ifdef HAVE_MULTITOUCH
+    if (HwStateAllocTouch(hw, priv) != Success)
+    {
+        free(hw);
+        return NULL;
+    }
+#endif
+
+    return hw;
 }
 
 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);
     *hw = NULL;
 }
@@ -2847,5 +2906,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 8d50ce6..158c90d 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