test: don't leak open/closed counts into the next test

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
path: fix inconsistent use of devnode vs input->path

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Replace output screen size callback with transform helpers

Instead of automatically transforming absolute coordinates of touch and
pointer events to screen coordinates, the user now uses the corresponding
transform helper function. This means the coordinates returned by
libinput_event_pointer_get_absolute_x(),
libinput_event_pointer_get_absolute_y(), libinput_touch_get_x() and
libinput_touch_get_y() has changed from being in output screen coordinate
space to being in device specific coordinate space.

For example, where one before would call libinput_event_touch_get_x(event),
one now calls libinput_event_touch_get_x_transformed(event, output_width).

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Remove mention of delta coordinates having device specific direction

The event represent pointer motions on a screen, so this information is
unnecessary. It could also be confused for meaning the provided
coordinate's direction being device specific.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
evdev: Fix absolute coordinate transform formula

Since the device min/max x/y coordinates are inclusive, to get the
width/height one need to add one to (min x/y - max x/y).

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
test: plug a memory leak, all events need to be destroyed

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Move opening and closing the device fd into evdev.c

evdev_device_remove() already calls close(device->fd). Move the
close_restricted call there to avoid one privileged call in the backend and
one in the device. And move the open_restricted() into the evdev device too to
reduce the duplicated code in the two backends.

Update to one of the tests: since we'd now fail getting the device node from
the invalid /tmp path, the open_func_count is 0.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
path: add error handling for failing to create a seat

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: if mtdev failed to open, fail to init the device

We can't handle protocol A devices properly without mtdev, so skip the device
altogether.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: restore EVDEV_UNHANDLED_DEVICE error code

If we don't have capabilities we can deal with, return a different error so
the backends can handle it separately (they already do).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Revert "evdev: restore EVDEV_UNHANDLED_DEVICE error code"

This reverts commit e8c20c7241d29aa3b725e6a03d52656cafacf0e0.

Ooops, bad rebase. This accesses the device after it was already destroyed
which is not the intent of the patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
path: modify backend to allow for more than one device

The previous path backend created a libinput context attached to a single
device. This is insufficient when we need to use cross-device functionality.
One example of this cross-device functionality include disabling a touchpad
while the trackstick is in use (Lenovo T440 and related models).

This patch merely adds the infrastructure to support multiple devices for a
path backend. Follow-up patches add the function calls to add and remove
devices. This is needed by Xorg input drivers that still make use of the
server's device hotplug mechanisms but want to otherwise use libinput.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
path: add libinput_path_add_device() and libinput_path_remove_device()

This allows multiple devices to share a single libinput context. The new
function returns the newly added device immediately. Unlike the udev seat
where devices may or may not be added - over the lifetime of the seat - a
path-based backend knows immediately if device exists or doesn't exist.

Returning the device is required by callers that have the event processing
separate from adding devices - by the time we have the DEVICE_ADDED event in
the queue we may have other events to process first. And the DEVICE_ADDED
event won't easily link to the path we gave it anyway, so it's hard to figure
out which DEVICE_ADDED event corresponds to the new device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
path: add libinput_path_create_context instead of libinput_create_from_path

Creates an empty context that is not hooked up to a device. Callers can then
add and remove devices to this context using libinput_path_add_device() and
libinput_path_remove_device().

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
udev: rename create_from_udev to udev_create_for_seat

Maintain proper namespacing rename the backend-specific calls to
	libinput_<backend>_<foo>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test: Add tests for adding/removing devices

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev: restore EVDEV_UNHANDLED_DEVICE error code

If we don't have capabilities we can deal with, return a different
error so the backends can handle it separately (they already do).

Signe-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Make it possible to have persistent libinput_seat instances

With this patch, a user can keep a reference to a libinput_seat
instance, which will cause the seat to never be unlinked from the
libinput context nor destroyed.

Previously, a when the last device of a seat was removed, the seat was
unlinked and if a new device was discovered with a previously empty seat
a new seat instance would always be created, meaning two potential seat
instances with identical physical and logical seat name pairs.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
util: add min/max macros

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
evdev-touchpad: replace some numbers with a #define

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