Our serial number is always 0 to begin with. The event processing code knows
the serial number of the tool but didn't pass it on. This patch hooks into
the processing code to update the serial number in the device property.

Because of SIGIO malloc restrictions, the property must be updated through a
timer function.

Reported-by: Alexia Death <[email protected]>
Signed-off-by: Peter Hutterer <[email protected]>
---
 src/wcmCommon.c     |   16 +++++++++-----
 src/wcmConfig.c     |    4 +++
 src/wcmXCommand.c   |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xf86Wacom.h     |    1 +
 src/xf86WacomDefs.h |    2 +
 5 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index 5264ba5..3d52fd6 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -594,13 +594,17 @@ void wcmSendEvents(InputInfoPtr pInfo, const 
WacomDeviceState* ds)
        int naxes = priv->naxes;
        int v3, v4, v5;
 
-       if (priv->serial && serial != priv->serial)
+       if (priv->serial)
        {
-               DBG(10, priv, "serial number"
-                       " is %u but your system configured %u", 
-                       serial, (int)priv->serial);
-               return;
-       }
+               if (serial != priv->serial)
+               {
+                       DBG(10, priv, "serial number"
+                                       " is %u but your system configured %u",
+                                       serial, (int)priv->serial);
+                       return;
+               }
+       } else
+               wcmUpdateSerial(pInfo, serial);
 
        /* don't move the cursor when going out-prox */
        if (!ds->proximity)
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index d660088..efdc659 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -142,6 +142,9 @@ static int wcmAllocate(InputInfoPtr pInfo)
        area->next = NULL;    /* next area in list */
        area->device = pInfo; /* associated WacomDevice */
 
+       /* timers */
+       priv->serial_timer = TimerSet(NULL, 0, 0, NULL, NULL);
+
        return 1;
 
 error:
@@ -164,6 +167,7 @@ static void wcmFree(InputInfoPtr pInfo)
        if (!priv)
                return;
 
+       TimerFree(priv->serial_timer);
        free(priv->toolarea);
        free(priv->tool);
        wcmFreeCommon(&priv->common);
diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c
index 1b36280..58c95c9 100644
--- a/src/wcmXCommand.c
+++ b/src/wcmXCommand.c
@@ -24,6 +24,7 @@
 #include "xf86Wacom.h"
 #include "wcmFilter.h"
 #include <exevents.h>
+#include <xf86_OSproc.h>
 
 /*****************************************************************************
 * wcmDevSwitchModeCall --
@@ -687,6 +688,14 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, 
XIPropertyValuePtr prop,
                        wcmRotateTablet(pInfo, value);
        } else if (property == prop_serials)
        {
+               /* This property is read-only but we need to
+                * set it at runtime. If we get here from wcmUpdateSerial,
+                * we know the serial has ben set internally already, so we
+                * can reply with success. */
+               if (prop->size == 4 && prop->format == 32)
+                       if (((CARD32*)prop->data)[3] == priv->serial)
+                               return Success;
+
                return BadValue; /* Read-only */
        } else if (property == prop_strip_buttons)
                return wcmSetStripProperty(dev, property, prop, checkonly);
@@ -842,4 +851,51 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, 
XIPropertyValuePtr prop,
 
        return Success;
 }
+
+static CARD32
+serialTimerFunc(OsTimerPtr timer, CARD32 now, pointer arg)
+{
+       InputInfoPtr pInfo = arg;
+       WacomDevicePtr priv = pInfo->private;
+       XIPropertyValuePtr prop;
+       CARD32 prop_value[4];
+       int sigstate;
+       int rc;
+
+       sigstate = xf86BlockSIGIO();
+
+       rc = XIGetDeviceProperty(pInfo->dev, prop_serials, &prop);
+       if (rc != Success || prop->format != 32 || prop->size != 4)
+       {
+               xf86Msg(X_ERROR, "%s: Failed to update serial number.\n",
+                       pInfo->name);
+               return 0;
+       }
+
+       memcpy(prop_value, prop->data, sizeof(prop_value));
+       prop_value[3] = priv->serial;
+
+       XIChangeDeviceProperty(pInfo->dev, prop_serials, XA_INTEGER,
+                              prop->format, PropModeReplace,
+                              prop->size, prop_value, TRUE);
+
+       xf86UnblockSIGIO(sigstate);
+
+       return 0;
+}
+
+void
+wcmUpdateSerial(InputInfoPtr pInfo, int serial)
+{
+       WacomDevicePtr priv = pInfo->private;
+       if (!serial || priv->serial == serial)
+               return;
+
+       priv->serial = serial;
+       /* This function is called during SIGIO. Schedule timer for property
+        * event delivery outside of signal handler. */
+       priv->serial_timer = TimerSet(priv->serial_timer, 0 /* reltime */,
+                                     1, serialTimerFunc, pInfo);
+}
+
 /* vim: set noexpandtab tabstop=8 shiftwidth=8: */
diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
index bcc3b73..ff8841b 100644
--- a/src/xf86Wacom.h
+++ b/src/xf86Wacom.h
@@ -176,6 +176,7 @@ extern int wcmGetPhyDeviceID(WacomDevicePtr priv);
 extern int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr 
prop, BOOL checkonly);
 extern int wcmDeleteProperty(DeviceIntPtr dev, Atom property);
 extern void InitWcmDeviceProperties(InputInfoPtr pInfo);
+extern void wcmUpdateSerial(InputInfoPtr pInfo, int serial);
 
 /* Utility functions */
 extern Bool is_absolute(InputInfoPtr pInfo);
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 8cdc9e2..98b7f21 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -264,6 +264,8 @@ struct _WacomDeviceRec
        Atom btn_actions[WCM_MAX_BUTTONS];
        Atom wheel_actions[4];
        Atom strip_actions[4];
+
+       OsTimerPtr serial_timer;
 };
 
 /******************************************************************************
-- 
1.7.3.2

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to