1dd3a4bc4d2aada75b5ed2eac644b2eb8e194e27
[platform/upstream/libevdev.git] / libevdev / libevdev.h
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 /**
34  * @mainpage
35  *
36  * **libevdev** is a library for handling evdev kernel devices. It abstracts
37  * the \ref ioctls through type-safe interfaces and provides functions to change
38  * the appearance of the device.
39  *
40  * Development of libevdev is discussed on
41  * [input-tools@lists.freedesktop.org](http://lists.freedesktop.org/mailman/listinfo/input-tools)
42  * Please submit patches, questions or general comments there.
43  *
44  * Handling events and SYN_DROPPED
45  * ===============================
46  *
47  * libevdev provides an interface for handling events, including most notably
48  * SYN_DROPPED events. SYN_DROPPED events are sent by the kernel when the
49  * process does not read events fast enough and the kernel is forced to drop
50  * some events. This causes the device to get out of sync with the process'
51  * view of it. libevdev handles this by telling the caller that a SYN_DROPPED
52  * has been received and that the state of the device is different to what is
53  * to be expected. It then provides the delta between the previous state and
54  * the actual state of the device as a set of events. See
55  * libevdev_next_event() for more information.
56  *
57  * Signal safety
58  * =============
59  *
60  * libevdev is signal-safe for the majority of its operations. Check the API
61  * documentation to make sure, unless explicitly stated a call is <b>not</b>
62  * signal safe.
63  *
64  * Device handling
65  * ===============
66  *
67  * libevdev does not attempt duplicate detection. Initializing two libevdev
68  * devices for the same fd is valid and behaves the same as for two different
69  * devices.
70  *
71  * libevdev does not handle the file descriptors directly, it merely uses
72  * them. The caller is responsible for opening the file descriptors, setting
73  * them to O_NONBLOCK and handling permissions.
74  *
75  * Where does libevdev sit?
76  * ========================
77  *
78  * libevdev is essentially a `read(2)` on steroids for `/dev/input/eventX
79  * devices. It sits below the process that handles input events, in between
80  * the kernel and that process. In the simplest case, e.g. an evtest-like tool
81  * the stack would look like this:
82  *
83  *      kernel → libevdev → evtest
84  *
85  * For X.Org input modules, the stack would look like this:
86  *
87  *      kernel → libevdev → xf86-input-evdev → X server → X client
88  *
89  * For Weston/Wayland, the stack would look like this:
90  *
91  *      kernel → libevdev → Weston → Wayland client
92  *
93  * libevdev does **not** have knowledge of X clients or Wayland clients, it is
94  * too low in the stack.
95  *
96  * Example
97  * =======
98  * Below is a simple example that shows how libevdev could be used. This example
99  * opens a device, checks for relative axes and a left mouse button and if it
100  * finds them monitors the device to print the event.
101  *
102  * @code
103  *      struct libevdev *dev = NULL;
104  *      int fd;
105  *      int rc = 1;
106  *
107  *      fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
108  *      rc = libevdev_new_from_fd(fd, &dev);
109  *      if (rc < 0) {
110  *              fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
111  *              exit(1);
112  *      }
113  *      printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
114  *      printf("Input device ID: bus %#x vendor %#x product %#x\n",
115  *             libevdev_get_id_bustype(dev),
116  *             libevdev_get_id_vendor(dev),
117  *             libevdev_get_id_product(dev));
118  *      if (!libevdev_has_event_type(dev, EV_REL) ||
119  *          !libevdev_has_event_code(dev, EV_KEY, BTN_LEFT)) {
120  *              printf("This device does not look like a mouse\n");
121  *              exit(1);
122  *      }
123  *
124  *      do {
125  *              struct input_event ev;
126  *              rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
127  *              if (rc == 0)
128  *                      printf("Event: %s %s %d\n",
129  *                             libevdev_get_event_type_name(ev.type),
130  *                             libevdev_get_event_code_name(ev.type, ev.code),
131  *                             ev.value);
132  *      } while (rc == 1 || rc == 0 || rc == -EAGAIN);
133  * @endcode
134  *
135  * A more complete example is available with the libevdev-events tool here:
136  * http://cgit.freedesktop.org/libevdev/tree/tools/libevdev-events.c
137  *
138  * Backwards compatibility with older kernel
139  * =========================================
140  * libevdev attempts to build and run correctly on a number of kernel versions.
141  * If features required are not available, libevdev attempts to work around them
142  * in the most reasonable way. For more details see \ref backwardscompatibility.
143  *
144  * License information
145  * ===================
146  * libevdev is licensed under the
147  * [X11 license](http://cgit.freedesktop.org/libevdev/tree/COPYING).
148  *
149  * Reporting bugs
150  * ==============
151  * Please report bugs in the freedesktop.org bugzilla under the libevdev product:
152  * https://bugs.freedesktop.org/enter_bug.cgi?product=libevdev
153  */
154
155 /**
156  * @page testing libevdev-internal test suite
157  *
158  * libevdev's internal test suite uses the
159  * [Check unit testing framework](http://check.sourceforge.net/). Tests are
160  * divided into test suites and test cases. Most tests create a uinput device,
161  * so you'll need to run as root.
162  *
163  * To run a specific suite only:
164  *
165  *     export CK_RUN_SUITE="suite name"
166  *
167  * To run a specific test case only:
168  *
169  *     export CK_RUN_TEST="test case name"
170  *
171  * To get a list of all suites or tests:
172  *
173  *     git grep "suite_create"
174  *     git grep "tcase_create"
175  *
176  * By default, check forks, making debugging harder. Run gdb as below to avoid
177  * forking.
178  *
179  *     sudo CK_FORK=no CK_RUN_TEST="test case name" gdb ./test/test-libevdev
180  *
181  * A special target `make gcov-report.txt` exists that runs gcov and leaves a
182  * `libevdev.c.gcov` file. Check that for test coverage.
183  *
184  * `make check` is hooked up to run the test and gcov (again, needs root).
185  *
186  * The test suite creates a lot of devices, very quickly. Add the following
187  * xorg.conf.d snippet to avoid the devices being added as X devices (at the
188  * time of writing, mutter can't handle these devices and exits after getting
189  * a BadDevice error).
190  *
191  *     $ cat /etc/X11/xorg.conf.d/99-ignore-libevdev-devices.conf
192  *     Section "InputClass"
193  *             Identifier "Ignore libevdev test devices"
194  *             MatchProduct "libevdev test device"
195  *             Option "Ignore" "on"
196  *     EndSection
197  *
198  */
199
200 /**
201  * @page backwardscompatibility Compatibility and Behavior across kernel versions
202  *
203  * This page describes libevdev's behavior when the build-time kernel and the
204  * run-time kernel differ in their feature set.
205  *
206  * With the exception of event names, libevdev defines features that may be
207  * missing on older kernels and building on such kernels will not disable
208  * features. Running libevdev on a kernel that is missing some feature will
209  * change libevdev's behavior. In most cases, the new behavior should be
210  * obvious, but it is spelled out below in detail.
211  *
212  * Minimum requirements
213  * ====================
214  * libevdev requires a 2.6.36 kernel as minimum. Specifically, it requires
215  * ABS_MT_SLOT and the matching behavior.
216  *
217  * Event and input property names
218  * ==============================
219  * Event names and input property names are defined at build-time by the
220  * linux/input.h shipped with libevedv.
221  * The list of event names is compiled at build-time and thus any events not defined
222  * at build time will not resolve. Specifically,
223  * libevdev_event_code_get_name(type, code) for an undefined type or code will
224  * always return NULL. Likewise, libevdev_property_get_name() will return NULL
225  * for properties undefined on the build system.
226  *
227  * Input properties
228  * ================
229  * If the kernel does not support input properties, specifically the
230  * EVIOCGPROPS ioctl, libevdev does not expose input properties to the caller.
231  * Specifically, libevdev_has_property() will always return 0 unless the
232  * property has been manually set with libevdev_enable_property().
233  *
234  * This also applies to the libevdev-uinput code. If uinput does not honor
235  * UI_SET_PROPBIT, libevdev will continue without setting the properties on
236  * the device.
237  *
238  * MT slot behavior
239  * =================
240  * If the kernel does not support the EVIOCGMTSLOTS ioctl, libevdev continues
241  * as normal and assumes all values in all slots to be 0.
242  *
243  * SYN_DROPPED behavior
244  * ====================
245  * A kernel without SYN_DROPPED, won't send the event. libevdev_next_event()
246  * will never require the switch to sync mode.
247  *
248  */
249
250 /**
251  * @page ioctls evdev ioctls
252  *
253  * This page lists the status of the evdev-specific ioctls in libevdev.
254  *
255  * <dl>
256  * <dt>EVIOCGVERSION:</dt>
257  * <dd>supported, see libevdev_get_driver_version()</dd>
258  * <dt>EVIOCGID:</dt>
259  * <dd>supported, see libevdev_get_id_product(), libevdev_get_id_vendor(),
260  * libevdev_get_id_bustype(), * * libevdev_get_id_version()</dd>
261  * <dt>EVIOCGREP:</dt>
262  * <dd>supported, see libevdev_get_event_value())</dd>
263  * <dt>EVIOCSREP:</dt>
264  * <dd>supported, see libevdev_enable_event_code()</dd>
265  * <dt>EVIOCGKEYCODE:</dt>
266  * <dd>currently not supported</dd>
267  * <dt>EVIOCGKEYCODE:</dt>
268  * <dd>currently not supported</dd>
269  * <dt>EVIOCSKEYCODE:</dt>
270  * <dd>currently not supported</dd>
271  * <dt>EVIOCSKEYCODE:</dt>
272  * <dd>currently not supported</dd>
273  * <dt>EVIOCGNAME:</dt>
274  * <dd>supported, see libevdev_get_name()</dd>
275  * <dt>EVIOCGPHYS:</dt>
276  * <dd>supported, see libevdev_get_phys()</dd>
277  * <dt>EVIOCGUNIQ:</dt>
278  * <dd>supported, see libevdev_get_uniq()</dd>
279  * <dt>EVIOCGPROP:</dt>
280  * <dd>supported, see libevdev_has_property()</dd>
281  * <dt>EVIOCGMTSLOTS:</dt>
282  * <dd>supported, see libevdev_get_num_slots(), libevdev_get_slot_value()</dd>
283  * <dt>EVIOCGKEY:</dt>
284  * <dd>supported, see libevdev_has_event_code(), libevdev_get_event_value()</dd>
285  * <dt>EVIOCGLED:</dt>
286  * <dd>supported, see libevdev_has_event_code(), libevdev_get_event_value()</dd>
287  * <dt>EVIOCGSND:</dt>
288  * <dd>currently not supported</dd>
289  * <dt>EVIOCGSW:</dt>
290  * <dd>supported, see libevdev_has_event_code(), libevdev_get_event_value()</dd>
291  * <dt>EVIOCGBIT:</dt>
292  * <dd>supported, see libevdev_has_event_code(), libevdev_get_event_value()</dd>
293  * <dt>EVIOCGABS:</dt>
294  * <dd>supported, see libevdev_has_event_code(), libevdev_get_event_value(),
295  * libevdev_get_abs_info()</dd>
296  * <dt>EVIOCSABS:</dt>
297  * <dd>supported, see libevdev_kernel_set_abs_info()</dd>
298  * <dt>EVIOCSFF:</dt>
299  * <dd>currently not supported</dd>
300  * <dt>EVIOCRMFF:</dt>
301  * <dd>currently not supported</dd>
302  * <dt>EVIOCGEFFECTS:</dt>
303  * <dd>currently not supported</dd>
304  * <dt>EVIOCGRAB:</dt>
305  * <dd>supported, see libevdev_grab()</dd>
306  * <dt>EVIOCSCLOCKID:</dt>
307  * <dd>supported, see libevdev_set_clock_id()</dd>
308  * </dl>
309  *
310  */
311
312 /**
313  * @defgroup init Initialization and setup
314  *
315  * Initialization, initial setup and file descriptor handling.
316  * These functions are the main entry points for users of libevdev, usually a
317  * caller will use this series of calls:
318  *
319  * @code
320  * struct libevdev *dev;
321  * int err;
322  *
323  * dev = libevdev_new();
324  * if (!dev)
325  *         return ENOMEM;
326  *
327  * err = libevdev_set_fd(dev, fd);
328  * if (err < 0) {
329  *         printf("Failed (errno %d): %s\n", -err, strerror(-err));
330  *
331  * libevdev_free(dev);
332  * @endcode
333  *
334  * libevdev_set_fd() is the central call and initializes the internal structs
335  * for the device at the given fd. libevdev functions will fail if called
336  * before libevdev_set_fd() unless documented otherwise.
337  */
338
339 /**
340  * @defgroup bits Querying device capabilities
341  *
342  * Abstraction functions to handle device capabilities, specificially
343  * device propeties such as the name of the device and the bits
344  * representing the events suppported by this device.
345  *
346  * The logical state returned may lag behind the physical state of the device.
347  * libevdev queries the device state on libevdev_set_fd() and then relies on
348  * the caller to parse events through libevdev_next_fd(). If a caller does not
349  * use libevdev_next_fd(), libevdev will not update the internal state of the
350  * device and thus returns outdated values.
351  */
352
353 /**
354  * @defgroup mt Multi-touch related functions
355  * Functions for querying multi-touch-related capabilities. MT devices
356  * following the kernel protocol B (using ABS_MT_SLOT) provide multiple touch
357  * points through so-called slots on the same axis. The slots are enumerated,
358  * a client reading from the device will first get an ABS_MT_SLOT event, then
359  * the values of axes changed in this slot. Multiple slots may be provided in
360  * before an EV_SYN event.
361  *
362  * As with @ref bits, the logical state of the device as seen by the library
363  * depends on the caller using libevdev_next_event().
364  */
365
366 /**
367  * @defgroup kernel Modifying the appearance or capabilities of the device
368  *
369  * Modifying the set of events reported by this device. By default, the
370  * libevdev device mirrors the kernel device, enabling only those bits
371  * exported by the kernel. This set of functions enable or disable bits as
372  * seen from the caller.
373  *
374  * Enabling an event type or code does not affect event reporting - a
375  * software-enabled event will not be generated by the physical hardware.
376  * Disabling an event will prevent libevdev from routing such events to the
377  * caller. Enabling and disabling event types and codes is at the library
378  * level and thus only affects the caller.
379  *
380  * If an event type or code is enabled at kernel-level, future users of this
381  * device will see this event enabled. Currently there is no option of
382  * disabling an event type or code at kernel-level.
383  */
384
385 /**
386  * @defgroup misc Miscellaneous helper functions
387  *
388  * Functions for printing or querying event ranges. The list of names is
389  * compiled into libevdev and will not change when the kernel changes. Adding
390  * or removing names requires a re-compilation of libevdev. Likewise, the max
391  * for each event type is compiled in and does not check the underlying
392  * kernel.
393  */
394
395 /**
396  * @defgroup events Event handling
397  *
398  * Functions to handle events and fetch the current state of the event. Generally,
399  * libevdev updates its internal state as the event is processed and forwarded
400  * to the caller. Thus, the libevdev state of the device should always be identical
401  * to the caller's state. It may however lag behind the actual state of the device.
402  */
403
404 /**
405  * @ingroup init
406  *
407  * Opaque struct representing an evdev device.
408  */
409 struct libevdev;
410
411 /**
412  * @ingroup events
413  */
414 enum libevdev_read_flag {
415         LIBEVDEV_READ_FLAG_SYNC         = 1, /**< Process data in sync mode */
416         LIBEVDEV_READ_FLAG_NORMAL       = 2, /**< Process data in normal mode */
417         LIBEVDEV_READ_FLAG_FORCE_SYNC   = 4, /**< Pretend the next event is a SYN_DROPPED and
418                                                   require the caller to sync */
419         LIBEVDEV_READ_FLAG_BLOCKING     = 8  /**< The fd is not in O_NONBLOCK and a read may block */
420 };
421
422 /**
423  * @ingroup init
424  *
425  * Initialize a new libevdev device. This function only allocates the
426  * required memory and initializes the struct to sane default values.
427  * To actually hook up the device to a kernel device, use
428  * libevdev_set_fd().
429  *
430  * Memory allocated through libevdev_new() must be released by the
431  * caller with libevdev_free().
432  *
433  * @see libevdev_set_fd
434  * @see libevdev_free
435  */
436 struct libevdev* libevdev_new(void);
437
438 /**
439  * @ingroup init
440  *
441  * Initialize a new libevdev device from the given fd.
442  *
443  * This is a shortcut for
444  *
445  * @code
446  * int err;
447  * struct libevdev *dev = libevdev_new();
448  * err = libevdev_set_fd(dev, fd);
449  * @endcode
450  *
451  * @param fd A file descriptor to the device in O_RDWR or O_RDONLY mode.
452  * @param[out] dev The newly initialized evdev device.
453  *
454  * @return On success, zero is returned and dev is set to the newly
455  * allocated struct. On failure, a negative errno is returned and the value
456  * of dev is undefined.
457  *
458  * @see libevdev_free
459  */
460 int libevdev_new_from_fd(int fd, struct libevdev **dev);
461
462 /**
463  * @ingroup init
464  *
465  * Clean up and free the libevdev struct. After completion, the <code>struct
466  * libevdev</code> is invalid and must not be used.
467  *
468  * @param dev The evdev device
469  *
470  * @note This function may be called before libevdev_set_fd().
471  */
472 void libevdev_free(struct libevdev *dev);
473
474 /**
475  * @ingroup init
476  */
477 enum libevdev_log_priority {
478         LIBEVDEV_LOG_ERROR = 10,        /**< critical errors and application bugs */
479         LIBEVDEV_LOG_INFO  = 20,        /**< informational messages */
480         LIBEVDEV_LOG_DEBUG = 30         /**< debug information */
481 };
482
483 /**
484  * @ingroup init
485  *
486  * Logging function called by library-internal logging.
487  * This function is expected to treat its input like printf would.
488  *
489  * @param priority Log priority of this message
490  * @param data User-supplied data pointer (see libevdev_set_log_function())
491  * @param file libevdev source code file generating this message
492  * @param line libevdev source code line generating this message
493  * @param func libevdev source code function generating this message
494  * @param format printf-style format string
495  * @param args List of arguments
496  *
497  * @see libevdev_set_log_function
498  */
499 typedef void (*libevdev_log_func_t)(enum libevdev_log_priority priority,
500                                     void *data,
501                                     const char *file, int line,
502                                     const char *func,
503                                     const char *format, va_list args);
504
505 /**
506  * @ingroup init
507  *
508  * Set a printf-style logging handler for library-internal logging. The default
509  * logging function is to stdout.
510  *
511  * @param logfunc The logging function for this device. If NULL, the current
512  * logging function is unset and no logging is performed.
513  * @param data User-specific data passed to the log handler.
514  *
515  * @note This function may be called before libevdev_set_fd().
516  */
517 void libevdev_set_log_function(libevdev_log_func_t logfunc, void *data);
518
519 /**
520  * @ingroup init
521  *
522  * Define the minimum level to be printed to the log handler.
523  * Messages higher than this level are printed, others are discarded. This
524  * is a global setting and applies to any future logging messages.
525  *
526  * @param priority Minimum priority to be printed to the log.
527  *
528  */
529 void libevdev_set_log_priority(enum libevdev_log_priority priority);
530
531 /**
532  * @ingroup init
533  *
534  * @return the current log level
535  */
536 enum libevdev_log_priority libevdev_get_log_priority(void);
537
538 /**
539  * @ingroup init
540  */
541 enum libevdev_grab_mode {
542         LIBEVDEV_GRAB = 3,      /**< Grab the device if not currently grabbed */
543         LIBEVDEV_UNGRAB = 4     /**< Ungrab the device if currently grabbed */
544 };
545
546 /**
547  * @ingroup init
548  *
549  * Grab or ungrab the device through a kernel EVIOCGRAB. This prevents other
550  * clients (including kernel-internal ones such as rfkill) from receiving
551  * events from this device.
552  *
553  * This is generally a bad idea. Don't do this.
554  *
555  * Grabbing an already grabbed device, or ungrabbing an ungrabbed device is
556  * a noop and always succeeds.
557  *
558  * @param dev The evdev device, already initialized with libevdev_set_fd()
559  * @param grab If true, grab the device. Otherwise ungrab the device.
560  *
561  * @return 0 if the device was successfull grabbed or ungrabbed, or a
562  * negative errno in case of failure.
563  */
564 int libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab);
565
566 /**
567  * @ingroup init
568  *
569  * Set the fd for this struct and initialize internal data.
570  * The fd must be in O_RDONLY or O_RDWR mode.
571  *
572  * This function may only be called once per device. If the device changed and
573  * you need to re-read a device, use libevdev_free() and libevdev_new(). If
574  * you need to change the fd after closing and re-opening the same device, use
575  * libevdev_change_fd().
576  *
577  * Unless otherwise specified, libevdev function behavior is undefined until
578  * a successfull call to libevdev_set_fd().
579  *
580  * @param dev The evdev device
581  * @param fd The file descriptor for the device
582  *
583  * @return 0 on success, or a negative error code on failure
584  *
585  * @see libevdev_change_fd
586  * @see libevdev_new
587  * @see libevdev_free
588  */
589 int libevdev_set_fd(struct libevdev* dev, int fd);
590
591 /**
592  * @ingroup init
593  *
594  * Change the fd for this device, without re-reading the actual device. If the fd
595  * changes after initializing the device, for example after a VT-switch in the
596  * X.org X server, this function updates the internal fd to the newly opened.
597  * No check is made that new fd points to the same device. If the device has
598  * changed, libevdev's behavior is undefined.
599  *
600  * libevdev does not sync itself after changing the fd and keeps the current
601  * device state. Use libevdev_next_event with the LIBEVDEV_FORCE_SYNC flag to
602  * force a re-sync.
603  *
604  * The fd may be open in O_RDONLY or O_RDWR.
605  *
606  * It is an error to call this function before calling libevdev_set_fd().
607  *
608  * @param dev The evdev device, already initialized with libevdev_set_fd()
609  * @param fd The new fd
610  *
611  * @return 0 on success, or -1 on failure.
612  *
613  * @see libevdev_set_fd
614  */
615 int libevdev_change_fd(struct libevdev* dev, int fd);
616
617 /**
618  * @ingroup init
619  *
620  * @param dev The evdev device
621  *
622  * @return The previously set fd, or -1 if none had been set previously.
623  * @note This function may be called before libevdev_set_fd().
624  */
625 int libevdev_get_fd(const struct libevdev* dev);
626
627
628 /**
629  * @ingroup events
630  */
631 enum libevdev_read_status {
632         /**
633          * libevdev_next_event() has finished without an error
634          * and an event is available for processing.
635          *
636          * @see libevdev_next_event
637          */
638         LIBEVDEV_READ_STATUS_SUCCESS = 0,
639         /**
640          * Depending on the libevdev_next_event() read flag:
641          * * libevdev received a SYN_DROPPED from the device, and the caller should
642          * now resync the device, or,
643          * * an event has been read in sync mode.
644          *
645          * @see libevdev_next_event
646          */
647         LIBEVDEV_READ_STATUS_SYNC = 1
648 };
649 /**
650  * @ingroup events
651  *
652  * Get the next event from the device. This function operates in two different
653  * modes: normal mode or sync mode.
654  *
655  * In normal mode, this function returns LIBEVDEV_READ_STATUS_SUCCESS and
656  * returns the event in the parameter ev. If no events are available at this
657  * time, it returns -EAGAIN and ev is undefined.
658  *
659  * If a SYN_DROPPED is read from the device, this function returns
660  * LIBEVDEV_READ_STATUS_SYNC. The caller should now call this function with the
661  * LIBEVDEV_READ_FLAG_SYNC flag set, to get the set of events that make up the
662  * device state delta. This function returns LIBEVDEV_READ_STATUS_SYNC for
663  * each event part of that delta, until it returns -EAGAIN once all events
664  * have been synced.
665  *
666  * If a device needs to be synced by the caller but the caller does not call
667  * with the LIBEVDEV_READ_STATUS_SYNC flag set, all events from the diff are
668  * dropped and event processing continues as normal.
669  *
670  * @param dev The evdev device, already initialized with libevdev_set_fd()
671  * @param flags Set of flags to determine behaviour. If LIBEVDEV_READ_FLAG_NORMAL
672  * is set, the next event is read in normal mode. If LIBEVDEV_READ_FLAG_SYNC is
673  * set, the next event is read in sync mode.
674  * @param ev On success, set to the current event.
675  * @return On failure, a negative errno is returned.
676  * @retval LIBEVDEV_READ_STATUS_SUCCESS One or more events where read of the device
677  * @retval -EAGAIN No events are currently available on the device
678  * @retval LIBEVDEV_READ_STATUS_SYNC A SYN_DROPPED event was received, or a
679  * synced event was returned.
680  *
681  * @note This function is signal-safe.
682  */
683 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev);
684
685 /**
686  * @ingroup events
687  *
688  * Check if there are events waiting for us. This does not read an event off
689  * the fd and may not access the fd at all. If there are events queued
690  * internally this function will return non-zero. If the internal queue is empty,
691  * this function will poll the file descriptor for data.
692  *
693  * This is a convenience function for simple processes, most complex programs
694  * are expected to use select(2) or poll(2) on the file descriptor. The kernel
695  * guarantees that if data is available, it is a multiple of sizeof(struct
696  * input_event), and thus calling libevdev_next_event() when select(2) or
697  * poll(2) return is safe. You do not need libevdev_has_event_pending() if
698  * you're using select(2) or poll(2).
699  *
700  * @param dev The evdev device, already initialized with libevdev_set_fd()
701  * @return On failure, a negative errno is returned.
702  * @retval 0 No event is currently available
703  * @retval 1 One or more events are available on the fd
704  *
705  * @note This function is signal-safe.
706  */
707 int libevdev_has_event_pending(struct libevdev *dev);
708
709 /**
710  * @ingroup bits
711  *
712  * @param dev The evdev device, already initialized with libevdev_set_fd()
713  *
714  * @return The device name as read off the kernel device. The name is never
715  * NULL but it may be the empty string.
716  *
717  * @note This function is signal-safe.
718  */
719 const char* libevdev_get_name(const struct libevdev *dev);
720
721 /**
722  * @ingroup kernel
723  *
724  * @param dev The evdev device
725  * @param name The new, non-NULL, name to assign to this device.
726  *
727  * @note This function may be called before libevdev_set_fd(). A call to
728  * libevdev_set_fd() will overwrite any previously set value.
729  */
730 void libevdev_set_name(struct libevdev *dev, const char *name);
731
732 /**
733  * @ingroup bits
734  *
735  * Virtual devices such as uinput devices have no phys location.
736  *
737  * @param dev The evdev device, already initialized with libevdev_set_fd()
738  *
739  * @return The physical location of this device, or NULL if there is none
740  *
741  * @note This function is signal safe.
742  */
743 const char * libevdev_get_phys(const struct libevdev *dev);
744
745 /**
746  * @ingroup kernel
747  *
748  * @param dev The evdev device
749  * @param phys The new, non-NULL, phys to assign to this device.
750  *
751  * @note This function may be called before libevdev_set_fd(). A call to
752  * libevdev_set_fd() will overwrite any previously set value.
753  */
754 void libevdev_set_phys(struct libevdev *dev, const char *phys);
755
756 /**
757  * @ingroup bits
758  *
759  * @param dev The evdev device, already initialized with libevdev_set_fd()
760  *
761  * @return The unique identifier for this device, or NULL if there is none
762  *
763  * @note This function is signal safe.
764  */
765 const char * libevdev_get_uniq(const struct libevdev *dev);
766
767 /**
768  * @ingroup kernel
769  *
770  * @param dev The evdev device
771  * @param uniq The new, non-NULL, uniq to assign to this device.
772  *
773  * @note This function may be called before libevdev_set_fd(). A call to
774  * libevdev_set_fd() will overwrite any previously set value.
775  */
776 void libevdev_set_uniq(struct libevdev *dev, const char *uniq);
777
778 /**
779  * @ingroup bits
780  *
781  * @param dev The evdev device, already initialized with libevdev_set_fd()
782  *
783  * @return The device's product ID
784  *
785  * @note This function is signal-safe.
786  */
787 int libevdev_get_id_product(const struct libevdev *dev);
788
789 /**
790  * @ingroup kernel
791  *
792  * @param dev The evdev device
793  * @param product_id The product ID to assign to this device
794  *
795  * @note This function may be called before libevdev_set_fd(). A call to
796  * libevdev_set_fd() will overwrite any previously set value.
797  */
798 void libevdev_set_id_product(struct libevdev *dev, int product_id);
799
800 /**
801  * @ingroup bits
802  *
803  * @param dev The evdev device, already initialized with libevdev_set_fd()
804  *
805  * @return The device's vendor ID
806  *
807  * @note This function is signal-safe.
808  */
809 int libevdev_get_id_vendor(const struct libevdev *dev);
810
811 /**
812  * @ingroup kernel
813  *
814  * @param dev The evdev device
815  * @param vendor_id The vendor ID to assign to this device
816  *
817  * @note This function may be called before libevdev_set_fd(). A call to
818  * libevdev_set_fd() will overwrite any previously set value.
819  */
820 void libevdev_set_id_vendor(struct libevdev *dev, int vendor_id);
821
822 /**
823  * @ingroup bits
824  *
825  * @param dev The evdev device, already initialized with libevdev_set_fd()
826  *
827  * @return The device's bus type
828  *
829  * @note This function is signal-safe.
830  */
831 int libevdev_get_id_bustype(const struct libevdev *dev);
832
833 /**
834  * @ingroup kernel
835  *
836  * @param dev The evdev device
837  * @param bustype The bustype to assign to this device
838  *
839  * @note This function may be called before libevdev_set_fd(). A call to
840  * libevdev_set_fd() will overwrite any previously set value.
841  */
842 void libevdev_set_id_bustype(struct libevdev *dev, int bustype);
843
844 /**
845  * @ingroup bits
846  *
847  * @param dev The evdev device, already initialized with libevdev_set_fd()
848  *
849  * @return The device's firmware version
850  *
851  * @note This function is signal-safe.
852  */
853 int libevdev_get_id_version(const struct libevdev *dev);
854
855 /**
856  * @ingroup kernel
857  *
858  * @param dev The evdev device
859  * @param version The version to assign to this device
860  *
861  * @note This function may be called before libevdev_set_fd(). A call to
862  * libevdev_set_fd() will overwrite any previously set value.
863  */
864 void libevdev_set_id_version(struct libevdev *dev, int version);
865
866 /**
867  * @ingroup bits
868  *
869  * @param dev The evdev device, already initialized with libevdev_set_fd()
870  *
871  * @return The driver version for this device
872  *
873  * @note This function is signal-safe.
874  */
875 int libevdev_get_driver_version(const struct libevdev *dev);
876
877 /**
878  * @ingroup bits
879  *
880  * @param dev The evdev device, already initialized with libevdev_set_fd()
881  * @param prop The input property to query for, one of INPUT_PROP_...
882  *
883  * @return 1 if the device provides this input property, or 0 otherwise.
884  *
885  * @note This function is signal-safe
886  */
887 int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
888
889 /**
890  * @ingroup kernel
891  *
892  * @param dev The evdev device
893  * @param prop The input property to enable, one of INPUT_PROP_...
894  *
895  * @return 0 on success or -1 on failure
896  *
897  * @note This function may be called before libevdev_set_fd(). A call to
898  * libevdev_set_fd() will overwrite any previously set value.
899  */
900 int libevdev_enable_property(struct libevdev *dev, unsigned int prop);
901
902 /**
903  * @ingroup bits
904  *
905  * @param dev The evdev device, already initialized with libevdev_set_fd()
906  * @param type The event type to query for, one of EV_SYN, EV_REL, etc.
907  *
908  * @return 1 if the device supports this event type, or 0 otherwise.
909  *
910  * @note This function is signal-safe.
911  */
912 int libevdev_has_event_type(const struct libevdev *dev, unsigned int type);
913
914 /**
915  * @ingroup bits
916  *
917  * @param dev The evdev device, already initialized with libevdev_set_fd()
918  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
919  * @param code The event code to query for, one of ABS_X, REL_X, etc.
920  *
921  * @return 1 if the device supports this event type and code, or 0 otherwise.
922  *
923  * @note This function is signal-safe.
924  */
925 int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code);
926
927 /**
928  * @ingroup bits
929  *
930  * Get the minimum axis value for the given axis, as advertised by the kernel.
931  *
932  * @param dev The evdev device, already initialized with libevdev_set_fd()
933  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
934  *
935  * @return axis minimum for the given axis or 0 if the axis is invalid
936  */
937 int libevdev_get_abs_minimum(const struct libevdev *dev, unsigned int code);
938 /**
939  * @ingroup bits
940  *
941  * Get the maximum axis value for the given axis, as advertised by the kernel.
942  *
943  * @param dev The evdev device, already initialized with libevdev_set_fd()
944  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
945  *
946  * @return axis maximum for the given axis or 0 if the axis is invalid
947  */
948 int libevdev_get_abs_maximum(const struct libevdev *dev, unsigned int code);
949 /**
950  * @ingroup bits
951  *
952  * Get the axis fuzz for the given axis, as advertised by the kernel.
953  *
954  * @param dev The evdev device, already initialized with libevdev_set_fd()
955  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
956  *
957  * @return axis fuzz for the given axis or 0 if the axis is invalid
958  */
959 int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code);
960 /**
961  * @ingroup bits
962  *
963  * Get the axis flat for the given axis, as advertised by the kernel.
964  *
965  * @param dev The evdev device, already initialized with libevdev_set_fd()
966  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
967  *
968  * @return axis flat for the given axis or 0 if the axis is invalid
969  */
970 int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code);
971 /**
972  * @ingroup bits
973  *
974  * Get the axis resolution for the given axis, as advertised by the kernel.
975  *
976  * @param dev The evdev device, already initialized with libevdev_set_fd()
977  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
978  *
979  * @return axis resolution for the given axis or 0 if the axis is invalid
980  */
981 int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code);
982
983 /**
984  * @ingroup bits
985  *
986  * Get the axis info for the given axis, as advertised by the kernel.
987  *
988  * @param dev The evdev device, already initialized with libevdev_set_fd()
989  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
990  *
991  * @return The input_absinfo for the given code, or NULL if the device does
992  * not support this event code.
993  */
994 const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, unsigned int code);
995
996 /**
997  * @ingroup bits
998  *
999  * Behaviour of this function is undefined if the device does not provide
1000  * the event.
1001  *
1002  * If the device supports ABS_MT_SLOT, the value returned for any ABS_MT_*
1003  * event code is the value of the currently active slot. You should use
1004  * libevdev_get_slot_value() instead.
1005  *
1006  * @param dev The evdev device, already initialized with libevdev_set_fd()
1007  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
1008  * @param code The event code to query for, one of ABS_X, REL_X, etc.
1009  *
1010  * @return The current value of the event.
1011  *
1012  * @note This function is signal-safe.
1013  * @note The value for ABS_MT_ events is undefined, use
1014  * libevdev_get_slot_value() instead
1015  *
1016  * @see libevdev_get_slot_value
1017  */
1018 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
1019
1020 /**
1021  * @ingroup kernel
1022  *
1023  * Set the value for a given event type and code. This only makes sense for
1024  * some event types, e.g. setting the value for EV_REL is pointless.
1025  *
1026  * This is a local modification only affecting only this representation of
1027  * this device. A future call to libevdev_get_event_value() will return this
1028  * value, unless the value was overwritten by an event.
1029  *
1030  * If the device supports ABS_MT_SLOT, the value set for any ABS_MT_*
1031  * event code is the value of the currently active slot. You should use
1032  * libevdev_set_slot_value() instead.
1033  *
1034  * @param dev The evdev device, already initialized with libevdev_set_fd()
1035  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
1036  * @param code The event code to set the value for, one of ABS_X, LED_NUML, etc.
1037  * @param value The new value to set
1038  *
1039  * @return 0 on success, or -1 on failure.
1040  * @retval -1 the device does not have the event type or code enabled, or the code is outside the
1041  * allowed limits for the given type, or the type cannot be set.
1042  *
1043  * @see libevdev_set_slot_value
1044  * @see libevdev_get_event_value
1045  */
1046 int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value);
1047
1048 /**
1049  * @ingroup bits
1050  *
1051  * Fetch the current value of the event type. This is a shortcut for
1052  *
1053  * @code
1054  *   if (libevdev_has_event_type(dev, t) && libevdev_has_event_code(dev, t, c))
1055  *       val = libevdev_get_event_value(dev, t, c);
1056  * @endcode
1057  *
1058  * @param dev The evdev device, already initialized with libevdev_set_fd()
1059  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
1060  * @param code The event code to query for, one of ABS_X, REL_X, etc.
1061  * @param[out] value The current value of this axis returned.
1062  *
1063  * @return If the device supports this event type and code, the return value is
1064  * non-zero and value is set to the current value of this axis. Otherwise,
1065  * zero is returned and value is unmodified.
1066  *
1067  * @note This function is signal-safe.
1068  * @note The value for ABS_MT_ events is undefined, use
1069  * libevdev_fetch_slot_value() instead
1070  *
1071  * @see libevdev_fetch_slot_value
1072  */
1073 int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value);
1074
1075 /**
1076  * @ingroup mt
1077  *
1078  * Return the current value of the code for the given slot.
1079  *
1080  * The return value is undefined for a slot exceeding the available slots on
1081  * the device, for a code that is not in the permitted ABS_MT range or for a
1082  * device that does not have slots.
1083  *
1084  * @param dev The evdev device, already initialized with libevdev_set_fd()
1085  * @param slot The numerical slot number, must be smaller than the total number
1086  * of slots on this device
1087  * @param code The event code to query for, one of ABS_MT_POSITION_X, etc.
1088  *
1089  * @note This function is signal-safe.
1090  * @note The value for events other than ABS_MT_ is undefined, use
1091  * libevdev_fetch_value() instead
1092  *
1093  * @see libevdev_get_event_value
1094  */
1095 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
1096
1097 /**
1098  * @ingroup kernel
1099  *
1100  * Set the value for a given code for the given slot.
1101  *
1102  * This is a local modification only affecting only this representation of
1103  * this device. A future call to libevdev_get_slot_value() will return this
1104  * value, unless the value was overwritten by an event.
1105  *
1106  * This function does not set event values for axes outside the ABS_MT range,
1107  * use libevdev_set_event_value() instead.
1108  *
1109  * @param dev The evdev device, already initialized with libevdev_set_fd()
1110  * @param slot The numerical slot number, must be smaller than the total number
1111  * of slots on this device
1112  * @param code The event code to set the value for, one of ABS_MT_POSITION_X, etc.
1113  * @param value The new value to set
1114  *
1115  * @return 0 on success, or -1 on failure.
1116  * @retval -1 the device does not have the event code enabled, or the code is
1117  * outside the allowed limits for multitouch events, or the slot number is outside
1118  * the limits for this device, or the device does not support multitouch events.
1119  *
1120  * @see libevdev_set_event_value
1121  * @see libevdev_get_slot_value
1122  */
1123 int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value);
1124
1125 /**
1126  * @ingroup mt
1127  *
1128  * Fetch the current value of the code for the given slot. This is a shortcut for
1129  *
1130  * @code
1131  *   if (libevdev_has_event_type(dev, EV_ABS) &&
1132  *       libevdev_has_event_code(dev, EV_ABS, c) &&
1133  *       slot < device->number_of_slots)
1134  *       val = libevdev_get_slot_value(dev, slot, c);
1135  * @endcode
1136  *
1137  * @param dev The evdev device, already initialized with libevdev_set_fd()
1138  * @param slot The numerical slot number, must be smaller than the total number
1139  * of slots on this * device
1140  * @param[out] value The current value of this axis returned.
1141  *
1142  * @param code The event code to query for, one of ABS_MT_POSITION_X, etc.
1143  * @return If the device supports this event code, the return value is
1144  * non-zero and value is set to the current value of this axis. Otherwise, or
1145  * if the event code is not an ABS_MT_* event code, zero is returned and value
1146  * is unmodified.
1147  *
1148  * @note This function is signal-safe.
1149  */
1150 int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value);
1151
1152 /**
1153  * @ingroup mt
1154  *
1155  * Get the number of slots supported by this device.
1156  *
1157  * @param dev The evdev device, already initialized with libevdev_set_fd()
1158  *
1159  * @return The number of slots supported, or -1 if the device does not provide
1160  * any slots
1161  *
1162  * @note A device may provide ABS_MT_SLOT but a total number of 0 slots. Hence
1163  * the return value of -1 for "device does not provide slots at all"
1164  */
1165 int libevdev_get_num_slots(const struct libevdev *dev);
1166
1167 /**
1168  * @ingroup mt
1169  *
1170  * Get the currently active slot. This may differ from the value
1171  * an ioctl may return at this time as events may have been read off the fd
1172  * since changing the slot value but those events are still in the buffer
1173  * waiting to be processed. The returned value is the value a caller would
1174  * see if it were to process events manually one-by-one.
1175  *
1176  * @param dev The evdev device, already initialized with libevdev_set_fd()
1177  *
1178  * @return the currently active slot (logically)
1179  */
1180 int libevdev_get_current_slot(const struct libevdev *dev);
1181
1182 /**
1183  * @ingroup kernel
1184  *
1185  * Change the minimum for the given EV_ABS event code, if the code exists.
1186  * This function has no effect if libevdev_has_event_code() returns false for
1187  * this code.
1188  */
1189 void libevdev_set_abs_minimum(struct libevdev *dev, unsigned int code, int min);
1190
1191 /**
1192  * @ingroup kernel
1193  *
1194  * Change the maximum for the given EV_ABS event code, if the code exists.
1195  * This function has no effect if libevdev_has_event_code() returns false for
1196  * this code.
1197  */
1198 void libevdev_set_abs_maximum(struct libevdev *dev, unsigned int code, int max);
1199
1200 /**
1201  * @ingroup kernel
1202  *
1203  * Change the fuzz for the given EV_ABS event code, if the code exists.
1204  * This function has no effect if libevdev_has_event_code() returns false for
1205  * this code.
1206  */
1207 void libevdev_set_abs_fuzz(struct libevdev *dev, unsigned int code, int fuzz);
1208
1209 /**
1210  * @ingroup kernel
1211  *
1212  * Change the flat for the given EV_ABS event code, if the code exists.
1213  * This function has no effect if libevdev_has_event_code() returns false for
1214  * this code.
1215  */
1216 void libevdev_set_abs_flat(struct libevdev *dev, unsigned int code, int flat);
1217
1218 /**
1219  * @ingroup kernel
1220  *
1221  * Change the resolution for the given EV_ABS event code, if the code exists.
1222  * This function has no effect if libevdev_has_event_code() returns false for
1223  * this code.
1224  */
1225 void libevdev_set_abs_resolution(struct libevdev *dev, unsigned int code, int resolution);
1226
1227 /**
1228  * @ingroup kernel
1229  *
1230  * Change the abs info for the given EV_ABS event code, if the code exists.
1231  * This function has no effect if libevdev_has_event_code() returns false for
1232  * this code.
1233  */
1234 void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1235
1236 /**
1237  * @ingroup kernel
1238  *
1239  * Forcibly enable an event type on this device, even if the underlying
1240  * device does not support it. While this cannot make the device actually
1241  * report such events, it will now return true for libevdev_has_event_type().
1242  *
1243  * This is a local modification only affecting only this representation of
1244  * this device.
1245  *
1246  * @param dev The evdev device, already initialized with libevdev_set_fd()
1247  * @param type The event type to enable (EV_ABS, EV_KEY, ...)
1248  *
1249  * @return 0 on success or -1 otherwise
1250  *
1251  * @see libevdev_has_event_type
1252  */
1253 int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
1254
1255 /**
1256  * @ingroup kernel
1257  *
1258  * Forcibly disable an event type on this device, even if the underlying
1259  * device provides it. This effectively mutes the respective set of
1260  * events. libevdev will filter any events matching this type and none will
1261  * reach the caller. libevdev_has_event_type() will return false for this
1262  * type.
1263  *
1264  * In most cases, a caller likely only wants to disable a single code, not
1265  * the whole type. Use libevdev_disable_event_code() for that.
1266  *
1267  * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
1268  * It hurts.
1269  *
1270  * This is a local modification only affecting only this representation of
1271  * this device.
1272  *
1273  * @param dev The evdev device, already initialized with libevdev_set_fd()
1274  * @param type The event type to disable (EV_ABS, EV_KEY, ...)
1275  *
1276  * @return 0 on success or -1 otherwise
1277  *
1278  * @see libevdev_has_event_type
1279  * @see libevdev_disable_event_type
1280  */
1281 int libevdev_disable_event_type(struct libevdev *dev, unsigned int type);
1282
1283 /**
1284  * @ingroup kernel
1285  *
1286  * Forcibly enable an event type on this device, even if the underlying
1287  * device does not support it. While this cannot make the device actually
1288  * report such events, it will now return true for libevdev_has_event_code().
1289  *
1290  * The last argument depends on the type and code:
1291  * - If type is EV_ABS, data must be a pointer to a struct input_absinfo
1292  * containing the data for this axis.
1293  * - For all other types, the argument must be NULL.
1294  *
1295  * This function calls libevdev_enable_event_type() if necessary.
1296  *
1297  * This is a local modification only affecting only this representation of
1298  * this device.
1299  *
1300  * @param dev The evdev device, already initialized with libevdev_set_fd()
1301  * @param type The event type to enable (EV_ABS, EV_KEY, ...)
1302  * @param code The event code to enable (ABS_X, REL_X, etc.)
1303  * @param data If type is EV_ABS, data points to a struct input_absinfo. If type is EV_REP, data
1304  * points to an integer. Otherwise, data must be NULL.
1305  *
1306  * @return 0 on success or -1 otherwise
1307  *
1308  * @see libevdev_enable_event_type
1309  */
1310 int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data);
1311
1312 /**
1313  * @ingroup kernel
1314  *
1315  * Forcibly disable an event code on this device, even if the underlying
1316  * device provides it. This effectively mutes the respective set of
1317  * events. libevdev will filter any events matching this type and code and
1318  * none will reach the caller. libevdev_has_event_code() will return false for
1319  * this code.
1320  *
1321  * Disabling all event codes for a given type will not disable the event
1322  * type. Use libevdev_disable_event_type() for that.
1323  *
1324  * This is a local modification only affecting only this representation of
1325  * this device.
1326  *
1327  * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
1328  * It hurts.
1329  *
1330  * @param dev The evdev device, already initialized with libevdev_set_fd()
1331  * @param type The event type to disable (EV_ABS, EV_KEY, ...)
1332  * @param code The event code to disable (ABS_X, REL_X, etc.)
1333  *
1334  * @return 0 on success or -1 otherwise
1335  *
1336  * @see libevdev_has_event_code
1337  * @see libevdev_disable_event_type
1338  */
1339 int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code);
1340
1341 /**
1342  * @ingroup kernel
1343  *
1344  * Set the device's EV_ABS axis to the value defined in the abs
1345  * parameter. This will be written to the kernel.
1346  *
1347  * @param dev The evdev device, already initialized with libevdev_set_fd()
1348  * @param code The EV_ABS event code to modify, one of ABS_X, ABS_Y, etc.
1349  * @param abs Axis info to set the kernel axis to
1350  *
1351  * @return zero on success, or a negative errno on failure
1352  *
1353  * @see libevdev_enable_event_code
1354  */
1355 int libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
1356
1357
1358 /**
1359  * @ingroup kernel
1360  */
1361 enum libevdev_led_value {
1362         LIBEVDEV_LED_ON = 3,
1363         LIBEVDEV_LED_OFF = 4
1364 };
1365
1366 /**
1367  * @ingroup kernel
1368  *
1369  * Turn an LED on or off. Convenience function, if you need to modify multiple
1370  * LEDs simultaneously, use libevdev_kernel_set_led_values() instead.
1371  *
1372  * @note enabling an LED requires write permissions on the device's file descriptor.
1373  *
1374  * @param dev The evdev device, already initialized with libevdev_set_fd()
1375  * @param code The EV_LED event code to modify, one of LED_NUML, LED_CAPSL, ...
1376  * @param value Specifies whether to turn the LED on or off
1377  * @return zero on success, or a negative errno on failure
1378  */
1379 int libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value);
1380
1381 /**
1382  * @ingroup kernel
1383  *
1384  * Turn multiple LEDs on or off simultaneously. This function expects a pair
1385  * of LED codes and values to set them to, terminated by a -1. For example, to
1386  * switch the NumLock LED on but the CapsLock LED off, use:
1387  *
1388  * @code
1389  *     libevdev_kernel_set_led_values(dev, LED_NUML, LIBEVDEV_LED_ON,
1390  *                                         LED_CAPSL, LIBEVDEV_LED_OFF,
1391  *                                         -1);
1392  * @endcode
1393  *
1394  * If any LED code or value is invalid, this function returns -EINVAL and no
1395  * LEDs are modified.
1396  *
1397  * @note enabling an LED requires write permissions on the device's file descriptor.
1398  *
1399  * @param dev The evdev device, already initialized with libevdev_set_fd()
1400  * @param ... A pair of LED_* event codes and libevdev_led_value_t, followed by
1401  * -1 to terminate the list.
1402  * @return zero on success, or a negative errno on failure
1403  */
1404 int libevdev_kernel_set_led_values(struct libevdev *dev, ...);
1405
1406 /**
1407  * @ingroup kernel
1408  *
1409  * Set the clock ID to be used for timestamps. Further events from this device
1410  * will report an event time based on the given clock.
1411  *
1412  * This is a modification only affecting this representation of
1413  * this device.
1414  *
1415  * @param dev The evdev device, already initialized with libevdev_set_fd()
1416  * @param clockid The clock to use for future events. Permitted values
1417  * are CLOCK_MONOTONIC and CLOCK_REALTIME (the default).
1418  * @return zero on success, or a negative errno on failure
1419  */
1420 int libevdev_set_clock_id(struct libevdev *dev, int clockid);
1421
1422 /**
1423  * @ingroup misc
1424  *
1425  * Helper function to check if an event is of a specific type. This is
1426  * virtually the same as:
1427  *
1428  *      ev->type == type
1429  *
1430  * with the exception that some sanity checks are performed to ensure type
1431  * is valid.
1432  *
1433  * @note The ranges for types are compiled into libevdev. If the kernel
1434  * changes the max value, libevdev will not automatically pick these up.
1435  *
1436  * @param ev The input event to check
1437  * @param type Input event type to compare the event against (EV_REL, EV_ABS,
1438  * etc.)
1439  *
1440  * @return 1 if the event type matches the given type, 0 otherwise (or if
1441  * type is invalid)
1442  */
1443 int libevdev_event_is_type(const struct input_event *ev, unsigned int type);
1444
1445 /**
1446  * @ingroup misc
1447  *
1448  * Helper function to check if an event is of a specific type and code. This
1449  * is virtually the same as:
1450  *
1451  *      ev->type == type && ev->code == code
1452  *
1453  * with the exception that some sanity checks are performed to ensure type and
1454  * code are valid.
1455  *
1456  * @note The ranges for types and codes are compiled into libevdev. If the kernel
1457  * changes the max value, libevdev will not automatically pick these up.
1458  *
1459  * @param ev The input event to check
1460  * @param type Input event type to compare the event against (EV_REL, EV_ABS,
1461  * etc.)
1462  * @param code Input event code to compare the event against (ABS_X, REL_X,
1463  * etc.)
1464  *
1465  * @return 1 if the event type matches the given type and code, 0 otherwise
1466  * (or if type/code are invalid)
1467  */
1468 int libevdev_event_is_code(const struct input_event *ev, unsigned int type, unsigned int code);
1469
1470 /**
1471  * @ingroup misc
1472  *
1473  * @param type The event type to return the name for.
1474  *
1475  * @return The name of the given event type (e.g. EV_ABS) or NULL for an
1476  * invalid type
1477  *
1478  * @note The list of names is compiled into libevdev. If the kernel adds new
1479  * defines for new properties libevdev will not automatically pick these up.
1480  */
1481 const char * libevdev_event_type_get_name(unsigned int type);
1482 /**
1483  * @ingroup misc
1484  *
1485  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
1486  * @param code The event code to return the name for (e.g. ABS_X)
1487  *
1488  * @return The name of the given event code (e.g. ABS_X) or NULL for an
1489  * invalid type or code
1490  *
1491  * @note The list of names is compiled into libevdev. If the kernel adds new
1492  * defines for new properties libevdev will not automatically pick these up.
1493  */
1494 const char * libevdev_event_code_get_name(unsigned int type, unsigned int code);
1495
1496 /**
1497  * @ingroup misc
1498  *
1499  * @param prop The input prop to return the name for (e.g. INPUT_PROP_BUTTONPAD)
1500  *
1501  * @return The name of the given input prop (e.g. INPUT_PROP_BUTTONPAD) or NULL for an
1502  * invalid property
1503  *
1504  * @note The list of names is compiled into libevdev. If the kernel adds new
1505  * defines for new properties libevdev will not automatically pick these up.
1506  * @note On older kernels input properties may not be defined and
1507  * libevdev_property_get_name() will always return NULL
1508  */
1509 const char* libevdev_property_get_name(unsigned int prop);
1510
1511 /**
1512  * @ingroup misc
1513  *
1514  * @param type The event type to return the maximum for (EV_ABS, EV_REL, etc.). No max is defined for
1515  * EV_SYN.
1516  *
1517  * @return The max value defined for the given event type, e.g. ABS_MAX for a type of EV_ABS, or -1
1518  * for an invalid type.
1519  *
1520  * @note The max value is compiled into libevdev. If the kernel changes the
1521  * max value, libevdev will not automatically pick these up.
1522  */
1523 int libevdev_event_type_get_max(unsigned int type);
1524
1525 /**
1526  * @ingroup misc
1527  *
1528  * Look up an event-type by its name. Event-types start with "EV_" followed by
1529  * the name (eg., "EV_ABS"). The "EV_" prefix must be included in the name. It
1530  * returns the constant assigned to the event-type or -1 if not found.
1531  *
1532  * @param name A non-NULL string describing an input-event type ("EV_KEY",
1533  * "EV_ABS", ...), zero-terminated.
1534  *
1535  * @return The given type constant for the passed name or -1 if not found.
1536  *
1537  * @note EV_MAX is also recognized.
1538  */
1539 int libevdev_event_type_from_name(const char *name);
1540
1541 /**
1542  * @ingroup misc
1543  *
1544  * Look up an event-type by its name. Event-types start with "EV_" followed by
1545  * the name (eg., "EV_ABS"). The "EV_" prefix must be included in the name. It
1546  * returns the constant assigned to the event-type or -1 if not found.
1547  *
1548  * @param name A non-NULL string describing an input-event type ("EV_KEY",
1549  * "EV_ABS", ...).
1550  * @param len The length of the passed string excluding any terminating 0
1551  * character.
1552  *
1553  * @return The given type constant for the passed name or -1 if not found.
1554  *
1555  * @note EV_MAX is also recognized.
1556  */
1557 int libevdev_event_type_from_name_n(const char *name, size_t len);
1558
1559 /**
1560  * @ingroup misc
1561  *
1562  * Look up an event-code by its type and name. Event-codes start with a fixed
1563  * prefix followed by their name (eg., "ABS_X"). The prefix must be included in
1564  * the name. It returns the constant assigned to the event-code or -1 if not
1565  * found.
1566  *
1567  * You have to pass the event-type where to look for the name. For instance, to
1568  * resolve "ABS_X" you need to pass EV_ABS as type and "ABS_X" as string.
1569  * Supported event-codes are codes starting with SYN_, KEY_, BTN_, REL_, ABS_,
1570  * MSC_, SND_, SW_, LED_, REP_, FF_.
1571  *
1572  * @param type The event type (EV_* constant) where to look for the name.
1573  * @param name A non-NULL string describing an input-event code ("KEY_A",
1574  * "ABS_X", "BTN_Y", ...), zero-terminated.
1575  *
1576  * @return The given code constant for the passed name or -1 if not found.
1577  */
1578 int libevdev_event_code_from_name(unsigned int type, const char *name);
1579
1580 /**
1581  * @ingroup misc
1582  *
1583  * Look up an event-code by its type and name. Event-codes start with a fixed
1584  * prefix followed by their name (eg., "ABS_X"). The prefix must be included in
1585  * the name. It returns the constant assigned to the event-code or -1 if not
1586  * found.
1587  *
1588  * You have to pass the event-type where to look for the name. For instance, to
1589  * resolve "ABS_X" you need to pass EV_ABS as type and "ABS_X" as string.
1590  * Supported event-codes are codes starting with SYN_, KEY_, BTN_, REL_, ABS_,
1591  * MSC_, SND_, SW_, LED_, REP_, FF_.
1592  *
1593  * @param type The event type (EV_* constant) where to look for the name.
1594  * @param name A non-NULL string describing an input-event code ("KEY_A",
1595  * "ABS_X", "BTN_Y", ...).
1596  * @param len The length of the passed string excluding any terminating 0
1597  * character.
1598  *
1599  * @return The given code constant for the passed name or -1 if not found.
1600  */
1601 int libevdev_event_code_from_name_n(unsigned int type, const char *name,
1602                                     size_t len);
1603
1604 /**
1605  * @ingroup bits
1606  *
1607  * Get the repeat delay and repeat period values for this device. This
1608  * function is a convenience function only, EV_REP is supported by
1609  * libevdev_get_event_value().
1610  *
1611  * @param dev The evdev device, already initialized with libevdev_set_fd()
1612  * @param delay If not null, set to the repeat delay value
1613  * @param period If not null, set to the repeat period value
1614  *
1615  * @return 0 on success, -1 if this device does not have repeat settings.
1616  *
1617  * @note This function is signal-safe
1618  *
1619  * @see libevdev_get_event_value
1620  */
1621 int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period);
1622
1623
1624 /********* DEPRECATED SECTION *********/
1625 #if defined(__GNUC__) && __GNUC__ >= 4
1626 #define LIBEVDEV_DEPRECATED __attribute__ ((deprecated))
1627 #else
1628 #define LIBEVDEV_DEPRECATED
1629 #endif
1630
1631 #ifdef __cplusplus
1632 }
1633 #endif
1634
1635 #endif /* LIBEVDEV_H */