Commit graph

182 commits

Author SHA1 Message Date
Peter Hutterer
f925cee8df Hook up libevdev as backend
libevdev wraps the various peculiarities of the evdev kernel API into a
type-safe API. It also buffers the device so checking for specific features at
a later time is easier than re-issuing the ioctls. Plus, it gives us almost
free support for SYN_DROPPED events (in the following patch).

This patch switches all the bit checks over to libevdev and leaves the event
processing as-is. Makes it easier to review.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2014-02-24 09:29:09 +10:00
Peter Hutterer
d31b1b7b70 evdev: reset the device fd after closing it
A caller may have a reference to the device after closing it, make sure that
ref doesn't have a dangling fd so future attempts of reading from/writing to
the device fail.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-21 16:13:02 +10:00
Benjamin Tissoires
128f98c43b evdev: fix device_transform_ functions
X and Y are li_fixed_t, which is 24.8 fixed point real number.
li_fixed_t max is thus ~8388607.

On a touchscreen with a range of 32767 values (like a 3M sensor), and
mapped on monitor with a resolution of 1920x1080, we currently have:
(x - li_fixed_from_int(device->abs.min_x)) * width == 62912640

which is 7 times bigger than li_fixed_t max.

Force a cast to uint64_t to keep the precision of the sensor.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-02-20 11:30:08 +10:00
Jonas Ådahl
803f254343 evdev: Use -1 to represent touch events slots from single touch devices
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-02-17 20:12:19 +01:00
Peter Hutterer
26a1fff787 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>
2014-02-10 15:40:49 +10:00
Peter Hutterer
f6e8160ce1 Revert "evdev: restore EVDEV_UNHANDLED_DEVICE error code"
This reverts commit e8c20c7241.

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>
2014-02-10 11:23:35 +10:00
Peter Hutterer
e8c20c7241 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>
2014-02-06 09:46:34 +10:00
Peter Hutterer
e13f736cff 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>
2014-02-06 09:46:34 +10:00
Peter Hutterer
1901449871 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>
2014-02-06 09:16:43 +10:00
Jonas Ådahl
512e964661 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>
2014-02-03 23:39:58 +01:00
Jonas Ådahl
1f1304041c 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>
2014-02-03 23:39:58 +01:00
Jonas Ådahl
b57656aa9a evdev: Don't queue touch events when no touch capability is reported
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-27 23:35:14 +01:00
Jonas Ådahl
3290b78bd6 evdev: Don't report touch devices with buttons as actual touch devices
This was a detail of the original version of the commit "evdev: Remove
EVDEV_TOUCH and with it evdev_device->caps" that got lost during porting.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-27 23:35:11 +01:00
Jonas Ådahl
8264c3b60b evdev: Make evdev manage its seat reference
Before the seat reference would be decreased when a device was removed.
This could cause libinput_device_get_seat() to potentially return an
invalid pointer when a device was removed, its seat unreferenced and
destryoed.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-22 23:59:32 +01:00
Jonas Ådahl
a0a685ff2e evdev: Make error handling more consistent
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-22 23:43:45 +01:00
Peter Hutterer
09a3770961 evdev: don't ignore scroll events with a value greater than 1/-1
Higher values than 1 or -1 are legitimate on some devices, though not all mice
send wheel events other than 1/-1.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 11:16:29 +10:00
Peter Hutterer
6ff352f5e3 Promote touch frames to top-level events
These events are not a state of a single touchpoints but rather a notification
that all touchpoints finished processing. As such, they should have their own
type.

And make sure we actually send them when needed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 11:16:28 +10:00
Peter Hutterer
ab9260c5c7 Drop capability events
We don't really support devices changing capabilities at runtime. The kernel
has no ability to tell us when this happens on an already-opened device and
the few devices that can literally change physical capabilities (e.g. the
wiimote) open up extra kernel devices instead of modifying the existing one.

Thus, we don't need to notify about devices changing capabilities.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-10 11:08:40 +10:00
Kristian Høgsberg
fef5004c46 evdev: Drop joystick rejection heurstics
We now no longer add joysticks at all.  They show up as absolute motion
devices without has_button, so we don't add them as a pointer.  We may add
a keyboard for the keyboard-style keys, but that's fine.  With the previous
commit, we no longer generate spurious absolute pointer motion for the abs
axes.

https://bugs.freedesktop.org/show_bug.cgi?id=71687
2013-12-21 12:54:27 +01:00
Kristian Høgsberg
4004080f27 evdev: Reject absolute motion if we're not a pointer or a touch device
Some joysticks have certain buttons that acts keyboard keys.  As such,
we'll reconize them as keyboards but not pointers.  In that case, don't
send pointer motion events when we get absolute joystick events.
2013-12-21 12:53:29 +01:00
Kristian Høgsberg
83f3319f18 evdev: Drop obsolete accelerometer reject rule
This rule triggers for devices with an ABS_X/Y evaluators and no
keyboard or multitouch events.  There is no way we would ever add such
a device as a pointer, keyboard or touch device anyway.  A pointer
device requires has_button (in which case the !has_key condtion would
fail); a keyboard device would also mean !has_key is false and a touch
screen device implies that !device->is_mt is false.
2013-12-21 12:51:52 +01:00
Kristian Høgsberg
6eebf35653 evdev: Remove EVDEV_TOUCH and with it evdev_device->caps
We now keep all the configuration intermediate results inside
evdev_configure_device() and the result is device->seat_caps.
2013-12-21 12:49:17 +01:00
Kristian Høgsberg
f6caf57b00 evdev: Use a has_keyboard flag instead of EVDEV_KEYBOARD bit 2013-12-21 12:44:03 +01:00
Kristian Høgsberg
4124ca1433 evdev: Replace EVDEV_BUTTON with local has_button flag 2013-12-21 12:35:43 +01:00
Kristian Høgsberg
a847278c4a evdev: Replace EVDEV_MOTION_ABS with local has_abs flag 2013-12-21 12:34:26 +01:00
Kristian Høgsberg
7226e8c368 evdev: Use has_abs only for ABS_X and ABS_Y, introduce has_mt for MT events
We split up has_abs into plain ABS_X/Y and MT events, but this shouldn't
introduce any logic changes.
2013-12-21 12:32:31 +01:00
Kristian Høgsberg
606706f87f evdev: Drop EVDEV_MOTION_REL flag
This is only used inside evdev_configure_device() and we now use a local
has_rel flag instead.
2013-12-21 12:32:06 +01:00
Kristian Høgsberg
a5db876938 evdev: Combine evdev_handle_device() and evdev_configure_device()
We split the device probing and idenfication somewhat arbitrarily between
these two functions.  This commit combines them into one.  Return of -1
indicates error, 0 success, but succesful probing can return a device
with device->caps == 0, which means we don't handle the device.
2013-12-21 12:25:17 +01:00
Jonas Ådahl
1dad790a7f Introduce libinput_device_get_sysname() API
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-15 17:50:04 +01:00
Jonas Ådahl
d791a7ab09 Introduce libinput_device_has_capability() API
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-15 17:45:02 +01:00
Peter Hutterer
9e6cf91f48 evdev: fix memcopy for calibration
Function arguments with fixed length are still just pointers, so
sizeof(calibration) here is sizeof(float*), not sizeof(float) * 6.

evdev.c: In function 'evdev_device_calibrate':
evdev.c:693:54: warning: argument to 'sizeof' in 'memcpy' call is the same
  pointer type 'float *' as the destination; expected 'float' or an explicit
  length [-Wsizeof-pointer-memaccess]
  memcpy(device->abs.calibration, calibration, sizeof calibration);

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Jonas Ådahl
56f7ddec82 Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.

The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.

Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.

The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().

The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.

There is one known problem with the current API that is the potentially
racy initialization.

The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-24 21:19:18 +01:00
Jonas Ådahl
3450e49c86 Add interface to libinput object and move screen dimension callback to it
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-19 22:26:45 +01:00
Jonas Ådahl
d894b1d700 Use events instead of callbacks for capability registration
This commit also introduces a new requirement to
libinput_device_destroy() - libinput_device_terminate() must be called
before libinput_device_destroy() in order to allow the user to dispatch
the events related to a terminating input devices while the device is
still valid.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-17 18:32:53 +01:00
Jonas Ådahl
ce787552bc Introduce libinput object managing all input data
Instead of having the user manage added and removed fd's as well as the
fd used for creating evdev devices, introduce a libinput object that
itself has an epoll fd.

The user no longer manages multiple fd's per libinput instance, but
instead handles one fd, dispatches libinput when data is available, then
reading events using libinput_get_event().

libinput_event's are now per libinstance, but divided into categories.
So far the only category is device events. Device events are categorized
by the presence of a non-NULL device pointer in the event.

The current API usage should look like:

struct libinput libinput = ...;
struct libinput_event *event;

if (libinput_dispatch(libinput) != 0)
	return -1;
while ((event = libinput_get_event(libinput))) {
	if (event->device)
		process_device_event(event);
	free(event);
}

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-17 17:03:06 +01:00
Jonas Ådahl
79d77d4b8b Don't use the `seat' concept on device capability enum
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-13 22:11:34 +01:00
Jonas Ådahl
bd4db1c2a2 Port evdev code to be used as a shared library
This commit introduces build script configuration for building a shared
library 'libinput.so' containing the evdev input device functionality
from weston.

evdev.c, evdev.h and evdev-touchpad.c are ported to not use the data
structures and API in weston and libwayland-server in order to minimize
dependencies.

The API of filter.c and filter.h are renamed to not include the
'weston_' prefix.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-12 22:37:20 +01:00
Jonas Ådahl
75f453df6a evdev: Synchronize keys only if seat is keyboard capable
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
Jonas Ådahl
098ca89e17 Make weston_output_transform_coordinate() take wl_fixed_t coordinates
This is to make it possible for future API to have non-integer
coordinates as input.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
Kristian Høgsberg
077e0c937a compositor: Remove redundant and not well-defined focus field
It was never clear what this field really did.
2013-11-10 17:51:34 +01:00
Jonas Ådahl
c442b9fd60 evdev: Reference count input device's seat capabilities
When the only input device of a certain seat capability is unplugged,
stop advertising the capability.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
David Herrmann
b98d0b9d89 evdev: release devices on read() error
If read() fails without EAGAIN/EINTR, the device is very likely dead.
However, we must not remove the device as it might be muted/revoked. So we
simply remove the event-source to avoid polling the device and simply wait
for the udev-remove signal now.

Note that we cannot call evdev_device_destroy() as the caller created the
FD and might need custom code to close it (like weston_launcher_close()).
2013-11-10 17:51:34 +01:00
Kristian Høgsberg
d4c9c6b83b evdev: Clear touch capability if we see a mouse-type button
If an input device has BTN_LEFT (typically) it's not a touch screen but
a touch pad.
2013-11-10 17:51:34 +01:00
Kristian Høgsberg
3fc0ec1bc3 evdev: Only init a pointer if the evdev device has a button
We used to test for abs | rel | button,  which inits a pointer device for
a device with just rel or abs capabilities.  We now make sure we have either
rel or abs as well as button.
2013-11-10 17:51:33 +01:00
Kristian Høgsberg
5d493ad6f4 evdev: Stop looking for pointer buttons when we get to BTN_JOYSTICK
We don't want to mark a touchscreen as a button device just because it
exposes the BTN_TOUCH and BTN_TOOL buttons.
2013-11-10 17:51:33 +01:00
Neil Roberts
ee5f763fc8 evdev: Process touch up events of single-touch devices
Previously only the touch up key event was used for single-touch
devices and the touch down event was generated on the first motion
event. This was breaking if the touch up and down events were sent
without a motion in-between because the evdev driver wouldn't generate
a touch down event and Weston would lose track of the number of touch
points that are down. This patch changes it to track the up and down
key events as pending events similar to how it does for multi-touch
devices.

https://bugs.freedesktop.org/show_bug.cgi?id=69759
2013-11-10 17:51:33 +01:00
Neil Roberts
96ec0936ca evdev: Only track one pending event
Instead of having a mask of pending events there is now an enum with a
single value to represent the one pending event. The event gets
flushed explicitly as part of the handling code for each event type
rather than in the outer event reading loop. The pending event is used
so that we can combine multiple motion events into one and to make
sure that we have recieved the latest position before sending a touch
up or down event. This should fix the following problems with the old
approach:

• If you release a finger and press it down again quickly you could
  get the up and down events in the same batch. However the pending
  events were always processed in the order down then up so it would
  end up notifying two down events and then an up. The pending event
  is now always flushed when there is a new up or down event so they
  will always be in the right order.

• When it got a slot event it would immediately change the slot number
  and then set the pending event. Then when it flushed the events it
  would use the new slot number to flush the old pending event so the
  events could have the wrong finger. The pending event is now
  immediately flushed when a slot event is received so it will have
  the right finger.

• If you get more than 32 events in one read then it was resetting the
  pending events before processing the next batch in
  evdev_process_events. If four fingers were pressed down at once then
  it ended up with more than 32 events and the sync message would be
  in the second batch. The pending flag for the last finger was
  getting cleared so it never got emitted. In this patch the pending
  event is no longer reset after reading nor is it explicitly flushed.
  Instead it is flushed when we receive a EV_SYN event or a different
  pending event needs to replace it.

The touchpad handling code was trying to use the pending event
mechanism to notify the relative motion events. I'm not sure why it
was doing this because it looks the event would effectively get
emitted as soon as the touchpad_process function is finished anyway
and it wasn't accumulating the values. Instead I've just changed it to
emit the event directly.

https://bugs.freedesktop.org/show_bug.cgi?id=67563
2013-11-10 17:51:33 +01:00
Neil Roberts
b3023f5d0a evdev: Flush motion events when the slot changes, not just after sync
If two fingers are released almost simultaneously then evdev can send
the touch up events in one bunch without sending a sync event
in-between. However, the evdev_device struct only keeps track of one
pending touch up event so in this case the second touch up event would
override the first and it would be lost. This patch changes it to also
flush the events whenever the slot changes so that it will flush the
previous touch up event before trying to queue the next one.

https://bugs.freedesktop.org/show_bug.cgi?id=67563
2013-11-10 17:51:33 +01:00
Hardening
6f96846e0a Rename current, origin, scale, origin_scale
This patch renames that fields to have consistent names.
2013-11-10 17:51:33 +01:00
Kristian Høgsberg
51e2c3f40e evdev: Don't transform device->abs.x/y in place
We don't always get both an X and an Y event in a SYN report, so we end
up transforming the coordinate we don't get twice.  For example, if we
only receive an ABS_X event, we transform the already transformed
device->abs.y again in transform_absolute() when applying the calibration.
2013-11-10 17:51:33 +01:00