Strengthen condition that pad may never be arbitrated pointer control

The pad should never be arbitrated pointer control since it is not a
pointer controlling device. The `check_arbitrated_control` function
performs its checks in the wrong order, however, and will grant control
if no other device is currently active.

This can cause touch to be disabled for "generic protocol" devices (e.g.
Intuos, Bamboo, etc.) until a pen is used because touch is the lowest-
priority device to be arbitrated access. For protocol 4/5 devices (e.g.
Intuos 5/4/3 and Cintiq) this can also lock out touch, but only if the
ExpressKey was pressed prior to the beginning of the touch, and only
while it remains held.

This patch strengthens the condition that the pad may never be granted
control by making it the first thing checked.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Fix pointer jump when tool enters prox with filtered coordinate

When a tool enters proximity, the usbChooseChannel function zeros
out one of the WacomDeviceState structures in the common->wcmChannel
array and returns its index. That state is then initalized using
the input events recieved from the kernel, and is assumed to be
a complete description by the time it is handed off to the wcmEvent
function.

The kernel's duplicate event filtering can cause problems for this,
however. If the value of the axis as it enters prox is identical to
its value when it left prox, the kernel will not send an event for
it (leaving the associated WacomDeviceState field zero). If this
occurs with the X and/or Y axis, the pointer will jump to the wrong
screen location.

To prevent the pointer from jumping around, we check if the X or Y
value of the WacomDeviceState are still zero after reading through
an enter-prox packet. If either is, we request its current value
from the kernel just in case it was filtered out. Other axes may be
affected by this bug, but should not cause as many problems.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Set the active driver to NULL before uninitalizing the device

If a device being used is disconnected, it may be possible to find
yourself in a situation where a second device performs an "active"
check and dereferences a null (freed in 'wcmFree') 'priv' pointer.
To prevent this from occuring, always check if the device being
uninitialized is considered 'active' and unset it if so.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reset wcmGestureState to current device state upon gesture start

The scroll and zoom gestures use of how far the fingers have travelled
as a way to determine how many times to send the scroll/zoom event.
When a gesture first starts, however, the fingers have already moved a
large distance simply to have the gesture be recognized. This may cause
a rapid and undesired "catch up" effect due to the large built-up delta.

To work around this, when a gesture starts, we reset the wcmGestureState
so that the functions are working with a clean slate and do not see the
large delta.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>