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 
750 struct libevdev;
751 
761 };
762 
777 struct libevdev* libevdev_new(void);
778 
801 int libevdev_new_from_fd(int fd, struct libevdev **dev);
802 
816 void libevdev_free(struct libevdev *dev);
817 
825 };
826 
843 typedef void (*libevdev_log_func_t)(enum libevdev_log_priority priority,
844  void *data,
845  const char *file, int line,
846  const char *func,
847  const char *format, va_list args)
849 
868 void libevdev_set_log_function(libevdev_log_func_t logfunc, void *data);
869 
883 
896 
916 typedef void (*libevdev_device_log_func_t)(const struct libevdev *dev,
917  enum libevdev_log_priority priority,
918  void *data,
919  const char *file, int line,
920  const char *func,
921  const char *format, va_list args)
923 
945 void libevdev_set_device_log_function(struct libevdev *dev,
947  enum libevdev_log_priority priority,
948  void *data);
949 
956 };
957 
980 int libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab);
981 
1014 int libevdev_set_fd(struct libevdev* dev, int fd);
1015 
1054 int libevdev_change_fd(struct libevdev* dev, int fd);
1055 
1064 int libevdev_get_fd(const struct libevdev* dev);
1065 
1086 };
1087 
1138 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev);
1139 
1162 int libevdev_has_event_pending(struct libevdev *dev);
1163 
1178 const char* libevdev_get_name(const struct libevdev *dev);
1179 
1193 void libevdev_set_name(struct libevdev *dev, const char *name);
1194 
1210 const char * libevdev_get_phys(const struct libevdev *dev);
1211 
1225 void libevdev_set_phys(struct libevdev *dev, const char *phys);
1226 
1240 const char * libevdev_get_uniq(const struct libevdev *dev);
1241 
1255 void libevdev_set_uniq(struct libevdev *dev, const char *uniq);
1256 
1266 int libevdev_get_id_product(const struct libevdev *dev);
1267 
1277 void libevdev_set_id_product(struct libevdev *dev, int product_id);
1278 
1288 int libevdev_get_id_vendor(const struct libevdev *dev);
1289 
1299 void libevdev_set_id_vendor(struct libevdev *dev, int vendor_id);
1300 
1310 int libevdev_get_id_bustype(const struct libevdev *dev);
1311 
1321 void libevdev_set_id_bustype(struct libevdev *dev, int bustype);
1322 
1332 int libevdev_get_id_version(const struct libevdev *dev);
1333 
1343 void libevdev_set_id_version(struct libevdev *dev, int version);
1344 
1354 int libevdev_get_driver_version(const struct libevdev *dev);
1355 
1366 int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
1367 
1379 int libevdev_enable_property(struct libevdev *dev, unsigned int prop);
1380 
1391 int libevdev_has_event_type(const struct libevdev *dev, unsigned int type);
1392 
1404 int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code);
1405 
1418 int libevdev_get_abs_minimum(const struct libevdev *dev, unsigned int code);
1419 
1432 int libevdev_get_abs_maximum(const struct libevdev *dev, unsigned int code);
1433 
1446 int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code);
1447 
1460 int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code);
1461 
1474 int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code);
1475 
1489 const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, unsigned int code);
1490 
1513 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
1514 
1549 int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value);
1550 
1576 int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value);
1577 
1598 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
1599 
1628 int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value);
1629 
1655 int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value);
1656 
1670 int libevdev_get_num_slots(const struct libevdev *dev);
1671 
1687 int libevdev_get_current_slot(const struct libevdev *dev);
1688 
1700 void libevdev_set_abs_minimum(struct libevdev *dev, unsigned int code, int min);
1701 
1713 void libevdev_set_abs_maximum(struct libevdev *dev, unsigned int code, int max);
1714 
1726 void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int fuzz);
1727 
1739 void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int flat);
1740 
1752 void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int resolution);
1753 
1765 void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1766 
1784 int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
1785 
1812 int libevdev_disable_event_type(struct libevdev *dev, unsigned int type);
1813 
1847 int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data);
1848 
1876 int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code);
1877 
1892 int libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1893 
1900 };
1901 
1915 int libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value);
1916 
1940 int libevdev_kernel_set_led_values(struct libevdev *dev, ...);
1941 
1956 int libevdev_set_clock_id(struct libevdev *dev, int clockid);
1957 
1979 int libevdev_event_is_type(const struct input_event *ev, unsigned int type);
1980 
2004 int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code);
2005 
2017 const char * libevdev_event_type_get_name(unsigned int type);
2030 const char * libevdev_event_code_get_name(unsigned int type, unsigned int code);
2031 
2052 const char * libevdev_event_value_get_name(unsigned int type,
2053  unsigned int code,
2054  int value);
2068 const char* libevdev_property_get_name(unsigned int prop);
2069 
2082 int libevdev_event_type_get_max(unsigned int type);
2083 
2098 int libevdev_event_type_from_name(const char *name);
2099 
2116 int libevdev_event_type_from_name_n(const char *name, size_t len);
2117 
2137 int libevdev_event_code_from_name(unsigned int type, const char *name);
2138 
2160 int libevdev_event_code_from_name_n(unsigned int type, const char *name,
2161  size_t len);
2162 
2184 int libevdev_event_value_from_name(unsigned int type, unsigned int code,
2185  const char *name);
2186 
2203 int
2204 libevdev_event_type_from_code_name(const char *name);
2205 
2224 int
2225 libevdev_event_type_from_code_name_n(const char *name, size_t len);
2226 
2243 int
2244 libevdev_event_code_from_code_name(const char *name);
2245 
2264 int
2265 libevdev_event_code_from_code_name_n(const char *name, size_t len);
2266 
2290 int libevdev_event_value_from_name_n(unsigned int type, unsigned int code,
2291  const char *name, size_t len);
2292 
2305 int libevdev_property_from_name(const char *name);
2306 
2321 int libevdev_property_from_name_n(const char *name, size_t len);
2322 
2340 int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period);
2341 
2342 /********* DEPRECATED SECTION *********/
2343 #if defined(__GNUC__) && __GNUC__ >= 4
2344 #define LIBEVDEV_DEPRECATED __attribute__ ((deprecated))
2345 #else
2346 #define LIBEVDEV_DEPRECATED
2347 #endif
2348 
2349 #ifdef __cplusplus
2350 }
2351 #endif
2352 
2353 #endif /* LIBEVDEV_H */
libevdev_read_status
Definition: libevdev.h:1069
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_has_event_pending(struct libevdev *dev)
Check if there are events waiting for us.
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:916
int libevdev_event_type_from_name_n(const char *name, size_t len)
Look up an event-type by its name.
int libevdev_has_property(const struct libevdev *dev, unsigned int prop)
int libevdev_change_fd(struct libevdev *dev, int fd)
Change the fd for this device, without re-reading the actual device.
informational messages
Definition: libevdev.h:823
int libevdev_enable_property(struct libevdev *dev, unsigned int prop)
const char * libevdev_event_type_get_name(unsigned int type)
int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code)
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.
critical errors and application bugs
Definition: libevdev.h:822
void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int fuzz)
Change the fuzz for the given EV_ABS event code, if the code exists.
Process data in sync mode.
Definition: libevdev.h:756
int libevdev_get_fd(const struct libevdev *dev)
int libevdev_event_type_from_code_name(const char *name)
Look up an event type for a event code name.
libevdev_led_value
Definition: libevdev.h:1897
void libevdev_set_uniq(struct libevdev *dev, const char *uniq)
Change the device&#39;s unique identifier as returned by libevdev_get_uniq().
debug information
Definition: libevdev.h:824
const char * libevdev_event_code_get_name(unsigned int type, unsigned int code)
int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period)
Get the repeat delay and repeat period values for this device.
The fd is not in O_NONBLOCK and a read may block.
Definition: libevdev.h:760
enum libevdev_log_priority libevdev_get_log_priority(void)
Return the current log priority level.
int libevdev_event_code_from_code_name(const char *name)
Look up an event code by its name.
void libevdev_set_log_function(libevdev_log_func_t logfunc, void *data)
Set a printf-style logging handler for library-internal logging.
int libevdev_has_event_type(const struct libevdev *dev, unsigned int type)
int libevdev_event_code_from_name(unsigned int type, const char *name)
Look up an event code by its type and name.
Turn the LED off.
Definition: libevdev.h:1899
void libevdev_set_abs_maximum(struct libevdev *dev, unsigned int code, int max)
Change the maximum for the given EV_ABS event code, if the code exists.
Pretend the next event is a SYN_DROPPED and require the caller to sync.
Definition: libevdev.h:758
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.
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_event_code_from_name_n(unsigned int type, const char *name, size_t len)
Look up an event code by its type and name.
void libevdev_set_id_vendor(struct libevdev *dev, int vendor_id)
void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int resolution)
Change the resolution for the given EV_ABS event code, if the code exists.
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_grab(struct libevdev *dev, enum libevdev_grab_mode grab)
Grab or ungrab the device through a kernel EVIOCGRAB.
Turn the LED on.
Definition: libevdev.h:1898
int libevdev_get_id_bustype(const struct libevdev *dev)
int libevdev_event_type_get_max(unsigned int type)
int libevdev_event_type_from_name(const char *name)
Look up an event-type by its name.
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...
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_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code)
Return the current value of the code for the given slot.
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. ...
const char * libevdev_get_name(const struct libevdev *dev)
Retrieve the device&#39;s name, either as set by the caller or as read from the kernel.
int libevdev_get_driver_version(const struct libevdev *dev)
int libevdev_get_id_version(const struct libevdev *dev)
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_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev)
Get the next event from the device.
const char * libevdev_get_uniq(const struct libevdev *dev)
Retrieve the device&#39;s unique identifier, either as set by the caller or as read from the kernel...
Depending on the libevdev_next_event() read flag:
Definition: libevdev.h:1085
int libevdev_property_from_name_n(const char *name, size_t len)
Look up an input property by its name.
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:843
int libevdev_new_from_fd(int fd, struct libevdev **dev)
Initialize a new libevdev device from the given fd.
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.
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_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
Set the device&#39;s EV_ABS axis to the value defined in the abs parameter.
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.
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_id_bustype(struct libevdev *dev, int bustype)
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_event_is_type(const struct input_event *ev, unsigned int type)
Helper function to check if an event is of a specific type.
void libevdev_set_id_version(struct libevdev *dev, int version)
const char * libevdev_property_get_name(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.
#define LIBEVDEV_ATTRIBUTE_PRINTF(_format, _args)
Definition: libevdev.h:33
int libevdev_get_id_product(const struct libevdev *dev)
const char * libevdev_get_phys(const struct libevdev *dev)
Retrieve the device&#39;s physical location, either as set by the caller or as read from the kernel...
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.
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_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value)
Turn an LED on or off.
int libevdev_set_clock_id(struct libevdev *dev, int clockid)
Set the clock ID to be used for timestamps.
int libevdev_get_num_slots(const struct libevdev *dev)
Get the number of slots supported by this device.
int libevdev_property_from_name(const char *name)
Look up an input property by its name.
void libevdev_set_log_priority(enum libevdev_log_priority priority)
Define the minimum level to be printed to the log handler.
libevdev_next_event() has finished without an error and an event is available for processing...
Definition: libevdev.h:1076
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...
libevdev_read_flag
Definition: libevdev.h:755
int libevdev_set_fd(struct libevdev *dev, int fd)
Set the fd for this struct and initialize internal data.
int libevdev_kernel_set_led_values(struct libevdev *dev,...)
Turn multiple LEDs on or off simultaneously.
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.
void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int flat)
Change the flat for the given EV_ABS event code, if the code exists.
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.
void libevdev_set_phys(struct libevdev *dev, const char *phys)
Change the device&#39;s physical location as returned by libevdev_get_phys().
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...
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.
Grab the device if not currently grabbed.
Definition: libevdev.h:954
void libevdev_set_name(struct libevdev *dev, const char *name)
Change the device&#39;s name as returned by libevdev_get_name().
void libevdev_free(struct libevdev *dev)
Clean up and free the libevdev struct.
void libevdev_set_abs_minimum(struct libevdev *dev, unsigned int code, int min)
Change the minimum for the given EV_ABS event code, if the code exists.
int libevdev_get_id_vendor(const struct libevdev *dev)
int libevdev_event_code_from_code_name_n(const char *name, size_t len)
Look up an event code by its name.
Process data in normal mode.
Definition: libevdev.h:757
libevdev_grab_mode
Definition: libevdev.h:953
libevdev_log_priority
Definition: libevdev.h:821
void libevdev_set_id_product(struct libevdev *dev, int product_id)
struct libevdev * libevdev_new(void)
Initialize a new libevdev device.
Ungrab the device if currently grabbed.
Definition: libevdev.h:955