libevdev
0.4
A wrapper library for evdev devices
|
libevdev is a library for handling evdev kernel devices. It abstracts the ioctls through type-safe interfaces and provides functions to change the appearance of the device.
Development of libevdev is discussed on input-tools@lists.freedesktop.org Please submit patches, questions or general comments there.
libevdev provides an interface for handling events, including most notably SYN_DROPPED events. SYN_DROPPED events are sent by the kernel when the process does not read events fast enough and the kernel is forced to drop some events. This causes the device to get out of sync with the process' view of it. libevdev handles this by telling the caller that a SYN_DROPPED has been received and that the state of the device is different to what is to be expected. It then provides the delta between the previous state and the actual state of the device as a set of events. See libevdev_next_event() for more information.
libevdev is signal-safe for the majority of its operations. Check the API documentation to make sure, unless explicitly stated a call is not signal safe.
libevdev does not attempt duplicate detection. Initializing two libevdev devices for the same fd is valid and behaves the same as for two different devices.
libevdev does not handle the file descriptors directly, it merely uses them. The caller is responsible for opening the file descriptors, setting them to O_NONBLOCK and handling permissions.
libevdev is essentially a read(2)
on steroids for `/dev/input/eventX devices. It sits below the process that handles input events, in between the kernel and that process. In the simplest case, e.g. an evtest-like tool the stack would look like this:
kernel → libevdev → evtest
For X.Org input modules, the stack would look like this:
kernel → libevdev → xf86-input-evdev → X server → X client
For Weston/Wayland, the stack would look like this:
kernel → libevdev → Weston → Wayland client
libevdev does not have knowledge of X clients or Wayland clients, it is too low in the stack.
Below is a simple example that shows how libevdev could be used. This example opens a device, checks for relative axes and a left mouse button and if it finds them monitors the device to print the event.
A more complete example is available with the libevdev-events tool here: http://cgit.freedesktop.org/libevdev/tree/tools/libevdev-events.c
libevdev's internal test suite uses the Check unit testing framework. Tests are divided into test suites and test cases. Most tests create a uinput device, so you'll need to run as root.
To run a specific suite only:
export CK_RUN_SUITE="suite name"
To run a specific test case only:
export CK_RUN_TEST="test case name"
To get a list of all suites or tests:
git grep "suite_create" git grep "tcase_create"
By default, check forks, making debugging harder. Run gdb as below to avoid forking.
sudo CK_FORK=no CK_RUN_TEST="test case name" gdb ./test/test-libevdev
A special target make gcov-report.txt
exists that runs gcov and leaves a libevdev.c.gcov
file. Check that for test coverage.
make check
is hooked up to run the test and gcov (again, needs root).
The test suite creates a lot of devices, very quickly. Add the following xorg.conf.d snippet to avoid the devices being added as X devices (at the time of writing, mutter can't handle these devices and exits after getting a BadDevice error).
$ cat /etc/X11/xorg.conf.d/99-ignore-libevdev-devices.conf Section "InputClass" Identifier "Ignore libevdev test devices" MatchProduct "libevdev test device" Option "Ignore" "on" EndSection
libevdev is licensed under the X11 license.
Please report bugs in the freedesktop.org bugzilla under the libevdev product: https://bugs.freedesktop.org/enter_bug.cgi?product=libevdev