With the introduction of multi-touch, the chances of getting touch
events while pen is in prox have been increased. One obvious use
case is that the touch events could be used for gestures while pen
is in prox. However, we do not want two cursors compete on the screen.

Link the pen and touch device once during the initialization stage
instead of every time when we receive a pen event. Then, centralize
pen and touch arbitration process so we can store the touch data in
wcmUSB.c instead of discarding them. The touch events will only be
ignored if it is a single touch event that causes a cursor movement
while pen is in prox.

Some cleanup in wcmUSB.c is needed. It will be considered when we
make MAX_CHANNEL a dynamic value based on MAX_FINGERS. The
MAX_FINGERS is going to be the maximum of ABS_MT_SLOT that we
retrieve from the kernel. That brings us to the state to support
XInput 2.1 and devices that have dynamic number of fingers.

Note: this patch is based on the assumption that all devices
connected to the same system have unique product IDs. That is,
no two or more identical devices are connected. Identical devices
will be properly linked when we find a decent way to distinguish
them in the driver.

Signed-off-by: Ping Cheng <pingli...@gmail.com>
---
Changes in v2: unlink touch and pen when at least one of them
is disabled; fixed an if-statement in ignoring touch when pen is
in prox; and a few coding style suggestions made by Peter.

 src/wcmCommon.c     |   32 +++++++++++++-------------------
 src/wcmConfig.c     |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xf86Wacom.c     |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/xf86WacomDefs.h |    4 ++++
 4 files changed, 111 insertions(+), 19 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index a370389..fff5a08 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1138,30 +1138,23 @@ static void commonDispatchDevice(WacomCommonPtr common, 
unsigned int channel,
                return;
        }
 
-       /* send a touch out for USB Tablet PCs */
-       if (IsUSBDevice(common) && !IsTouch(priv)
-                       && common->wcmTouchDefault && !priv->oldProximity)
+       if (TabletHasFeature(common, WCM_PENTOUCH))
        {
-               InputInfoPtr device = xf86FirstLocalDevice();
-               WacomCommonPtr tempcommon = NULL;
-               WacomDevicePtr temppriv = NULL;
-
-               /* Lookup to see if associated touch was enabled */
-               for (; device != NULL; device = device->next)
+               if (IsPen(priv))
                {
-                       if (strstr(device->drv->driverName, "wacom"))
+                       /* send touch out when pen coming in-prox for devices
+                        * that provideboth pen and touch events so system
+                        * cursor won't jump between tools.
+                        */
+                       if (common->wcmTouchDevice->oldProximity)
                        {
-                               temppriv = (WacomDevicePtr) device->private;
-                               tempcommon = temppriv->common;
-
-                               if ((tempcommon->tablet_id == 
common->tablet_id) &&
-                                               IsTouch(temppriv) && 
temppriv->oldProximity)
-                               {
-                                       /* Send soft prox-out for touch first */
-                                       wcmSoftOutEvent(device);
-                               }
+                               wcmSoftOutEvent(common->wcmTouchDevice->pInfo);
+                               return;
                        }
                }
+               else if (IsTouch(priv) && common->wcmPenInProx)
+                       /* Ignore touch events when pen is in prox */
+                       return;
        }
 
        if (IsPen(priv))
@@ -1170,6 +1163,7 @@ static void commonDispatchDevice(WacomCommonPtr common, 
unsigned int channel,
                filtered.pressure = normalizePressure(priv, &filtered);
                filtered.buttons = setPressureButton(priv, &filtered);
                filtered.pressure = applyPressureCurve(priv,&filtered);
+               common->wcmPenInProx = filtered.proximity;
        }
 
        else if (IsCursor(priv) && !priv->oldCursorHwProx)
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index 6235d3c..f989fb0 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -397,6 +397,51 @@ wcmInitModel(InputInfoPtr pInfo)
        return TRUE;
 }
 
+/**
+ * Link the touch tool to the pen of the same device
+ * so we can arbitrate the events when posting them.
+ */
+static void wcmLinkTouchAndPen(InputInfoPtr pInfo)
+{
+       WacomDevicePtr priv = pInfo->private;
+       WacomCommonPtr common = priv->common;
+       InputInfoPtr device = xf86FirstLocalDevice();
+       WacomCommonPtr tmpcommon = NULL;
+       WacomDevicePtr tmppriv = NULL;
+       Bool touch_device_assigned = FALSE;
+
+       /* Lookup to find the associated pen and touch */
+       for (; device != NULL; device = device->next)
+       {
+               if (!strcmp(device->drv->driverName, "wacom"))
+               {
+                       tmppriv = (WacomDevicePtr) device->private;
+                       tmpcommon = tmppriv->common;
+                       touch_device_assigned = (common->wcmTouchDevice ||
+                                               tmpcommon->wcmTouchDevice);
+
+                       /* skip the same tool or already linked devices */
+                       if ((tmppriv == priv) || touch_device_assigned)
+                               continue;
+
+                       if (tmpcommon->tablet_id == common->tablet_id)
+                       {
+                               if (IsTouch(tmppriv) && IsPen(priv))
+                                       common->wcmTouchDevice = tmppriv;
+                               else if (IsTouch(priv) && IsPen(tmppriv))
+                                       tmpcommon->wcmTouchDevice = priv;
+
+                               if (common->wcmTouchDevice ||
+                                               tmpcommon->wcmTouchDevice)
+                               {
+                                       common->tablet_type |= WCM_PENTOUCH;
+                                       tmpcommon->tablet_type |= WCM_PENTOUCH;
+                               }
+                       }
+               }
+       }
+}
+
 /* wcmPreInit - called for each input devices with the driver set to
  * "wacom" */
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
@@ -518,6 +563,12 @@ static int wcmPreInit(InputDriverPtr drv, InputInfoPtr 
pInfo, int flags)
                pInfo->fd = -1;
        }
 
+       /* only link them once per port. We need to try for both pen and touch
+        * since we do not know which tool (touch or pen) will be added first.
+        */
+       if (IsTouch(priv) || (IsPen(priv) && !common->wcmTouchDevice))
+               wcmLinkTouchAndPen(pInfo);
+
        return Success;
 
 SetupProc_fail:
diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
index a124ed3..6545c90 100644
--- a/src/xf86Wacom.c
+++ b/src/xf86Wacom.c
@@ -766,6 +766,48 @@ static void wcmDisableTool(DeviceIntPtr dev)
 {
        wcmEnableDisableTool(dev, FALSE);
 }
+
+/**
+ * Unlink the touch tool from the pen of the same device
+ */
+static void wcmUnlinkTouchAndPen(InputInfoPtr pInfo)
+{
+       WacomDevicePtr priv = pInfo->private;
+       WacomCommonPtr common = priv->common;
+       InputInfoPtr device = xf86FirstLocalDevice();
+       WacomCommonPtr tmpcommon = NULL;
+       WacomDevicePtr tmppriv = NULL;
+       Bool touch_device = FALSE;
+
+       if (!TabletHasFeature(common, WCM_PENTOUCH))
+               return;
+
+       /* Lookup to find the associated pen and touch */
+       for (; device != NULL; device = device->next)
+       {
+               if (!strcmp(device->drv->driverName, "wacom"))
+               {
+                       tmppriv = (WacomDevicePtr) device->private;
+                       tmpcommon = tmppriv->common;
+                       touch_device = (common->wcmTouchDevice ||
+                                               tmpcommon->wcmTouchDevice);
+
+                       /* skip the same tool or unlinked devices */
+                       if ((tmppriv == priv) || !touch_device)
+                               continue;
+
+                       if (tmpcommon->tablet_id == common->tablet_id)
+                       {
+                               common->wcmTouchDevice = NULL;
+                               tmpcommon->wcmTouchDevice = NULL;
+                               common->tablet_type &= ~WCM_PENTOUCH;
+                               tmpcommon->tablet_type &= ~WCM_PENTOUCH;
+                               return;
+                       }
+               }
+       }
+}
+
 /*****************************************************************************
  * wcmDevProc --
  *   Handle the initialization, etc. of a wacom tablet. Called by the server
@@ -810,6 +852,7 @@ static int wcmDevProc(DeviceIntPtr pWcm, int what)
                case DEVICE_OFF:
                case DEVICE_CLOSE:
                        wcmDisableTool(pWcm);
+                       wcmUnlinkTouchAndPen(pInfo);
                        if (pInfo->fd >= 0)
                        {
                                xf86RemoveEnabledDevice(pInfo);
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 93debca..712e181 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -173,6 +173,7 @@ struct _WacomModel
 #define WCM_TPC                        (0x00000200 | WCM_LCD) /* TabletPC 
(special
                                                          button handling,
                                                          always an LCD) */
+#define WCM_PENTOUCH           0x00000400 /* Tablet supports pen and touch */
 #define TabletHasFeature(common, feature) (((common)->tablet_type & (feature)) 
!= 0)
 
 #define ABSOLUTE_FLAG          0x00000100
@@ -420,6 +421,9 @@ struct _WacomCommonRec
        int fd;                      /* file descriptor to tablet */
        int fd_refs;                 /* number of references to fd; if =0, fd 
is invalid */
        unsigned long wcmKeys[NBITS(KEY_MAX)]; /* supported tool types for the 
device */
+       WacomDevicePtr wcmTouchDevice; /* The pointer for pen to access the
+                                         touch tool of the same device id */
+       Bool wcmPenInProx;      /* Keep pen in-prox state for touch tool */
 
        /* These values are in tablet coordinates */
        int wcmMaxX;                 /* tablet max X value */
-- 
1.7.4


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to