From: Egbert Eich <e...@suse.com>

usbInitToolType() tries to find the device type of a tool.
Unlike usbFindDeviceType() it doesn't take into account the device_id
which may exist in the event stream.
As a result the device type may be taken from the last known type.
This is generally a bad idea if the type has changed.
This will happen for example when pressing a key on the Cintiq 21UX menu
strips after removing a pen from the tablet.

Signed-off-by: Egbert Eich <e...@suse.com>
---
 src/wcmUSB.c | 50 ++++++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 14fff1b..f32c591 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -1078,6 +1078,26 @@ static int usbIdToType(int id)
        return type;
 }
 
+static int usbFindDeviceTypeById(int device_id)
+{
+       switch (device_id)
+       {
+               case STYLUS_DEVICE_ID:
+                       return STYLUS_ID;
+               case ERASER_DEVICE_ID:
+                       return ERASER_ID;
+               case CURSOR_DEVICE_ID:
+                       return CURSOR_ID;
+               case TOUCH_DEVICE_ID:
+                       return TOUCH_ID;
+               case PAD_DEVICE_ID:
+                       return PAD_ID;
+               default: /* protocol 5 */
+                       return usbIdToType(device_id);
+       }
+       return 0;
+}
+
 /**
  * Find the tool type (STYLUS_ID, etc.) based on the device_id or the
  *  current tool serial number if the device_id is unknown (0).
@@ -1096,27 +1116,7 @@ static int usbFindDeviceType(const WacomCommonPtr common,
 
        if (!ds->device_id) return 0;
 
-       switch (ds->device_id)
-       {
-               case STYLUS_DEVICE_ID:
-                       device_type = STYLUS_ID;
-                       break;
-               case ERASER_DEVICE_ID:
-                       device_type = ERASER_ID;
-                       break;
-               case CURSOR_DEVICE_ID:
-                       device_type = CURSOR_ID;
-                       break;
-               case TOUCH_DEVICE_ID:
-                       device_type = TOUCH_ID;
-                       break;
-               case PAD_DEVICE_ID:
-                       device_type = PAD_ID;
-                       break;
-               default: /* protocol 5 */
-                       device_type = usbIdToType(ds->device_id);
-       }
-
+       device_type = usbFindDeviceTypeById(ds->device_id);
        return device_type;
 }
 
@@ -1474,7 +1474,7 @@ static void usbParseBTNEvent(WacomCommonPtr common,
  * @param[in] code      Linux input tool code (e.g. BTN_STYLUS_PEN)
  * @return              Wacom device ID (e.g. STYLUS_ID) or 0 if no match.
  */
-static int toolTypeToDeviceType(WacomCommonPtr common, int type, int code)
+static int toolTypeToDeviceType(WacomCommonPtr common, int type, int code, int 
value)
 {
        wcmUSBData* private = common->private;
 
@@ -1506,6 +1506,8 @@ static int toolTypeToDeviceType(WacomCommonPtr common, 
int type, int code)
                        case ABS_MT_SLOT:
                        case ABS_MT_TRACKING_ID:
                                return TOUCH_ID;
+                       case ABS_MISC:
+                               return usbFindDeviceTypeById(value);
                }
        }
 
@@ -1535,7 +1537,7 @@ static int refreshDeviceType(WacomCommonPtr common)
        for (i = 0; i < KEY_MAX; i++)
        {
                if (ISBITSET(keys, i))
-                       device_type = toolTypeToDeviceType(common, EV_KEY, i);
+                       device_type = toolTypeToDeviceType(common, EV_KEY, i, 
0);
                if (device_type)
                        return device_type;
        }
@@ -1565,7 +1567,7 @@ static int usbInitToolType(WacomCommonPtr common, const 
struct input_event *even
 
        for (i = 0; (i < nevents) && !device_type; ++i, event_ptr++)
        {
-               device_type = toolTypeToDeviceType(common, event_ptr->type, 
event_ptr->code);
+               device_type = toolTypeToDeviceType(common, event_ptr->type, 
event_ptr->code, event_ptr->value);
        }
 
        if (!device_type)
-- 
1.8.4.5


------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to