test: Use only one test device for some udev and path tests

Some tests in test/path.c and test/udev.c are not dependent on
device behaviour but rather managing of device lifetime etc. Run those
tests only once with only one device, resulting more or less the same
code coverage but shorter run time.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
test: Remove test device from context when deleting

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
test: Don't fail when events are enabled multiple times

When overriding events of a test device, if one would enable an event
that was already enabled by default for the overridden device, an assert
checking if the event was already enabled would fail and cause the test
to fail.

Since the merging of the default and overriding event lists is implemented
by simply concatinating them letting libevdev deal with ignoring
superfluous event enabling, remove the assert to allow the implementation
to work.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: Let dispatch instances set their own capabilities

It's up to a evdev device backend to configure seat capabilities it
supports. Even though it may be possible for a touchpad to have extra
keys, there is currently no support for sending keyboard events from the
touchpad driver, and if that would be implemented, it'd be a detail of
the touchpad driver, not the generic evdev device part.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: Use helper for separating buttons from keys

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: Ignore key/button release events if key was never pressed

The kernel may send a 'release' event without ever having sent a key
'pressed' event in case the key was pressed before libinput was
initiated. Ignore these events so that we always guarantee a release
event always comes after a pressed event for any given key or button.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
evdev: Keep track of button/key press count per device

Keep track of the number of times a given button or key is pressed on a
device. For regular mouse devices or keyboard devices, such a count will
never exceed 1, but counting button presses could help when button
presses with the same code can originate from different sources. One could
for example implement overlapping tap-drags with button presses by
having them deal with their own life-time independently, sorting out
when the user should receive button presses or not depending on the
pressed count.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: Release still pressed keys/buttons when removing device

When removing a device, its not guaranteed that all button or key
presses have been released, resulting in an invalid seat wide button
count.

Note that kernel devices normally will send release events when being
unplugged, but this won't happen when removing a device from the path
backend.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Use -no-install instead of -static for local noinst linking

The goal of -static was to avoid the libtool wrappers for easier debugging.
The -no-install flag does exactly that, without requiring static linking.

Related to https://bugs.freedesktop.org/show_bug.cgi?id=82292

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Disable static libraries

Our static library leaks symbols like crazy, some of which are likely
conflicts with users of this library (log_msg, open_restricted, ...).

Disale static linking by default so we don't have to spend time debugging
this.

Related to:
https://bugs.freedesktop.org/show_bug.cgi?id=82292
https://bugs.freedesktop.org/show_bug.cgi?id=82785

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
evdev: plug memory leak on libevdev_new_from_fd failure

Found by coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Don't close the fd if libinput_add_fd() fails

Let the caller decide what to do with the fd.

In the current code the caller can't know if the fd was closed on error since
we return NULL on malloc failure as well as on epoll_ctl() failure. In the
latter case the fd was closed, not in the former. The caller had to close
the fd anyway (and all three callers do), so drop closing the fd from this
function.

Found by Coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
touchpad: mark a intentional switch case fallthrough as such

Both motion and timeout expiry transition into the TOUCH_2_HOLD state, but
only for motion do we need to cancel the current timeout.

Found by Coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Swap conditions for ARRAY_FOR_EACH()

The current conditions result in _elem being assigned _arr[i] before the
condition is checked. This is fine since we then break from the loop and don't
access it anyway, but it makes Coverity unhappy.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
touchpad: silence Coverity warnings about uninitialized use

container_of() accesses tp for offset calculation. Which is fine, but
Coverity doesn't know that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Fix a doxygen reference

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test: add helpers to wait for specific events

litest_wait_for_event() returns if any event is available.
litest_wait_for_event_of_type(... type, type, type, -1) returns if any of the
given event types is availble. All other events are discarded.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test: add a generic single-touch device

With a non-zero absmin for both axes and different ranges for x/y, just to
detect those errors.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
udev: use evdev_device_calibrate() instead of manually writing the matrix

We have a wrapper, use it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
evdev: constify evdev_device_calibrate

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>