[PATCH xf86-input-synaptics 2/6] Add touch device class support

Chase Douglas chase.douglas at canonical.com
Thu Jan 19 13:05:47 PST 2012


Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 configure.ac       |    5 ++++
 src/synaptics.c    |   65 ++++++++++++++++++++++++++++++++++++++++++++++++----
 src/synapticsstr.h |   15 ++++++++++++
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index bb95403..f8c7259 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,11 @@ AC_SUBST([sdkdir])
 DRIVER_NAME=synaptics
 AC_SUBST([DRIVER_NAME])
 
+PKG_CHECK_MODULES(XI22, [inputproto >= 2.1.99.3] [xorg-server >= 1.11.99.901], HAVE_XI22="yes", HAVE_XI22="no")
+if test "x$HAVE_XI22" = xyes; then
+    AC_DEFINE(HAVE_MULTITOUCH, 1, [XI2.2 available])
+fi
+
 # -----------------------------------------------------------------------------
 #			Configuration options
 # -----------------------------------------------------------------------------
diff --git a/src/synaptics.c b/src/synaptics.c
index 1c68358..1d963cb 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -937,8 +937,13 @@ DeviceClose(DeviceIntPtr dev)
     return RetValue;
 }
 
-static void InitAxesLabels(Atom *labels, int nlabels)
+static void InitAxesLabels(Atom *labels, int nlabels,
+                           const SynapticsPrivate *priv)
 {
+#ifdef HAVE_MULTITOUCH
+    int i;
+#endif
+
     memset(labels, 0, nlabels * sizeof(Atom));
     switch(nlabels)
     {
@@ -955,6 +960,15 @@ static void InitAxesLabels(Atom *labels, int nlabels)
             labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
             break;
     }
+
+#ifdef HAVE_MULTITOUCH
+    for (i = 0; i < priv->num_mt_axes; i++)
+    {
+        SynapticsTouchAxisRec *axis = &priv->touch_axes[i];
+        int axnum = nlabels - priv->num_mt_axes + i;
+        labels[axnum] = XIGetKnownProperty(axis->label);
+    }
+#endif
 }
 
 static void InitButtonLabels(Atom *labels, int nlabels)
@@ -1000,6 +1014,10 @@ DeviceInit(DeviceIntPtr dev)
     num_axes += 2;
 #endif
 
+#ifdef HAVE_MULTITOUCH
+    num_axes += priv->num_mt_axes;
+#endif
+
     axes_labels = calloc(num_axes, sizeof(Atom));
     if (!axes_labels)
     {
@@ -1007,7 +1025,7 @@ DeviceInit(DeviceIntPtr dev)
         return !Success;
     }
 
-    InitAxesLabels(axes_labels, num_axes);
+    InitAxesLabels(axes_labels, num_axes, priv);
     InitButtonLabels(btn_labels, SYN_MAX_BUTTONS);
 
     DBG(3, "Synaptics DeviceInit called\n");
@@ -1111,12 +1129,12 @@ DeviceInit(DeviceIntPtr dev)
     xf86InitValuatorAxisStruct(dev, 3, axes_labels[3], 0, -1, 0, 0, 0,
                                Relative);
     priv->scroll_axis_vert = 3;
-
-    free(axes_labels);
-
     priv->scroll_events_mask = valuator_mask_new(MAX_VALUATORS);
     if (!priv->scroll_events_mask)
+    {
+        free(axes_labels);
         return !Success;
+    }
 
     SetScrollValuator(dev, priv->scroll_axis_horiz, SCROLL_TYPE_HORIZONTAL,
                       priv->synpara.scroll_dist_horiz, 0);
@@ -1124,6 +1142,43 @@ DeviceInit(DeviceIntPtr dev)
                       priv->synpara.scroll_dist_vert, 0);
 #endif
 
+#ifdef HAVE_MULTITOUCH
+    if (priv->has_touch)
+    {
+        if (!InitTouchClassDeviceStruct(dev, priv->num_touches,
+                                        XIDependentTouch, priv->num_mt_axes))
+        {
+            xf86IDrvMsg(pInfo, X_ERROR,
+                        "failed to initialize touch class device\n");
+            priv->has_touch = 0;
+            goto no_touch;
+        }
+
+        for (i = 0; i < priv->num_mt_axes; i++)
+        {
+            SynapticsTouchAxisRec *axis = &priv->touch_axes[i];
+            int axnum = num_axes - priv->num_mt_axes + i;
+            Atom atom = axes_labels[axnum];
+
+            if (!xf86InitValuatorAxisStruct(dev, axnum, axes_labels[axnum],
+                                            axis->min, axis->max, axis->res, 0,
+                                            axis->res, Absolute))
+            {
+                xf86IDrvMsg(pInfo, X_WARNING,
+                            "failed to initialize axis %s, skipping\n",
+                            axis->label);
+                continue;
+            }
+
+            xf86InitValuatorDefaults(dev, axnum);
+        }
+    }
+
+no_touch:
+#endif
+
+    free(axes_labels);
+
     if (!alloc_shm_data(pInfo))
 	return !Success;
 
diff --git a/src/synapticsstr.h b/src/synapticsstr.h
index d74ebcd..d3b8607 100644
--- a/src/synapticsstr.h
+++ b/src/synapticsstr.h
@@ -56,6 +56,14 @@ typedef struct _SynapticsMoveHist
     CARD32 millis;
 } SynapticsMoveHistRec;
 
+typedef struct _SynapticsTouchAxis
+{
+    const char *label;
+    int min;
+    int max;
+    int res;
+} SynapticsTouchAxisRec;
+
 enum FingerState {              /* Note! The order matters. Compared with < operator. */
     FS_BLOCKED = -1,
     FS_UNTOUCHED = 0, /* this is 0 so it's the initialized value. */
@@ -265,6 +273,13 @@ typedef struct _SynapticsPrivateRec
     int scroll_axis_vert;               /* Vertical smooth-scrolling axis */
     ValuatorMask *scroll_events_mask;   /* ValuatorMask for smooth-scrolling */
 #endif
+
+#ifdef HAVE_MULTITOUCH
+    Bool has_touch;                     /* Device has multitouch capabilities */
+    int num_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 */
+#endif
 } SynapticsPrivate;
 
 #endif /* _SYNAPTICSSTR_H_ */
-- 
1.7.8.3



More information about the xorg-devel mailing list