If the start and end of a touch are dropped, the slot, according to the
kernel, may have a different state. We should inform the client of these
changes even if the slot is not currently active.
For most axes this doesn't matter too much as we expect them to change
during an active touch anyway so we don't expect the kernel's caching to
be a problem. However where the ABS_MT_TOOL_TYPE changed during a sync
we need to inform the client of the new tool type so that future
touchese won't be erroneously treated as e.g. palms.
For a full reproducer see the test case but it comes down to:
- touch down with MT_TOOL_PALM, make sure libevdev reads the state
- change that slot to MT_TOOL_FINGER, trigger a sync
- ensure that libevdev pushes out that tool type change even if the
slot is not currently active
Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/libevdev/libevdev/-/merge_requests/124>
Due to what must've been a copy/paste error many years ago, the license text
for libevdev wasn't actually the MIT license. Let's rectify this, it was
always MIT intended anyway.
To make this more obvious and reduce the chance of copy/paste mistakes, use
the SPDX license identifier in the various source files. The two installed
public header files have the full license text.
All contributors with copyrightable contributions have ACKed the license
change to MIT, either in the MR directly [1] or privately in reply to an
email.
[1] https://gitlab.freedesktop.org/libevdev/libevdev/-/merge_requests/69
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Alexander Dahl <ada@thorsis.com>
Acked-by: Andreas Pokorny <andreas.pokorny@canonical.com>
Acked-by: Armin K <krejzi@email.com>
Acked-by: Benjamin Tissoires <btissoir@redhat.com>
Acked-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Deepa Dinamani <deepa.kernel@gmail.com>
Acked-by: Emmanuele Bassi <ebassi@gnome.org>
Acked-by: Gaetan Nadon <memsize@videotron.ca>
Acked-by: George Thomas <georgefsthomas@gmail.com>
Acked-by: Michael Forney <mforney@mforney.org>
Acked-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
Acked-by: Niclas Zeising <zeising@daemonic.se>
Acked-by: Owen W. Taylor <otaylor@fishsoup.net>
Acked-by: Peter Seiderer <ps.report@gmx.net>
Acked-by: Ran Benita <ran234@gmail.com>
Acked-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Scott Jann <sjann@knight-rider.org>
Acked-by: Thilo Schulz <thilo@tjps.eu>
Acked-by: polyphemus <rolfmorel@gmail.com>
Where at least one touch ends during SYN_DROPPED, we send out two event
frames: one with all applicable touch sequences ending (tracking id -1) and
the second one with the whole device state *and* the applicable touch
sequences starting (tracking id != -1).
This requires us to also update the BTN_TOOL_ bits correctly so that they are
correct after the first frame. For that we count the number of previously
known touches and send a 0 event for the matching BTN_TOOL_ bit, together with
a 1 event for the currently known touches.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
For debugging it's more important to be able to quickly run a single test
rather than grouping them together, we don't have thousands of tests here
anyway. So let's add a macro to put every test func into its own TCase,
allowing for test selection via the environment variable CK_RUN_CASE.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
We're only testing EV_SW event delivery here and SW_LID has the tendency to
suspend the host when we don't specifically inhibit it. So let's just swap for
the next one.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
With the previous approach, every libevdev_next_event() invocation triggered a
read() on the device fd. This is not efficient, the kernel provides whole
event frames at a time so we're guaranteed to have more events waiting unless
the current event is a SYN_REPORT.
Assuming a fast-enough client and e.g. a touchpad device with multiple axes
per frame, we'd thus trigger several unnecessary read() calls per event frame.
Drop this behavior, instead only trigger the read when our internal queue is
empty and we need more events.
Fallout:
- we don't have any warning about a too-slow sync, i.e. if a SYN_DROPPED
arrives while we're syncing, we don't get a warning in the log anymore.
the test for this was removed.
- the tests that required the specific behavior were rewritten accordingly
- a revoke on a kernel device doesn't return ENODEV until already-received
events have been processed
The above shouldn't be an issue for existing real-world clients.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
It's not really autodetection, we just declare the test suites that need root
privs. But this way we can generically check for it from the main() that we
re-use across tests.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Move all tests to a special section, then loop through that section
to fetch all test suite. The result is that new tests only need to add the
source files without having to update everything else as well.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
We abort if anything goes wrong anyway, so we never returned anything but
success.
Found by coverity.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
ioctl points to uninitialized bytes - correct but we didn't use those anyway.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
The kernel ring buffer drops all events on SYN_DROPPED, but then continues to
fill up again. So by the time we read the events, the kernel's client buffer is
essentially like this:
SYN_DROPPED, ev1, ev2, ev3, ...., evN
The kernel's device state represents the device after evN, and that is what
the ioctls return. For EV_KEY, EV_SND, EV_LED and EV_SW the kernel removes
potential duplicates from the client buffer [1], it doesn't do so for EV_ABS.
So we can't actually sync while there are events on the wire because the
events represent an earlier state. So simply discard all events in the kernel
buffer, synchronize, and then start processing again. We lose some granularity
but at least the events are correct.
[1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/input/evdev.c?id=483180281f0ac60d1138710eb21f4b9961901294
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Follow-up to
commit 41334b5b40
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date: Thu Mar 6 11:54:00 2014 +1000
If the tracking ID changes during SYN_DROPPED, terminate the touch first
In normal mode, we may get double tracking ID events in the same slot, but
only if we either have a user-generated event sequence (uinput) or a malicious
device that tries to send data on a slot > dev->num_slots.
Since the client is unlikely to be able to handle these events, discard the
ABS_MT_TRACKING_ID completely. This is a bug somewhere in the stack, so
complain and hobble on along.
Note: the kernel doesn't allow that, but we cap to num_slots anyway, see
66fee1bec4.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
We can't allocate in sync_mt_state since it may be called in the signal
handler. So pre-allocate based on the device's number of slots, store that in
the libevdev struct and use it for the sync process.
This fixes a remaining bug with the handling of ABS_MT_TRACKING_ID. If a
device had > MAX_SLOTS and a slot above that limit would start or stop during
a SYN_DROPPED event, the slot would not be synced, and a subsequent touch in
that slot may double-terminate or double-open a touchpoint in the client.
For the effects of that see
commit 41334b5b40
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date: Thu Mar 6 11:54:00 2014 +1000
If the tracking ID changes during SYN_DROPPED, terminate the touch first
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
A max of num_slots -1 caused the first MT_SLOT event to be skipped, leading to
wrong tracking IDs in the slots.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test-libevdev-events.c: In function ‘test_double_syn_dropped_event’:
test-libevdev-events.c:187:2: warning: ignoring return value of ‘read’,
declared with attribute warn_unused_result [-Wunused-result]
This read was there to drain events even when there shouldn't be any on the
pipe anyway. So let's add an assert.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Most clients can't deal with tracking ID changes unless a -1 is sent first. So
if we notice that the tracking ID has changed during the sync process, send a
set of ABS_MT_TRACKING_ID -1 events for each of those, then send the rest of
the events.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
If multiple slots have changed during the sync handling, the client must be
re-set to the current slot before continuing with normal events.
Signed-off-by: Benjamin Tissoires <btissoir@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Devices with ABS_MT_SLOT-1 are fake MT devices, they merely overlap the
axis range but don't actually provide slots. The EVIOCGABS ioctl won't work to
retrieve the current value - the kernel does not store values for those axes
and the return value is always 0.
Thus, simply ignore those axes for fake MT devices and instead rely on the
next event to update the caller with the correct state for each axis.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
A malicious device may announce N slots but then send a slot index >= N. The
slot state is almost always allocated (definitely the case in libevdev and
true for most callers), so providing a slot number higher than the announced
maximum is likely to lead to invalid dereferences. Don't allow that.
Likewise, don't allow negative slot numbers.
Note that the kernel filters these events anyway, the only way to trigger this
is to change the device fd to something outside the kernel's control.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
When syncing, we expect the slot to stay the same until the client has
processed the events. This already worked, just add a check to make sure.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
As seen on 3M devices, which seems to be the maximum seen so far. Some Stantum
devices report 255 touches but are only capable of 10, so the are not affected
by our limits.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
If the first event after a completed device sync is a SYN_DROPPED, warn the
user that they're not fast enough handling this device.
The test for this is rather complicated since we can't write SYN_DROPPED
through uinput so we have to juggle the device fd and a pipe and switch
between the two at the right time (taking into account that libevdev will read
events from the fd whenever it can).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
All clients that want to handle SYN_DROPPED correctly need to pass an EV_SYN
through their own handlers before starting with the syn events. Rather than
letting them synthesize that, guarantee that the event is defined the first
time LIBEVDEV_READ_STATUS_SYNC is returned.
This does not change existing behavior, it merely documents it so we can rely
on it.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
We shouldn't have a separate API for that, the whole point of libevdev is to
abstract the quirkyness of the ioctls into a common interface. So let's
export the two EV_REP values through libevdev_get_event_value.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Rename from LIBEVDEV_READ_foo to LIBEVDEV_READ_FLAG_foo to differentiate
better from LIBEVDEV_READ_STATUS_foo.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Improved readability in callers, changing magic numbers 0 and 1 to
rc = libevdev_next_event();
if (rc == LIBEVDEV_READ_STATUS_SUCCESS)
do_something();
else if (rc == LIBEVDEV_READ_STATUS_SYNC)
do_something_else()
No ABI changes, the enum values are the previously documented values,
this is just a readability improvement.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This way any ABS_MT_ event value that comes in will also be stored in abs_info.
That always corresponds to "current slot", so if a user calls
libevdev_set_event_value() or libevdev_get_event_value() they're actually
modifying the current slot value.
When the current slot changes, sync the state back into the absinfo values.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This enables libevdev_get_event_value(dev, EV_LED, LED_NUML); to check
if a LED is on or off.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>