Fix double-free in wcmPreInitParseOptions

The 'tool' function here is set equal to 'priv->tool' earlier in
this function. If an error condition occurs, the tool can be freed
both here and in wcmFree (via wcmUninit).

It should be safe to postpone this free() until wcmFree to be
freed along with the rest of the memory allocated in wcmAllocate.
There should be no leak (wcmUninit will be called on failure) and
any code relying on priv->tool being a valid pointer after the
failure of wcmPreInitParseOptions is already broken.

https://bugs.freedesktop.org/show_bug.cgi?id=55200

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Properly handle nulls in wcmCheckSource

Commit cff344b1 modified the null-handling of wcmCheckSource, such
that the wrong result will be returned if either/both  fsource and
psource are null. This patch restores the original behavior.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Properly handle nulls in wcmIsHotpluggedDevice

Commit def7b5fd changed how wcmIsHotpluggedDevice handles null values,
with the result that a device with no "_source" specified would be
interpreted as having been hotplugged. This restores the original
behavior.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Add and use a 'dirty' bit for WacomChannel

Instead of keeping around 'channel_changed', 'mt_channel_changed',
and 'btn_channel_changed', just add a flag to the WacomChannel
itself that can be set whenever something changes.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Use serial number instead of channel number to identify contacts

Code that deals with touch points shouldn't care which channel an
event is occuring in; it should be more concerned with the finger
that caused it. At the moment these are the same things (first
finger is always in channel zero), but this will soon change.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Dynamically find touch channels, instead of hard-coding

Right now the driver assumes that the first touch will always
be in channel 0, and the second touch (if present) is in
channel 1. This patch adds a new function to scan the channel
list for appropriate contacts, and uses it instead of the
hard-coded index accesses.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Make usbInitToolType more generic, and always use

Tweaks the usbInitToolType function to be always useful. This is
needed so that we can use it to get the tool type for all event
frames, allowing us to properly fill in the tool type for devices
that we otherwise don't figure out until later on (which causes
problems with the proper operation of usbChooseChannel).

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Simplify usbChooseChannel logic

Instead of having different per-protocol cases, just obtain serial
numbers equivelent to those you'd get from Protocol 5 and then
use that serial to find a channel dynamically.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Have usbChooseChannel take explicit device type and serial args

Instead of divining this information from the stored private data,
take them as arguments. This gives us more flexibility in finding
channels for sub-tools (e.g. individual fingers).

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Dynamically choose channel for ABS_MT data

Now that the touch code doesn't look in statically-defined
channels and usbChooseChannel is capable of locating channel
numbers for arbitrary tool type/serial combinations, we can
use the latter to track an aribrary number of touches without
fear of stepping on the toes of another channel.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Use new multitouch protocol in XI2 if possible

Adds a new MULTITOUCH gesture mode that will redirect all in-contact
touches through the new multitouch code available in XI2.2 (ABI >= 16).

MULTITOUCH mode will only be entered when in-driver gestures have been
disabled and at least two fingers are present. The driver will remain
in this mode until *all* fingers have left the tablet.

For the moment, all touches are sent as XIDependentTouch. Direct touch
devices such as tablet PCs and Cintiqs are not an exception. This may
be changed in the future once frameworks are better equipped to handle
direct input touches.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Move check for enabled gestures to the functions that execute them

At the moment, disabling gestures disables *all* gestures. That includes
the core "tap to click" gesture (and slightly-less-core "tap and hold to
drag"). This patch allows these two gestures to not be considered such
by moving wcmGesture check into the functions that execute the gesture.
All two-finger functions (right click, scroll, and zoom) are disabled by
wcmGesture, but all single-finger functions remain operational.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Acked-by: Chris Bagwell <chris@cnpbagwell.com>
Tested-by: Chris Bagwell <chris@cnpbagwell.com>
Fix prerequisite check in wcmUpdateSerial

The prerequisite check in wcmUpdateSerial is incorrect. If the tool ID
changes, the property reflecting it will not be updated unless/until the
serial number also changes. The check is updated to reflect this.

Additionally, the prerequesite check at one of its callsites is removed
since the function performs the same check internally.

https://bugs.freedesktop.org/show_bug.cgi?id=45237

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Ping Cheng <pingc@wacom.com>