Instead of only allowing one owner keeping a libinput context alive,
make context reference counted, replacing libinput_destroy() with
libinput_unref() while adding another function libinput_ref().
Even though there might not be any current use cases, it doesn't mean we
should hard code this usage model in the API. The old behaviour can be
emulated by never calling libinput_ref() while replacing
libinput_destroy() with libinput_unref().
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
In order to know if an unref() destroyed an object and to allow more
convenient use of ref(), make both functions return a pointer to the
object it was passed, or NULL if that object was destroyed.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Rather than a single global logging function, make the logging dependent on
the individual context. This way we won't stomp on each other's feet in the
(admittedly unusual) case of having multiple libinput contexts.
The userdata argument to the log handler was dropped. The caller has a ref to
the libinput context now, any userdata can be attached to that context
instead.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
e912d620d0 changed from POINTER_BUTTON_STATE to
simply BUTTON_STATE, replicate that for key events too.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Instead of device-specific coordinates that the caller can't interpret without
knowing the range anyway, return mm as the default value.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This is useful for when we use libraries which want us to provide them with
a logging callback.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Currently we are using DIY timers in the touchpad softbutton and tap handling
code, and at least the softbutton code gets its wrong. It uses one timer-fd
per touchpad to set a timeout per touch, which means that if a timeout is
set for 100ms from now for touch 1, and then 50 ms later touch 2 sets a timeout
for 200 ms from now, then the timeout for touch 1 will come 150 ms too late.
This commits adds a proper timer subsystem so that we've one place to deal
with timer handling, and so that we can only get it wrong (well hopefully
we get it right) in one place.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Button states are applicable to more then just the pointer, so having a
non-generic name name for a generic enumerator value like
libinput_pointer_button_state doesn't make sense. Changing it to something
generic like libinput_button_state allows it to be reused by other devices that
may potentially be added to libinput in the future.
Signed-off-by: Stephen Chandler Paul <thatslyude@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Fixed point numbers can easily overflow, and double to fixed point
conversion is lossy. Use floating point (double) where fixed point
numbers where previously used and remove the li_fixed_t type.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Compositors will need to keep provide virtual devices of supported
generic device types (pointer, keyboard, touch etc). Events from each
device capable of a certain device type abstraction should be combined
as if it was only one device.
For key and button events this means counting presses of every key or
button. With this patch, libinput provides two new API for doing just
this; libinput_event_pointer_get_seat_button_count() and
libinput_event_keyboard_get_seat_key_count().
With these functions, a compositor can sort out what key or button events
that should be ignored for a virtual device. This could for example
look like:
event = libinput_get_event(libinput);
switch (libinput_event_get_type(event)) {
...
case LIBINPUT_EVENT_POINTER_BUTTON:
device = libinput_event_get_device(event);
seat = libinput_event_get_seat(device);
pevent = libinput_event_get_pointer_event(event);
if (libinput_event_pointer_get_button_state(pevent) &&
libinput_event_pointer_get_seat_button_count(pevent) == 1)
notify_pointer_button_press(seat);
else if (libinput_event_pointer_get_button_state(pevent) &&
libinput_event_pointer_get_seat_button_count(pevent) == 0)
notify_pointer_button_release(seat);
break;
...
}
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
A few functions only work on the base event but once we've converted to the
target event we can't go back. Casting works for now but that would expose
internal ABI.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
libinput is supposed to take a close callback in its interface
to allow you to call out to a privileged API to close FDs. But
the FD that libinput passes you is bogus, because
libinput_remove_source closes the FD on which it's passed. This
is really bad, as the libinput_source really doesn't own the FD
which it's passed, so it shouldn't be trying to close() it.
Only one out of the four users of libinput_remove_source actually
wants their FD closed, so move the close() call there.
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Instead of having one touch events representing different types of touch
events by providing a touch type, have one separate event type per touch
type. This means the LIBINPUT_EVENT_TYPE_TOUCH is replaced with
LIBINPUT_EVENT_TYPE_TOUCH_DOWN, LIBINPUT_EVENT_TYPE_TOUCH_MOTION,
LIBINPUT_EVENT_TYPE_TOUCH_UP and LIBINPUT_EVENT_TYPE_TOUCH_CANCEL.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Since a Wayland compositor have to represent all touch devices of a seat
as one virtual device, lets make that easier by also providing seat wide
slots with touch events.
Seat wide slots may be accessed using
libinput_event_touch_get_seat_slot().
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
The previous log handler wasn't actually hooked up to anything. Add a public
API for the log handler with priority filtering, defaulting to priority
'error' and stderr as output stream.
And to keep the diff down and convenience up, provide a few simple wrappers
for logging. The generic is log_msg(), but let's use log_info, log_error, etc.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
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>
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>
This also makes DEVICE_ADDED/REMOVED events own a reference, which is
necessary to not have libinput_event_get_device() potentially returning
an invalid pointer.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
There are now only two event classes and only two users of the event class.
It's easier to use the event type directly to see which event has references
and which one doesn't.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
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>
Slightly enhances the type-safety. A caller may now do something along the
lines of
struct libinput_event_pointer *ptrev;
ptrev = libinput_event_get_pointer_event(event);
if (!ptrev)
oops, that wasn't a pointer event
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
The event type itself says enough about the actual event type, we don't need
to have separate structs for every type.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Provide one top-level event for keyboard events: libinput_event_keyboard. The
event type specifies which subtype the event is anyway.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
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>