libevdev  0.4
A wrapper library for evdev devices
 All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Typedefs | Enumerations | Functions
Initialization and setup

Initialization, initial setup and file descriptor handling. More...

Typedefs

typedef void(* libevdev_log_func_t )(enum libevdev_log_priority priority, void *data, const char *file, int line, const char *func, const char *format, va_list args)
 Logging function called by library-internal logging. More...
 

Enumerations

enum  libevdev_log_priority { LIBEVDEV_LOG_ERROR, LIBEVDEV_LOG_INFO, LIBEVDEV_LOG_DEBUG }
 
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...
 
void libevdev_set_log_function (libevdev_log_func_t logfunc, void *data)
 Set a printf-style logging handler for library-internal logging. More...
 
void libevdev_set_log_priority (enum libevdev_log_priority priority)
 Define the minimum level to be printed to the log handler. More...
 
enum libevdev_log_priority libevdev_get_log_priority (void)
 
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)
 

Detailed Description

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:

struct libevdev *dev;
int err;
dev = libevdev_new();
if (!dev)
return ENOMEM;
err = libevdev_set_fd(dev, fd);
if (err < 0) {
printf("Failed (errno %d): %s\n", -err, strerror(-err));

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.

Typedef Documentation

typedef void(* libevdev_log_func_t)(enum libevdev_log_priority priority, void *data, const char *file, int line, const char *func, const char *format, va_list args)

Logging function called by library-internal logging.

This function is expected to treat its input like printf would.

Parameters
priorityLog priority of this message
dataUser-supplied data pointer (see libevdev_set_log_function())
filelibevdev source code file generating this message
linelibevdev source code line generating this message
funclibevdev source code function generating this message
formatprintf-style format string
argsList of arguments
See Also
libevdev_set_log_function

Enumeration Type Documentation

Enumerator
LIBEVDEV_GRAB 

Grab the device if not currently grabbed.

LIBEVDEV_UNGRAB 

Ungrab the device if currently grabbed.

Enumerator
LIBEVDEV_LOG_ERROR 

critical errors and application bugs

LIBEVDEV_LOG_INFO 

informational messages

LIBEVDEV_LOG_DEBUG 

debug information

Function Documentation

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.

The fd may be open in O_RDONLY or O_RDWR.

It is an error to call this function before calling libevdev_set_fd().

Parameters
devThe evdev device, already initialized with libevdev_set_fd()
fdThe new fd
Returns
0 on success, or -1 on failure.
See Also
libevdev_set_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.

Parameters
devThe evdev device
Note
This function may be called before libevdev_set_fd().
int libevdev_get_fd ( const struct libevdev *  dev)
Parameters
devThe evdev device
Returns
The previously set fd, or -1 if none had been set previously.
Note
This function may be called before libevdev_set_fd().
enum libevdev_log_priority libevdev_get_log_priority ( void  )
Returns
the current log level
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.

Parameters
devThe evdev device, already initialized with libevdev_set_fd()
grabIf true, grab the device. Otherwise ungrab the device.
Returns
0 if the device was successfull grabbed or ungrabbed, or a negative errno in case of failure.
struct libevdev* libevdev_new ( void  )
read

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().

See Also
libevdev_set_fd
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

int err;
struct libevdev *dev = libevdev_new();
err = libevdev_set_fd(dev, fd);
Parameters
fdA file descriptor to the device in O_RDWR or O_RDONLY mode.
[out]devThe newly initialized evdev device.
Returns
On success, zero is returned and dev is set to the newly allocated struct. On failure, a negative errno is returned and the value of dev is undefined.
See Also
libevdev_free
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().

Parameters
devThe evdev device
fdThe file descriptor for the device
Returns
0 on success, or a negative error code on failure
See Also
libevdev_change_fd
libevdev_new
libevdev_free
void libevdev_set_log_function ( libevdev_log_func_t  logfunc,
void *  data 
)

Set a printf-style logging handler for library-internal logging.

The default logging function is to stdout.

Parameters
logfuncThe logging function for this device. If NULL, the current logging function is unset and no logging is performed.
dataUser-specific data passed to the log handler.
Note
This function may be called before libevdev_set_fd().
void libevdev_set_log_priority ( enum libevdev_log_priority  priority)

Define the minimum level to be printed to the log handler.

Messages higher than this level are printed, others are discarded. This is a global setting and applies to any future logging messages.

Parameters
priorityMinimum priority to be printed to the log.