Commit graph

116 commits

Author SHA1 Message Date
Jonas Ådahl
faab25c25c Make context reference counted
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>
2014-06-25 10:27:03 +10:00
Jonas Ådahl
13e9a1d744 Make ref count unref/ref() functions return resulting object pointer
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>
2014-06-25 10:26:59 +10:00
Peter Hutterer
97a6bf10f9 Change the logging system to be per-context
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>
2014-06-23 15:39:08 +10:00
Peter Hutterer
967911791f Rename KEYBOARD_KEY_STATE to KEY_STATE
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>
2014-06-23 15:23:35 +10:00
Peter Hutterer
41f9176c0a Add a function to get the size of a device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-06-19 13:38:15 +10:00
Peter Hutterer
21cf84a580 Change absolute and touch events to use mm as default unit
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>
2014-06-19 13:38:15 +10:00
Hans de Goede
4ddd19d6bd Add a log_msg_va function
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>
2014-06-11 10:31:43 +10:00
Hans de Goede
f638677051 Add a timer subsystem
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>
2014-06-10 20:55:18 +10:00
Stephen Chandler Paul
e912d620d0 s/libinput_pointer_button_state/libinput_button_state/
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>
2014-06-09 20:48:05 +02:00
Jonas Ådahl
f3084e2c0d Use floating point numbers instead of fixed point numbers
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>
2014-06-09 20:46:53 +02:00
Jonas Ådahl
604f22eb79 Introduce seat wide button and key count API
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>
2014-04-23 00:07:40 +02:00
Peter Hutterer
3ece227044 Add functions to convert back to the base event
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>
2014-04-10 11:11:56 +10:00
Jasper St. Pierre
385bfdb762 libinput: Fix the close_restricted interface callback
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>
2014-03-04 15:21:38 +10:00
Jonas Ådahl
6f0ca1a386 Split up the touch event into the different touch types
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>
2014-02-26 19:32:33 +01:00
Jonas Ådahl
e80cff7b0e Add seat wide slot to touch events
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>
2014-02-26 19:32:33 +01:00
Peter Hutterer
3a07b03df5 Add a customizable log handler
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>
2014-02-19 08:35:25 +10:00
Jonas Ådahl
e108e8ddba Change touch event slots from being unsigned to signed
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-02-17 20:12:19 +01:00
Jonas Ådahl
8dd059061b Fix coding style issues
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-02-17 20:12:19 +01:00
Jonas Ådahl
b34139c9e7 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>
2014-02-10 22:28:46 +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
82d5b54d9c Fix some coding style inconsistencies
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-25 11:33:09 +01:00
Jonas Ådahl
a93a0597c5 Remove redundant device pointer from device notify event
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-22 23:59:18 +01:00
Jonas Ådahl
78c2b71c23 Simplify device reference counting of events
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>
2014-01-22 23:58:45 +01:00
Peter Hutterer
2b4761b94a Drop event classes
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>
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
e99d362787 Provide accessors to retrieve the right event type
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>
2014-01-22 11:15:54 +10:00
Peter Hutterer
1ef6938257 zalloc all events to make sure we have defined defaults
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 11:15:22 +10:00
Peter Hutterer
39469df2fb Reduce touch events to a single event type
No real effect since we're hiding the actual touch events through the touch
type.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-01-22 10:51:45 +10:00
Peter Hutterer
040c25a4f4 Reduce pointer events to one single type
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>
2014-01-22 10:50:14 +10:00
Peter Hutterer
34013b8bfc Reduce keyboard events to one single type
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>
2014-01-22 10:50:06 +10:00
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