From 2bd54ae1ca5c2368153a20c79d282b209050a4c8 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 23 Sep 2019 14:29:09 -0700 Subject: [PATCH] Ignore ABS_MISC as a source of device type information for AES pens AES sensors "appear" to use protocol 5 since they send ABS_MISC events which contain information about the tool type in use. The tool type information sent by AES sensors does not contain stylus/eraser/puck information, however, so we need to ignore it or else we may randomly end up treating the pens as erasers if a certian bit is set. Fixes: https://github.com/linuxwacom/xf86-input-wacom/issues/74 Signed-off-by: Jason Gerecke --- src/wcmUSB.c | 60 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/src/wcmUSB.c b/src/wcmUSB.c index 0e781ac9..f3c6bf25 100644 --- a/src/wcmUSB.c +++ b/src/wcmUSB.c @@ -1161,6 +1161,44 @@ static int usbFilterEvent(WacomCommonPtr common, struct input_event *event) return 0; } +/** + * Try to determine if a given tool ID belongs to an AES pen or not. + * Current definitions of the ID format define that bit 0 is a flag + * which indicates this. A few legacy pens have this bit set, however, + * making it hard to distinguish from this information alone. Ideally + * we would have a more robust mechanism that sets up an AES-specific + * protocol type at hotplug, but it seems I'm getting ahead of myself... + * + * @param id The tool id received from the kernel. + * @return 'true' if the tool uses AES, 'false' otherwise. + */ +static Bool toolIdIsAes(int id) +{ + if ((id & 0x01) == 0) { + return FALSE; + } + + /* If an AES pen is ever released with one of these IDs, this + * code will result in a false negative... *sigh* + */ + switch (id) { + case 0x801: /* Intuos3 Inking pen */ + case 0x823: /* Intuos3 Grip Pen */ + case 0x813: /* Intuos3 Classic Pen */ + case 0x885: /* Intuos3 Marker Pen */ + case 0x007: /* Mouse 4D and 2D */ + case 0x017: /* Intuos3 2D Mouse */ + case 0x097: /* Intuos3 Lens cursor */ + case 0x82b: /* Intuos3 Grip Pen Eraser */ + case 0x81b: /* Intuos3 Classic Pen Eraser */ + case 0x91b: /* Intuos3 Airbrush Eraser */ + case 0x913: /* Intuos3 Airbrush */ + return FALSE; + } + + return TRUE; +} + #define ERASER_BIT 0x008 #define PUCK_BITS 0xf00 #define PUCK_EXCEPTION 0x806 @@ -1177,14 +1215,20 @@ static int usbIdToType(int id) if (!id) return 0; - /* The existing tool ids have the following patten: all pucks, except - * one, have the third byte set to zero; all erasers have the fourth - * bit set. The rest are styli. - */ - if (id & ERASER_BIT) - type = ERASER_ID; - else if (!(id & PUCK_BITS) || (id == PUCK_EXCEPTION)) - type = CURSOR_ID; + if (toolIdIsAes(id)) { + /* Type information is not available from the ID for AES */ + return 0; + } + else { + /* The existing EMR tool ids have the following patten: all + * pucks, except one, have the third byte set to zero; all + * erasers have the fourth bit set. The rest are styli. + */ + if (id & ERASER_BIT) + type = ERASER_ID; + else if (!(id & PUCK_BITS) || (id == PUCK_EXCEPTION)) + type = CURSOR_ID; + } return type; }