Commit graph

286 commits

Author SHA1 Message Date
Peter Hutterer
54db6527ae Improve namespacing of event types
Now that the target of an event isn't exposed to the caller anymore, the
namespacing can be associated with a more intuitive one.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-21 22:50:59 +01:00
Peter Hutterer
f98d427713 Merge the device added/removed events into a single device notify event
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-21 22:50:59 +01:00
Peter Hutterer
b569272a7a Drop libinput_event_get_target()
Replaced by specific accessor functions for context, seat and device. This
obsoletes the internal target as well, we just direcly ref the element we need
to instead of temporarily storing it in the target.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-21 22:50:58 +01:00
Peter Hutterer
60d46e6bd7 Add a generic libinput_event_get_device() function
After dropping seat evens, all events are now are associated with a device, so
provide a generic accessor function and drop the custom ones.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-21 22:50:58 +01:00
Peter Hutterer
c29a8e8093 Split seats into having a physical and a logical name
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-17 18:17:45 +10:00
Peter Hutterer
5b5b6bca06 Drop seat events
seats are more a compositor concept than a concept of the input library. All
devices in a libinput context are associated with the seat given on creation
of the seat (maps to ID_SEAT in udev for the udev backend).

A logical seat may be assigned to a device (e.g. WL_SEAT) but this does not
necessarily map to the creation of the seat in the compositor.
Drop the seat events but keep seat objects around so that the caller can still
identify which seat a device belongs to.

If the libinput_seat_unref() in the udev backend destroys the seat, the device
list of that seat is invalid and we'd be accessing already freed bytes. To
avoid this, ref the seat before the device removal loop, then unref it once
we're done - that unref then may trigger the actual removal of the seat.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-17 18:17:11 +10:00
Peter Hutterer
06453ba7a5 Add libinput_event_get_context()
Add a function to retrieve the libinput context from any event.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-16 20:55:23 +01:00
Peter Hutterer
8eac85e3fb Add libinput_next_event_type()
Returns the event type of the next event pending in the queue. For systems
that have the device init state separate from the actual event procesing
(read: xorg drivers) we need to be able to peek at the next event type to
check for the end of any initialization events (seat/device added) and the
beginning of actual device input events.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-10 11:23:57 +10:00
Peter Hutterer
90fa77908b Add LIBEVENT_EVENT_NONE
This event type is needed to notify callers that there is currently no
event waiting (in a follow-up patch). Also, it it avoids true/false
inconsistencies on event types (LIBINPUT_EVENT_ADDED_SEAT would otherwise be
the only FALSE event). While that's not technically necessary, it may prevent
the odd bug further down the road.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-10 11:18:43 +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
Peter Hutterer
3cf9cd9c86 Suspend libinput before destroying it
libinput_suspend() already causes the fds to be closed, devices and seats to
be removed, etc. Call it before libinput_destroy() to reduce the
backend-specific code.

No real functional change, the udev backend already did this anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-10 11:08:24 +10:00
Peter Hutterer
6fcaf7699c udev: Refcount the seat for each device
Use the seat's internal refcounting to up the reference each time we have a
device using it. This fixes the issue with seats being created but never
actually removed by anything.

udev_seat_get_named() will now return a seat with refcount 1 for a newly
created seat, or just up the refcount for the seat if it already exists.

This requires that the ADDED_SEAT and REMOVED_SEAT events up the refcount of
the seat as well: a device may be removed before the event is processed,
without the refcount the seat would be destroyed (if it's the last device on
the seat).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-10 11:08:21 +10:00
Peter Hutterer
1ee5b28c6e Abstract the backend interface away
Remove the fixed calls into the udev backend and provide a basic interface
instead that allows other backends to hook into device/seat creation. This
enables multiple backends, specifically a path-based backend that is needed
for X.Org drivers.

This patch should have no visible functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-09 11:13:53 +10:00
Peter Hutterer
cd6a65bf37 Drop the destroyed sources list on libinput_destroy()
==2772== 40 bytes in 1 blocks are definitely lost in loss record 3 of 4
==2772==    at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2772==    by 0x405EC7: libinput_add_fd (libinput.c:335)
==2772==    by 0x40B346: udev_input_enable (udev-seat.c:268)
==2772==    by 0x40B5E7: libinput_create_from_udev (udev-seat.c:369)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-08 20:45:58 +01:00
Peter Hutterer
4e67b6da39 Allow libinput_destroy() on a NULL pointer
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-08 20:45:58 +01:00
Peter Hutterer
ded615c64f Add two asserts to avoid underrunning the seat/device refcount
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-08 20:45:58 +01:00
Peter Hutterer
c0ac1ef9f2 Always allocate an event queue
On the typical setup we have at least 3 events pending as soon as we hook it
up (seat added, device added, capability). In the udev case we get up to > 64
events without even having input events on my laptop with only two extra
devices connected. So always allocate an event buffer to avoid spurious
resizing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-07 21:28:08 +01:00
Peter Hutterer
faee8fe1a7 Don't access event buffer after realloc
realloc() may free the original event buffer, don't access it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-07 21:27:30 +01:00
Jonas Ådahl
68619ec714 Destroy associated reference counted objects when destroying context
This avoids issues with device and seat objects depending on a valid
context.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-03 22:38:42 +01:00
Jonas Ådahl
e92b996cff Destroy unprocessed events properly when destroying context
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-03 22:32:59 +01:00
Jonas Ådahl
847ce34597 Don't return error when dispatching didn't queue any event
As reading from timers or evdev does not necessarily mean an input
event is queued and ready to be retrieved with libinput_get_event(),
don't report such behaviour as an error.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-03 22:31:04 +01:00
Jonas Ådahl
58a33bd51c Unref seats and devices in libinput_destroy()
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-16 22:52:05 +01:00
Peter Hutterer
c188943568 Allow for NULL in libevdev_event_destroy
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-15 21:07:03 +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
Jonas Ådahl
ef2deab618 Make even structs private
To ease the possibility to extend messages with more information, make
every event struct private, while providing functions used for accessing
the parameters previously found directly in the public structs.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-08 12:36:27 +01:00
Jonas Ådahl
758e553645 Reference count event target struct when applicable
If the target of an event is a reference counted object, such as
libinput_seat and libinput_device, make events own its own reference to
the object, releasing it when destroyed.

In order to do this, a new API requirement and function are introduced;
libinput_event_destroy(). The user is required to use
libinput_event_destroy() instead of free() after having retrieved an
event using libinput_get_event().

This fixes a race that would be triggered if a device or seat would be
added and removed before the user calling libinput_get_event().

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-07 16:41:43 +01:00
Jonas Ådahl
5836054306 Remove unused disabled code
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-07 16:01:17 +01:00
Peter Hutterer
3a3a0c87a7 libinput_dispatch: return -EAGAIN if no events are ready
Notify the caller that no events are currently ready to be processed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Peter Hutterer
f583cb7f6c libinput_dispatch: return negative error number on failure
Might as well tell the caller what went wrong without having to worry about
errno.
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
2e6e33bc48 Change API from using listeners to using an event queue
Instead of having the input drivers invoke user set callbacks during
libinput_device_dispatch() and add_fd callback, let the driver queue
events that the user then reads from using libinput_device_get_event().

A typical use case would be:

struct libinput_device *device = ...;
struct libinput_event *event;

libinput_device_dispatch(device);
while ((event = libinput_device_get_event(device))) {
	process_event(device, event);
	free(event);
}

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-17 17:01:49 +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