[xf86-input-synaptics v3 09/14] Add touch valuator mask to hw state structure

Chase Douglas chase.douglas at canonical.com
Fri Feb 10 11:56:53 PST 2012


Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 src/eventcomm.c    |    8 +----
 src/synaptics.c    |    3 ++
 src/synapticsstr.h |    1 +
 src/synproto.c     |   91 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/synproto.h     |   16 +++++++++
 5 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/src/eventcomm.c b/src/eventcomm.c
index 7253bba..9197d5d 100644
--- a/src/eventcomm.c
+++ b/src/eventcomm.c
@@ -69,13 +69,7 @@ struct eventcomm_proto_data
     struct mtdev *mtdev;
     int axis_map[MT_ABS_SIZE];
     int cur_slot;
-    enum
-    {
-        SLOTSTATE_OPEN = 0,
-        SLOTSTATE_CLOSE,
-        SLOTSTATE_UPDATE,
-        SLOTSTATE_EMPTY,
-    } slot_state;
+    enum SynapticsSlotState slot_state;
     ValuatorMask *mt_mask;
     ValuatorMask **last_mt_vals;
     unsigned int num_touches;
diff --git a/src/synaptics.c b/src/synaptics.c
index 337a3aa..a6b1b18 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;
         }
 
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.c b/src/synproto.c
index 9f042b5..49d333d 100644
--- a/src/synproto.c
+++ b/src/synproto.c
@@ -28,16 +28,82 @@
 
 
 #include "synproto.h"
+#include "synaptics.h"
+#include "synapticsstr.h"
+
+#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;
+    }
+
+    hw->slot_state = calloc(hw->num_mt_mask, sizeof(enum SynapticsSlotState));
+    if (!hw->slot_state)
+        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;
+
+    if (!*hw)
+        return;
+
+    free((*hw)->slot_state);
+    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;
 }
@@ -46,5 +112,26 @@ 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]);
+    memcpy(dst->slot_state, src->slot_state,
+           dst->num_mt_mask * sizeof(enum SynapticsSlotState));
+#endif
 }
diff --git a/src/synproto.h b/src/synproto.h
index 8d50ce6..7ebca59 100644
--- a/src/synproto.h
+++ b/src/synproto.h
@@ -32,9 +32,19 @@
 #include <xf86Xinput.h>
 #include <xisb.h>
 
+#include "config.h"
+
 struct _SynapticsPrivateRec;
 typedef struct _SynapticsPrivateRec SynapticsPrivate;
 
+enum SynapticsSlotState
+{
+    SLOTSTATE_EMPTY = 0,
+    SLOTSTATE_OPEN,
+    SLOTSTATE_CLOSE,
+    SLOTSTATE_UPDATE,
+};
+
 /*
  * A structure to describe the state of the touchpad hardware (buttons and pad)
  */
@@ -53,6 +63,12 @@ struct SynapticsHwState {
 
     Bool multi[8];
     Bool middle;		/* Some ALPS touchpads have a middle button */
+
+#ifdef HAVE_MULTITOUCH
+    int num_mt_mask;
+    ValuatorMask **mt_mask;
+    enum SynapticsSlotState *slot_state;
+#endif
 };
 
 struct CommData {
-- 
1.7.8.3



More information about the xorg-devel mailing list