Use sensible slot IDs in XI2 mode

After DIM_TOUCH touches have been registered by the program in
total, the program will crash when running the XI2 backend becuase
old IDs are never recycled. The 'next_slot' continues to rise with
each new touch, eventually causing the 'output_touch' function to
write byond the end of the 'id' and 'color' arrays.

This changes how slot IDs are generated in 'handle_xi2_event' so
that this doesn't occur. We use the index of the touch in the
'ti->touches' array as a de-facto slot identifier.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Fix crash when device claims more touches than DIM_TOUCH

If a device claims support for more than DIM_TOUCH touches, we
walk off the end of the allocated space for the touches array and
corrupt other data in the stack. This limits touches to DIM_TOUCH
at most.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Prevent more than DIM_TOUCH simultaneous touches

If more than DIM_TOUCH simtulataneous touches are received, the evdev
and xi2 backends will attempt to store data for the touch beyond the
end of the touches array, potentially resulting in a segfault.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Loop index saved instead of valuator index

The valuator index is not necessarily the index of the loop. Using
the wrong index causes us to grab data from the wrong valuator
prior to display.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Access touch_data in handle_xi2_event through pointer, not index

The loop index 'i' is used in handle_xi2_event as both an index
to 'ti->touches' and as an index to the event's valuator mask.
Both senses are used simultaneously in the latter-half of the
function, leading to incorrect array accesses.

This function isolates the two usages by storing a pointer to
the touch_data found in the first half, so that the variable
may be safely reused in the second half.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Get XI2 X and Y axes from valuators, not root

The root value is not in device space, which causes the re-mapping
done in the output function to no longer map up 1:1 with what is
on-screen. We can either pre-scale the root values or grab them
from the valuators to fix this; this patch goes with the latter.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>