libevdev
0.5
A wrapper library for evdev devices
|
Creation of uinput devices based on existing libevdev devices. More...
Functions | |
int | libevdev_uinput_create_from_device (const struct libevdev *dev, int uinput_fd, struct libevdev_uinput **uinput_dev) |
Create a uinput device based on the libevdev device given. More... | |
void | libevdev_uinput_destroy (struct libevdev_uinput *uinput_dev) |
Destroy a previously created uinput device and free associated memory. More... | |
int | libevdev_uinput_get_fd (const struct libevdev_uinput *uinput_dev) |
Return the file descriptor used to create this uinput device. More... | |
const char * | libevdev_uinput_get_syspath (struct libevdev_uinput *uinput_dev) |
Return the syspath representing this uinput device. More... | |
const char * | libevdev_uinput_get_devnode (struct libevdev_uinput *uinput_dev) |
Return the device node representing this uinput device. More... | |
int | libevdev_uinput_write_event (const struct libevdev_uinput *uinput_dev, unsigned int type, unsigned int code, int value) |
Post an event through the uinput device. More... | |
Creation of uinput devices based on existing libevdev devices.
These functions help to create uinput devices that emulate libevdev devices. In the simplest form it serves to duplicate an existing device:
Alternatively, a device can be constructed from scratch:
int libevdev_uinput_create_from_device | ( | const struct libevdev * | dev, |
int | uinput_fd, | ||
struct libevdev_uinput ** | uinput_dev | ||
) |
Create a uinput device based on the libevdev device given.
The uinput device will be an exact copy of the libevdev device, minus the bits that uinput doesn't allow to be set.
If uinput_fd is LIBEVDEV_UINPUT_OPEN_MANAGED, libevdev_uinput_create_from_device() will open /dev/uinput
in read/write mode and manage the file descriptor. Otherwise, uinput_fd must be opened by the caller and opened with the appropriate permissions.
The device's lifetime is tied to the uinput file descriptor, closing it will destroy the uinput device. You should call libevdev_uinput_destroy() before closing the file descriptor to free allocated resources. A file descriptor can only create one uinput device at a time; the second device will fail with -EINVAL.
You don't need to keep the file descriptor variable around, libevdev_uinput_get_fd() will return it when needed.
dev | The device to duplicate | |
uinput_fd | LIBEVDEV_UINPUT_OPEN_MANAGED or a file descriptor to /dev/uinput , | |
[out] | uinput_dev | The newly created libevdev device. |
void libevdev_uinput_destroy | ( | struct libevdev_uinput * | uinput_dev | ) |
Destroy a previously created uinput device and free associated memory.
If the device was opened with LIBEVDEV_UINPUT_OPEN_MANAGED, libevdev_uinput_destroy() also closes the file descriptor. Otherwise, the fd is left as-is and must be closed by the caller.
uinput_dev | A previously created uinput device. |
const char* libevdev_uinput_get_devnode | ( | struct libevdev_uinput * | uinput_dev | ) |
Return the device node representing this uinput device.
This relies on libevdev_uinput_get_syspath() to provide a valid syspath. See libevdev_uinput_get_syspath() for more details.
uinput_dev | A previously created uinput device. |
int libevdev_uinput_get_fd | ( | const struct libevdev_uinput * | uinput_dev | ) |
Return the file descriptor used to create this uinput device.
This is the fd pointing to /dev/uinput. This file descriptor may be used to write events that are emitted by the uinput device. Closing this file descriptor will destroy the uinput device, you should call libevdev_uinput_destroy() first to free allocated resources.
uinput_dev | A previously created uinput device. |
const char* libevdev_uinput_get_syspath | ( | struct libevdev_uinput * | uinput_dev | ) |
Return the syspath representing this uinput device.
As of 3.11, the uinput kernel device does not provide a way to get the syspath directly through uinput so libevdev must guess. In some cases libevdev is unable to derive the syspath. If the running kernel supports the UI_GET_SYSPATH ioctl, the syspath is retrieved through that and will be reliable and not be NULL.
uinput_dev | A previously created uinput device. |
int libevdev_uinput_write_event | ( | const struct libevdev_uinput * | uinput_dev, |
unsigned int | type, | ||
unsigned int | code, | ||
int | value | ||
) |
Post an event through the uinput device.
It is the caller's responsibility that any event sequence is terminated with an EV_SYN/SYN_REPORT/0 event. Otherwise, listeners on the device node will not see the events until the next EV_SYN event is posted.
uinput_dev | A previously created uinput device. |
type | Event type (EV_ABS, EV_REL, etc.) |
code | Event code (ABS_X, REL_Y, etc.) |
value | The event value |