Commit graph

116 commits

Author SHA1 Message Date
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