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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
==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>
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>
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>
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>
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>
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>
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>
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>
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>
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>