libevdev.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission. The copyright holders make no representations
11  * about the suitability of this software for any purpose. It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22 
23 #ifndef LIBEVDEV_H
24 #define LIBEVDEV_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <linux/input.h>
31 #include <stdarg.h>
32 
33 #define LIBEVDEV_ATTRIBUTE_PRINTF(_format, _args) __attribute__ ((format (printf, _format, _args)))
34 
752 struct libevdev;
753 
763 };
764 
779 struct libevdev* libevdev_new(void);
780 
803 int libevdev_new_from_fd(int fd, struct libevdev **dev);
804 
818 void libevdev_free(struct libevdev *dev);
819 
826  LIBEVDEV_LOG_DEBUG = 30
827 };
828 
845 typedef void (*libevdev_log_func_t)(enum libevdev_log_priority priority,
846  void *data,
847  const char *file, int line,
848  const char *func,
849  const char *format, va_list args)
851 
871 
885 
898 
918 typedef void (*libevdev_device_log_func_t)(const struct libevdev *dev,
919  enum libevdev_log_priority priority,
920  void *data,
921  const char *file, int line,
922  const char *func,
923  const char *format, va_list args)
925 
947 void libevdev_set_device_log_function(struct libevdev *dev,
949  enum libevdev_log_priority priority,
950  void *data);
951 
957  LIBEVDEV_UNGRAB = 4
958 };
959 
982 int libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab);
983 
1016 int libevdev_set_fd(struct libevdev* dev, int fd);
1017 
1056 int libevdev_change_fd(struct libevdev* dev, int fd);
1057 
1066 int libevdev_get_fd(const struct libevdev* dev);
1067 
1088 };
1089 
1140 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev);
1141 
1164 int libevdev_has_event_pending(struct libevdev *dev);
1165 
1180 const char* libevdev_get_name(const struct libevdev *dev);
1181 
1195 void libevdev_set_name(struct libevdev *dev, const char *name);
1196 
1212 const char * libevdev_get_phys(const struct libevdev *dev);
1213 
1227 void libevdev_set_phys(struct libevdev *dev, const char *phys);
1228 
1242 const char * libevdev_get_uniq(const struct libevdev *dev);
1243 
1257 void libevdev_set_uniq(struct libevdev *dev, const char *uniq);
1258 
1268 int libevdev_get_id_product(const struct libevdev *dev);
1269 
1281 void libevdev_set_id_product(struct libevdev *dev, int product_id);
1282 
1292 int libevdev_get_id_vendor(const struct libevdev *dev);
1293 
1305 void libevdev_set_id_vendor(struct libevdev *dev, int vendor_id);
1306 
1316 int libevdev_get_id_bustype(const struct libevdev *dev);
1317 
1329 void libevdev_set_id_bustype(struct libevdev *dev, int bustype);
1330 
1340 int libevdev_get_id_version(const struct libevdev *dev);
1341 
1353 void libevdev_set_id_version(struct libevdev *dev, int version);
1354 
1364 int libevdev_get_driver_version(const struct libevdev *dev);
1365 
1376 int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
1377 
1389 int libevdev_enable_property(struct libevdev *dev, unsigned int prop);
1390 
1399 int libevdev_disable_property(struct libevdev *dev, unsigned int prop);
1400 
1411 int libevdev_has_event_type(const struct libevdev *dev, unsigned int type);
1412 
1424 int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code);
1425 
1438 int libevdev_get_abs_minimum(const struct libevdev *dev, unsigned int code);
1439 
1452 int libevdev_get_abs_maximum(const struct libevdev *dev, unsigned int code);
1453 
1466 int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code);
1467 
1480 int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code);
1481 
1494 int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code);
1495 
1509 const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, unsigned int code);
1510 
1533 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
1534 
1569 int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value);
1570 
1596 int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value);
1597 
1618 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
1619 
1648 int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value);
1649 
1675 int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value);
1676 
1690 int libevdev_get_num_slots(const struct libevdev *dev);
1691 
1707 int libevdev_get_current_slot(const struct libevdev *dev);
1708 
1720 void libevdev_set_abs_minimum(struct libevdev *dev, unsigned int code, int val);
1721 
1733 void libevdev_set_abs_maximum(struct libevdev *dev, unsigned int code, int val);
1734 
1746 void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int val);
1747 
1759 void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int val);
1760 
1772 void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int val);
1773 
1785 void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1786 
1804 int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
1805 
1832 int libevdev_disable_event_type(struct libevdev *dev, unsigned int type);
1833 
1867 int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data);
1868 
1896 int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code);
1897 
1912 int libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1913 
1919  LIBEVDEV_LED_OFF = 4
1920 };
1921 
1935 int libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value);
1936 
1960 int libevdev_kernel_set_led_values(struct libevdev *dev, ...);
1961 
1976 int libevdev_set_clock_id(struct libevdev *dev, int clockid);
1977 
1999 int libevdev_event_is_type(const struct input_event *ev, unsigned int type);
2000 
2024 int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code);
2025 
2037 const char * libevdev_event_type_get_name(unsigned int type);
2050 const char * libevdev_event_code_get_name(unsigned int type, unsigned int code);
2051 
2072 const char * libevdev_event_value_get_name(unsigned int type,
2073  unsigned int code,
2074  int value);
2088 const char* libevdev_property_get_name(unsigned int prop);
2089 
2102 int libevdev_event_type_get_max(unsigned int type);
2103 
2118 int libevdev_event_type_from_name(const char *name);
2119 
2136 int libevdev_event_type_from_name_n(const char *name, size_t len);
2137 
2157 int libevdev_event_code_from_name(unsigned int type, const char *name);
2158 
2180 int libevdev_event_code_from_name_n(unsigned int type, const char *name,
2181  size_t len);
2182 
2204 int libevdev_event_value_from_name(unsigned int type, unsigned int code,
2205  const char *name);
2206 
2223 int
2225 
2244 int
2245 libevdev_event_type_from_code_name_n(const char *name, size_t len);
2246 
2263 int
2265 
2284 int
2285 libevdev_event_code_from_code_name_n(const char *name, size_t len);
2286 
2310 int libevdev_event_value_from_name_n(unsigned int type, unsigned int code,
2311  const char *name, size_t len);
2312 
2325 int libevdev_property_from_name(const char *name);
2326 
2341 int libevdev_property_from_name_n(const char *name, size_t len);
2342 
2360 int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period);
2361 
2362 /********* DEPRECATED SECTION *********/
2363 #if defined(__GNUC__) && __GNUC__ >= 4
2364 #define LIBEVDEV_DEPRECATED __attribute__ ((deprecated))
2365 #else
2366 #define LIBEVDEV_DEPRECATED
2367 #endif
2368 
2369 #ifdef __cplusplus
2370 }
2371 #endif
2372 
2373 #endif /* LIBEVDEV_H */
void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int val)
Change the resolution for the given EV_ABS event code, if the code exists.
@ LIBEVDEV_UNGRAB
Ungrab the device if currently grabbed.
Definition: libevdev.h:957
int libevdev_event_type_get_max(unsigned int type)
int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code)
int libevdev_event_value_from_name_n(unsigned int type, unsigned int code, const char *name, size_t len)
Look up an event value by its type, code and name.
const struct input_absinfo * libevdev_get_abs_info(const struct libevdev *dev, unsigned int code)
Get the axis info for the given axis, as advertised by the kernel.
void libevdev_set_id_version(struct libevdev *dev, int version)
int libevdev_event_type_from_name(const char *name)
Look up an event-type by its name.
int libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value)
Turn an LED on or off.
int libevdev_has_property(const struct libevdev *dev, unsigned int prop)
int libevdev_event_type_from_code_name_n(const char *name, size_t len)
Look up an event type for a event code name.
@ LIBEVDEV_GRAB
Grab the device if not currently grabbed.
Definition: libevdev.h:956
int libevdev_event_value_from_name(unsigned int type, unsigned int code, const char *name)
Look up an event value by its type, code and name.
@ LIBEVDEV_READ_FLAG_BLOCKING
The fd is not in O_NONBLOCK and a read may block.
Definition: libevdev.h:762
int libevdev_property_from_name_n(const char *name, size_t len)
Look up an input property by its name.
@ LIBEVDEV_LED_OFF
Turn the LED off.
Definition: libevdev.h:1919
int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code)
Get the axis resolution for the given axis, as advertised by the kernel.
int libevdev_event_type_from_name_n(const char *name, size_t len)
Look up an event-type by its name.
libevdev_read_status
Definition: libevdev.h:1071
int libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
Forcibly enable an event type on this device, even if the underlying device does not support it.
int libevdev_property_from_name(const char *name)
Look up an input property by its name.
int libevdev_enable_property(struct libevdev *dev, unsigned int prop)
int libevdev_kernel_set_led_values(struct libevdev *dev,...)
Turn multiple LEDs on or off simultaneously.
int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value)
Fetch the current value of the event type.
void libevdev_set_log_function(libevdev_log_func_t logfunc, void *data)
Set a printf-style logging handler for library-internal logging.
struct libevdev * libevdev_new(void)
Initialize a new libevdev device.
int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code)
Return the current value of the code for the given slot.
libevdev_log_priority
Definition: libevdev.h:823
int libevdev_get_id_version(const struct libevdev *dev)
#define LIBEVDEV_ATTRIBUTE_PRINTF(_format, _args)
Definition: libevdev.h:33
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.
Definition: libevdev.h:845
const char * libevdev_event_code_get_name(unsigned int type, unsigned int code)
int libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
Set the device's EV_ABS axis to the value defined in the abs parameter.
int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code)
Behaviour of this function is undefined if the device does not provide the event.
int libevdev_event_code_from_name_n(unsigned int type, const char *name, size_t len)
Look up an event code by its type and name.
int libevdev_event_code_from_code_name_n(const char *name, size_t len)
Look up an event code by its name.
int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value)
Set the value for a given code for the given slot.
int libevdev_set_fd(struct libevdev *dev, int fd)
Set the fd for this struct and initialize internal data.
void libevdev_set_id_vendor(struct libevdev *dev, int vendor_id)
void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int val)
Change the flat for the given EV_ABS event code, if the code exists.
void libevdev_free(struct libevdev *dev)
Clean up and free the libevdev struct.
enum libevdev_log_priority libevdev_get_log_priority(void)
Return the current log priority level.
int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period)
Get the repeat delay and repeat period values for this device.
int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value)
Fetch the current value of the code for the given slot.
void libevdev_set_id_product(struct libevdev *dev, int product_id)
@ LIBEVDEV_READ_FLAG_FORCE_SYNC
Pretend the next event is a SYN_DROPPED and require the caller to sync.
Definition: libevdev.h:760
int libevdev_has_event_type(const struct libevdev *dev, unsigned int type)
void libevdev_set_abs_minimum(struct libevdev *dev, unsigned int code, int val)
Change the minimum for the given EV_ABS event code, if the code exists.
@ LIBEVDEV_LOG_INFO
informational messages
Definition: libevdev.h:825
int libevdev_has_event_pending(struct libevdev *dev)
Check if there are events waiting for us.
void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
Change the abs info for the given EV_ABS event code, if the code exists.
int libevdev_get_id_bustype(const struct libevdev *dev)
void libevdev_set_name(struct libevdev *dev, const char *name)
Change the device's name as returned by libevdev_get_name().
const char * libevdev_get_uniq(const struct libevdev *dev)
Retrieve the device's unique identifier, either as set by the caller or as read from the kernel.
void libevdev_set_id_bustype(struct libevdev *dev, int bustype)
libevdev_read_flag
Definition: libevdev.h:757
int libevdev_get_id_product(const struct libevdev *dev)
void libevdev_set_device_log_function(struct libevdev *dev, libevdev_device_log_func_t logfunc, enum libevdev_log_priority priority, void *data)
Set a printf-style logging handler for library-internal logging for this device context.
libevdev_led_value
Definition: libevdev.h:1917
int libevdev_get_id_vendor(const struct libevdev *dev)
void libevdev_set_uniq(struct libevdev *dev, const char *uniq)
Change the device's unique identifier as returned by libevdev_get_uniq().
@ LIBEVDEV_LOG_ERROR
critical errors and application bugs
Definition: libevdev.h:824
int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code)
Get the axis flat for the given axis, as advertised by the kernel.
int libevdev_get_num_slots(const struct libevdev *dev)
Get the number of slots supported by this device.
@ LIBEVDEV_READ_STATUS_SYNC
Depending on the libevdev_next_event() read flag:
Definition: libevdev.h:1087
@ LIBEVDEV_LOG_DEBUG
debug information
Definition: libevdev.h:826
int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev)
Get the next event from the device.
int libevdev_get_abs_minimum(const struct libevdev *dev, unsigned int code)
Get the minimum axis value for the given axis, as advertised by the kernel.
int libevdev_disable_property(struct libevdev *dev, unsigned int prop)
@ LIBEVDEV_READ_STATUS_SUCCESS
libevdev_next_event() has finished without an error and an event is available for processing.
Definition: libevdev.h:1078
int libevdev_get_current_slot(const struct libevdev *dev)
Get the currently active slot.
int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code)
Helper function to check if an event is of a specific type and code.
int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data)
Forcibly enable an event code on this device, even if the underlying device does not support it.
const char * libevdev_property_get_name(unsigned int prop)
const char * libevdev_event_value_get_name(unsigned int type, unsigned int code, int value)
This function resolves the event value for a code.
int libevdev_get_driver_version(const struct libevdev *dev)
int libevdev_event_code_from_name(unsigned int type, const char *name)
Look up an event code by its type and name.
int libevdev_set_clock_id(struct libevdev *dev, int clockid)
Set the clock ID to be used for timestamps.
int libevdev_get_abs_maximum(const struct libevdev *dev, unsigned int code)
Get the maximum axis value for the given axis, as advertised by the kernel.
void libevdev_set_phys(struct libevdev *dev, const char *phys)
Change the device's physical location as returned by libevdev_get_phys().
int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code)
Forcibly disable an event code on this device, even if the underlying device provides it.
int libevdev_change_fd(struct libevdev *dev, int fd)
Change the fd for this device, without re-reading the actual device.
int libevdev_disable_event_type(struct libevdev *dev, unsigned int type)
Forcibly disable an event type on this device, even if the underlying device provides it.
const char * libevdev_get_phys(const struct libevdev *dev)
Retrieve the device's physical location, either as set by the caller or as read from the kernel.
int libevdev_get_fd(const struct libevdev *dev)
int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code)
Get the axis fuzz for the given axis, as advertised by the kernel.
void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int val)
Change the fuzz for the given EV_ABS event code, if the code exists.
const char * libevdev_event_type_get_name(unsigned int type)
void libevdev_set_log_priority(enum libevdev_log_priority priority)
Define the minimum level to be printed to the log handler.
int libevdev_event_code_from_code_name(const char *name)
Look up an event code by its name.
int libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab)
Grab or ungrab the device through a kernel EVIOCGRAB.
int libevdev_event_is_type(const struct input_event *ev, unsigned int type)
Helper function to check if an event is of a specific type.
libevdev_grab_mode
Definition: libevdev.h:955
const char * libevdev_get_name(const struct libevdev *dev)
Retrieve the device's name, either as set by the caller or as read from the kernel.
@ LIBEVDEV_LED_ON
Turn the LED on.
Definition: libevdev.h:1918
void libevdev_set_abs_maximum(struct libevdev *dev, unsigned int code, int val)
Change the maximum for the given EV_ABS event code, if the code exists.
@ LIBEVDEV_READ_FLAG_NORMAL
Process data in normal mode.
Definition: libevdev.h:759
@ LIBEVDEV_READ_FLAG_SYNC
Process data in sync mode.
Definition: libevdev.h:758
void(* libevdev_device_log_func_t)(const struct libevdev *dev, 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 for a specific libevdev context.
Definition: libevdev.h:918
int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value)
Set the value for a given event type and code.
int libevdev_event_type_from_code_name(const char *name)
Look up an event type for a event code name.
int libevdev_new_from_fd(int fd, struct libevdev **dev)
Initialize a new libevdev device from the given fd.