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