Commit graph

399 commits

Author SHA1 Message Date
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
Jonas Ådahl
caf19d5968 doc: Clarify that the caller need to free retrieved event
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-07 14:06:55 +01:00
Peter Hutterer
2d2df7842c doc: hook up doxygen to generate the public API documentation
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-07 14:06:46 +01:00
Peter Hutterer
075119dd5a Rename libinput_create_udev to libinput_create_from_udev
A lot more obvious what it does, it creates a libinput context from a udev
handler (rather than creating the udev handler).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-07 13:55:37 +01:00
Peter Hutterer
d50c5108c1 udev-seat: fix leak when failing to add devices
udev-monitor and the udev_monitor_source would leak.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-07 13:55:31 +01:00
Peter Hutterer
7b09c753de Drop include of evdev.h from evdev.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Peter Hutterer
c06804b643 Drop unused libinput_fd_handle and libinput_fd_callback
Obsolete with ce787552bc

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Peter Hutterer
9e6cf91f48 evdev: fix memcopy for calibration
Function arguments with fixed length are still just pointers, so
sizeof(calibration) here is sizeof(float*), not sizeof(float) * 6.

evdev.c: In function 'evdev_device_calibrate':
evdev.c:693:54: warning: argument to 'sizeof' in 'memcpy' call is the same
  pointer type 'float *' as the destination; expected 'float' or an explicit
  length [-Wsizeof-pointer-memaccess]
  memcpy(device->abs.calibration, calibration, sizeof calibration);

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Peter Hutterer
adf859c2e9 Move libinput, libinput_seat and libinput_device to the top
Declare all three before they are used.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10:00
Peter Hutterer
8999445894 Declare libinput_seat explicitly
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:16 +10: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
Peter Hutterer
2aec703c2e Make the slots unsigned, the kernel guarantees a base of 0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:12 +10:00
Peter Hutterer
74955e0b95 Make buttons unsigned, there are no negative button numbers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-12-06 13:52:07 +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
c0af815eae util: Add logging utilities
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 12:55:44 +01:00
Jonas Ådahl
97a277a9f0 Merge branch 'master' into udev 2013-11-19 22:29:38 +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
8f8fdc85b1 src/Makefile.a: Fix whitespace
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-17 17:01:58 +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
David Herrmann
facf1dd264 launcher: add weston_launcher_close() dummy
If you request a device via weston_launcher_open(), you should now release
it via weston_launcher_close() instead of close(). This is currently not
needed but will be required for logind devices.
2013-11-16 21:54:07 +01:00
Jonas Ådahl
d26428475a udev-seat: Repick seat after a new device was added
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-16 21:54:07 +01:00
Kristian Høgsberg
0b0c842a09 launcher: Collect launcher state in new struct weston_launcher
We're going to add a bit more launcher state, so start out by creating
a new struct weston_launcher we can track it in.
2013-11-16 21:54:07 +01:00
Daniel Stone
1605e9ab19 Add more missing config.h includes
config.h includes were missing in a few files, including input.c, the
lack of which caused the X11 backend to segfault instantly due to not
having an xkbcommon context.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-11-16 21:54:07 +01:00
Peter Hutterer
3cb516930f malloc + memset -> zalloc
And for clients using the xmalloc helper, use xzalloc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-11-16 21:54:07 +01:00
Kristian Høgsberg
71d66e22e5 udev: Use WL_OUTPUT udev attribute for pairing touchscreens to outputs 2013-11-16 21:54:07 +01:00
Rob Bradford
dcaca098f8 compositor-drm: Enable seat constraining when configured in weston.ini
This change tweaks weston_pointer_clamp to take into consideration if a
seat is constrained to a particular output by only considering the
pointer position valid if it is within the output we a constrained to.
This function is also used for the initial warping of the pointer when a
constraint is first established.

The other two changes are the application of the constraint when either
a new device added or a new output created and therefore outputs and
input devices can be brought up in either order.

v2: the code in create_output_for_connector has been spun off into a
new function setup_output_seat_constraint (Ander). The inappropriate
warping behaviour has been resolved by using weston_pointer_clamp
(Pekka).
2013-11-16 21:54:07 +01:00
Rob Bradford
e2da4d888c udev-seat: Refactor out seat lookup and possible creation
This change spills the code for looking up a seat by name and then
potentially creating it if it doesn't exist into a new function called
udev_seat_get_named.

This change allows us to reuse this code when looking up the seat
when parsing seat constraints per output.
2013-11-16 21:54:07 +01:00
Daniel Stone
0a375ebb38 configure.ac: Enable AC_USE_SYSTEM_EXTENSIONS
AC_USE_SYSTEM_EXTENSIONS enables _XOPEN_SOURCE, _GNU_SOURCE and similar
macros to expose the largest extent of functionality supported by the
underlying system.  This is required since these macros are often
limiting rather than merely additive, e.g. _XOPEN_SOURCE will actually
on some systems hide declarations which are not part of the X/Open spec.

Since this goes into config.h rather than the command line, ensure all
source is consistently including config.h before anything else,
including system libraries.  This doesn't need to be guarded by a
HAVE_CONFIG_H ifdef, which was only ever a hangover from the X.Org
modular transition.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>

[pq: rebased and converted more files]
2013-11-16 21:54:06 +01:00
Rob Bradford
cb408b3acf udev-seat: Use udev rules to support multiple seats
By labelling devices with ENV{WL_SEAT} in udev rules the devices will be
pulled into multiple weston seats.

As a result you can get multiple independent seats under the DRM and
fbdev backends.
2013-11-16 21:54:06 +01:00
Rob Bradford
07b0da9c77 udev-seat: Separate the seat out to its own structure
Thie will allow us to instantiate multiple seats.
2013-11-16 21:54:06 +01:00
Rob Bradford
8065462d6d udev-seat: Make the udev_input structure an embedded structure
And as a result of this stop iterating through the compositor seat list
(of one item) and instead access the udev_input structure directly.

This enables a refactoring to pull out the weston_seat into a separate
structure permitting multiple seats.
2013-11-16 21:54:06 +01:00
Rob Bradford
a16790bcd7 udev-seat: Rename udev_seat to udev_input
This is a pure rename of the structure, functions and local variables in
preparation of the separation of the seat from the other udev input
handling.
2013-11-16 21:54:06 +01:00
Rob Bradford
56ed9258da input: Add a seat name parameter to weston_seat_init 2013-11-16 21:54:06 +01:00
Rob Bradford
a777610a77 udev-seat: Fail input setup only if no devices are found
Rather than failing if we cannot open any single device fail the input
setup if there are no input devices added.

https://bugs.freedesktop.org/show_bug.cgi?id=64506
2013-11-16 21:54:06 +01:00
Kristian Høgsberg
790c9a1faf input: Merge wl_seat into weston_seat 2013-11-16 21:54:06 +01:00
Kristian Høgsberg
43ff34cdae udev-seat: Simplfy enable/disable interface a bit
We always call enable_udev_monitor and add_devices together and always
disable_udev_monitor and remove_devices together.  Let's just have one
entry point for enable and one for disable.
2013-11-16 21:54:06 +01:00
Kristian Høgsberg
0b6adcd5e4 compositor-drm: Move udev_seat to its own file
We get to move the input code out of compositor-drm.c and we'll be
able to share it with the fbdev backend.
2013-11-16 21:54:06 +01:00
Jonas Ådahl
79d77d4b8b Don't use the `seat' concept on device capability enum
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-13 22:11:34 +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
Jonas Ådahl
fdf50bc34b filter: Remove unused variable
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-12 21:56:37 +01:00
Jonas Ådahl
75f453df6a evdev: Synchronize keys only if seat is keyboard capable
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
Jonas Ådahl
098ca89e17 Make weston_output_transform_coordinate() take wl_fixed_t coordinates
This is to make it possible for future API to have non-integer
coordinates as input.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
Kristian Høgsberg
077e0c937a compositor: Remove redundant and not well-defined focus field
It was never clear what this field really did.
2013-11-10 17:51:34 +01:00
Jonas Ådahl
c442b9fd60 evdev: Reference count input device's seat capabilities
When the only input device of a certain seat capability is unplugged,
stop advertising the capability.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-10 17:51:34 +01:00
David Herrmann
b98d0b9d89 evdev: release devices on read() error
If read() fails without EAGAIN/EINTR, the device is very likely dead.
However, we must not remove the device as it might be muted/revoked. So we
simply remove the event-source to avoid polling the device and simply wait
for the udev-remove signal now.

Note that we cannot call evdev_device_destroy() as the caller created the
FD and might need custom code to close it (like weston_launcher_close()).
2013-11-10 17:51:34 +01:00
Kristian Høgsberg
d4c9c6b83b evdev: Clear touch capability if we see a mouse-type button
If an input device has BTN_LEFT (typically) it's not a touch screen but
a touch pad.
2013-11-10 17:51:34 +01:00