libevdev
1.3.2
A wrapper library for evdev devices
|
Initialization, initial setup and file descriptor handling. More...
Enumerations | |
enum | libevdev_grab_mode { LIBEVDEV_GRAB, LIBEVDEV_UNGRAB } |
Functions | |
struct libevdev * | libevdev_new (void) |
Initialize a new libevdev device. More... | |
int | libevdev_new_from_fd (int fd, struct libevdev **dev) |
Initialize a new libevdev device from the given fd. More... | |
void | libevdev_free (struct libevdev *dev) |
Clean up and free the libevdev struct. More... | |
int | libevdev_grab (struct libevdev *dev, enum libevdev_grab_mode grab) |
Grab or ungrab the device through a kernel EVIOCGRAB. More... | |
int | libevdev_set_fd (struct libevdev *dev, int fd) |
Set the fd for this struct and initialize internal data. More... | |
int | libevdev_change_fd (struct libevdev *dev, int fd) |
Change the fd for this device, without re-reading the actual device. More... | |
int | libevdev_get_fd (const struct libevdev *dev) |
Initialization, initial setup and file descriptor handling.
These functions are the main entry points for users of libevdev, usually a caller will use this series of calls:
libevdev_set_fd() is the central call and initializes the internal structs for the device at the given fd. libevdev functions will fail if called before libevdev_set_fd() unless documented otherwise.
enum libevdev_grab_mode |
int libevdev_change_fd | ( | struct libevdev * | dev, |
int | fd | ||
) |
Change the fd for this device, without re-reading the actual device.
If the fd changes after initializing the device, for example after a VT-switch in the X.org X server, this function updates the internal fd to the newly opened. No check is made that new fd points to the same device. If the device has changed, libevdev's behavior is undefined.
libevdev does not sync itself after changing the fd and keeps the current device state. Use libevdev_next_event with the LIBEVDEV_READ_FLAG_FORCE_SYNC flag to force a re-sync.
The example code below illustrates how to force a re-sync of the library-internal state. Note that this code doesn't handle the events in the caller, it merely forces an update of the internal library state.
The fd may be open in O_RDONLY or O_RDWR.
It is an error to call this function before calling libevdev_set_fd().
dev | The evdev device, already initialized with libevdev_set_fd() |
fd | The new fd |
void libevdev_free | ( | struct libevdev * | dev | ) |
Clean up and free the libevdev struct.
After completion, the struct libevdev
is invalid and must not be used.
dev | The evdev device |
int libevdev_get_fd | ( | const struct libevdev * | dev | ) |
dev | The evdev device |
int libevdev_grab | ( | struct libevdev * | dev, |
enum libevdev_grab_mode | grab | ||
) |
Grab or ungrab the device through a kernel EVIOCGRAB.
This prevents other clients (including kernel-internal ones such as rfkill) from receiving events from this device.
This is generally a bad idea. Don't do this.
Grabbing an already grabbed device, or ungrabbing an ungrabbed device is a noop and always succeeds.
dev | The evdev device, already initialized with libevdev_set_fd() |
grab | If true, grab the device. Otherwise ungrab the device. |
struct libevdev* libevdev_new | ( | void | ) |
Initialize a new libevdev device.
This function only allocates the required memory and initializes the struct to sane default values. To actually hook up the device to a kernel device, use libevdev_set_fd().
Memory allocated through libevdev_new() must be released by the caller with libevdev_free().
int libevdev_new_from_fd | ( | int | fd, |
struct libevdev ** | dev | ||
) |
Initialize a new libevdev device from the given fd.
This is a shortcut for
fd | A file descriptor to the device in O_RDWR or O_RDONLY mode. | |
[out] | dev | The newly initialized evdev device. |
int libevdev_set_fd | ( | struct libevdev * | dev, |
int | fd | ||
) |
Set the fd for this struct and initialize internal data.
The fd must be in O_RDONLY or O_RDWR mode.
This function may only be called once per device. If the device changed and you need to re-read a device, use libevdev_free() and libevdev_new(). If you need to change the fd after closing and re-opening the same device, use libevdev_change_fd().
Unless otherwise specified, libevdev function behavior is undefined until a successfull call to libevdev_set_fd().
dev | The evdev device |
fd | The file descriptor for the device |