From: Egbert Eich <e...@suse.com> This is the last bit of clean up and consolidation in tool type detection: usbParseAbsEvent() sets the tool type if it recognized a button or key event and the tool type has not been set before. Before we get to usbParseAbsEvent() channel mapping must have failed most certainly so we must have gotten a new channel for each button or key sequence. Since this seems to be a last resort attempt to determine the tool type we only do this when all other methods have failed before. The newly introduced function deriveDeviceTypeFromButtonEvent() mimics the behavior of usbParseAbsEvent().
Signed-off-by: Egbert Eich <e...@suse.com> --- src/wcmUSB.c | 62 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/wcmUSB.c b/src/wcmUSB.c index d69f291..e208819 100644 --- a/src/wcmUSB.c +++ b/src/wcmUSB.c @@ -1108,28 +1108,6 @@ static int usbFindDeviceTypeById(int 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). - * - * Protocol 5 devices report different IDs for different styli and pucks, - * Protocol 4 devices simply report STYLUS_DEVICE_ID, etc. - * - * @param ds The current device state received from the kernel. - * @return The tool type associated with the tool id or the current - * tool serial number. - */ -static int usbFindDeviceType(const WacomCommonPtr common, - const WacomDeviceState *ds) -{ - int device_type = 0; - - if (!ds->device_id) return 0; - - device_type = usbFindDeviceTypeById(ds->device_id); - return device_type; -} - static void usbParseAbsEvent(WacomCommonPtr common, struct input_event *event, int channel_number) { @@ -1185,10 +1163,7 @@ static void usbParseAbsEvent(WacomCommonPtr common, case ABS_MISC: ds->proximity = (event->value != 0); if (event->value) - { ds->device_id = event->value; - ds->device_type = usbFindDeviceType(common, ds); - } break; default: change = 0; @@ -1461,10 +1436,6 @@ static void usbParseBTNEvent(WacomCommonPtr common, } channel->dirty |= change; - - /* expresskey pressed at startup or missing type */ - if (!ds->device_type && channel->dirty) - ds->device_type = PAD_ID; } /** @@ -1561,6 +1532,35 @@ static int refreshDeviceType(WacomCommonPtr common) return 0; } +static int deriveDeviceTypeFromButtonEvent(WacomCommonPtr common, + const struct input_event *event_ptr) +{ + wcmUSBData *usbdata = common->private; + int nkeys; + + if (event_ptr->type == EV_KEY) { + + switch (event_ptr->code) { + case BTN_LEFT: + case BTN_MIDDLE: + case BTN_RIGHT: + case BTN_SIDE: + case BTN_BACK: + case BTN_EXTRA: + case BTN_FORWARD: + return PAD_ID; + default: + for (nkeys = 0; nkeys < usbdata->npadkeys; nkeys++) + { + if (event_ptr->code == usbdata->padkey_code[nkeys]) { + return PAD_ID; + } + } + } + } + return 0; +} + /*** * Retrieve the tool type from an USB data packet by looking at the event * codes. Refer to linux/input.h for event codes that define tool types. @@ -1592,6 +1592,10 @@ static int usbInitToolType(WacomCommonPtr common, const struct input_event *even if (!device_type) device_type = refreshDeviceType(common); + if (!device_type) /* expresskey pressed at startup or missing type */ + for (i = 0; (i < nevents) && !device_type; ++i, event_ptr++) + device_type = deriveDeviceTypeFromButtonEvent(common, event_ptr); + return 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