usbInitToolType retrieves device type from the kernel when tool
is on the tablet at X server startup. No need to do it again later.

Since kernel does not have a specific device type for PAD, we have
to check the actual events to set its type.

Signed-off-by: Ping Cheng <pi...@wacom.com>
---
v2: move PAD corner case into a separate patch as suggested by Jason.
---
 src/wcmUSB.c |   59 +++++-----------------------------------------------------
 1 file changed, 5 insertions(+), 54 deletions(-)

diff --git a/src/wcmUSB.c b/src/wcmUSB.c
index 75caa6b..48a1f95 100644
--- a/src/wcmUSB.c
+++ b/src/wcmUSB.c
@@ -1,6 +1,6 @@
 /*
  * Copyright 1995-2002 by Frederic Lepied, France. <lep...@xfree86.org>
- * Copyright 2002-2010 by Ping Cheng, Wacom. <pi...@wacom.com>
+ * Copyright 2002-2013 by Ping Cheng, Wacom. <pi...@wacom.com>
  *                                                                            
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -1223,25 +1223,6 @@ static void usbParseAbsMTEvent(WacomCommonPtr common, 
struct input_event *event)
        (&common->wcmChannel[private->wcmMTChannel])->dirty |= change;
 }
 
-static struct
-{
-       unsigned long device_type;
-       unsigned long tool_key;
-} wcmTypeToKey [] =
-{
-       { STYLUS_ID, BTN_TOOL_PEN       },
-       { STYLUS_ID, BTN_TOOL_PENCIL    },
-       { STYLUS_ID, BTN_TOOL_BRUSH     },
-       { STYLUS_ID, BTN_TOOL_AIRBRUSH  },
-       { ERASER_ID, BTN_TOOL_RUBBER    },
-       { CURSOR_ID, BTN_TOOL_MOUSE     },
-       { CURSOR_ID, BTN_TOOL_LENS      },
-       { TOUCH_ID,  BTN_TOOL_DOUBLETAP },
-       { TOUCH_ID,  BTN_TOOL_TRIPLETAP },
-       { PAD_ID,    BTN_FORWARD        },
-       { PAD_ID,    BTN_0              }
-};
-
 static void usbParseKeyEvent(WacomCommonPtr common,
                            struct input_event *event, int channel_number)
 {
@@ -1434,6 +1415,8 @@ static void usbParseBTNEvent(WacomCommonPtr common,
                        }
                        if (nkeys >= usbdata->npadkeys)
                                change = 0;
+                       else if (!ds->device_type) /* expresskey pressed at 
startup */
+                               ds->device_type = PAD_ID;
        }
 
        channel->dirty |= change;
@@ -1625,9 +1608,9 @@ static void usbDispatchEvents(InputInfoPtr pInfo)
        ds = &common->wcmChannel[channel].work;
        dslast = common->wcmChannel[channel].valid.state;
 
-       /* no device type? tool was on the tablet at startup, force type and
-          proximity */
+       /* no device type? */
        if (!ds->device_type && private->wcmDeviceType) {
+               /* tool was on tablet at startup, force type and proximity */
                ds->device_type = private->wcmDeviceType;
                ds->proximity = 1;
        }
@@ -1686,38 +1669,6 @@ static void usbDispatchEvents(InputInfoPtr pInfo)
                }
        } /* next event */
 
-       /* device type unknown? Tool may be on the tablet when X starts. */
-       if (!ds->device_type && !dslast.proximity)
-       {
-               unsigned long keys[NBITS(KEY_MAX)] = { 0 };
-               int rc;
-
-               if (!ds->proximity) {
-                       DBG(3, common, "Unknown out-of-prox device leaving 
prox. Ignoring.\n");
-                       return;
-               }
-
-               /* Retrieve the type by asking a resend from the kernel */
-               rc = ioctl(common->fd, EVIOCGKEY(sizeof(keys)), keys);
-               if (rc == -1)
-               {
-                       LogMessageVerbSigSafe(X_ERROR, 0,
-                                             "%s: failed to retrieve key 
bits\n",
-                                             pInfo->name);
-                       return;
-               }
-
-               for (i = 0; i < ARRAY_SIZE(wcmTypeToKey); i++)
-               {
-                       if (ISBITSET(keys, wcmTypeToKey[i].tool_key))
-                       {
-                               ds->device_type = wcmTypeToKey[i].device_type;
-                               ds->proximity = 1;
-                               break;
-                       }
-               }
-       }
-
        /* DTF720 and DTF720a don't support eraser */
        if (((common->tablet_id == 0xC0) || (common->tablet_id == 0xC2)) && 
                (ds->device_type == ERASER_ID)) 
-- 
1.7.10.4


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to