Add a simple example to the documentation
[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 #include <config.h>
27 #include <linux/input.h>
28 #include <stdarg.h>
29
30 /**
31  * @mainpage
32  *
33  * **libevdev** is a library for handling evdev kernel devices. It abstracts
34  * the ioctls through type-safe interfaces and provides functions to change
35  * the appearance of the device.
36  *
37  * Handling events and SYN_DROPPED
38  * ===============================
39  *
40  * libevdev provides an interface for handling events, including most notably
41  * SYN_DROPPED events. SYN_DROPPED events are sent by the kernel when the
42  * process does not read events fast enough and the kernel is forced to drop
43  * some events. This causes the device to get out of sync with the process'
44  * view of it. libevdev handles this by telling the caller that a SYN_DROPPED
45  * has been received and that the state of the device is different to what is
46  * to be expected. It then provides the delta between the previous state and
47  * the actual state of the device as a set of events. See
48  * libevdev_next_event() for more information.
49  *
50  * Signal safety
51  * =============
52  *
53  * libevdev is signal-safe for the majority of its operations. Check the API
54  * documentation to make sure, unless explicitly stated a call is <b>not</b>
55  * signal safe.
56  *
57  * Device handling
58  * ===============
59  *
60  * libevdev does not attempt duplicate detection. Initializing two libevdev
61  * devices for the same fd is valid and behaves the same as for two different
62  * devices.
63  *
64  * libevdev does not handle the file descriptors directly, it merely uses
65  * them. The caller is responsible for opening the file descriptors, setting
66  * them to O_NONBLOCK and handling permissions.
67  *
68  * Where does libevdev sit?
69  * ========================
70  *
71  * libevdev is essentially a read(2) on steroids for /dev/input/eventX
72  * devices. It sits below the process that handles input events, in between
73  * the kernel and that process. In the simplest case, e.g. an evtest-like tool
74  * the stack would look like this:
75  *
76  *      kernel → libevdev → evtest
77  *
78  * For X.Org input modules, the stack would look like this:
79  *
80  *      kernel → libevdev → xf86-input-evdev → X server → X client
81  *
82  * For Weston/Wayland, the stack would look like this:
83  *
84  *      kernel → libevdev → Weston → Wayland client
85  *
86  * libevdev does **not** have knowledge of X clients or Wayland clients, it is
87  * too low in the stack.
88  *
89  * Example
90  * =======
91  * Below is a simple example that shows how libevdev could be used. This example
92  * opens a device, checks for relative axes and a left mouse button and if it
93  * finds them monitors the device to print the event.
94  *
95  *      struct libevdev *dev = NULL;
96  *      int fd;
97  *      int rc = 1;
98  *
99  *      fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
100  *      rc = libevdev_new_from_fd(fd, &dev);
101  *      if (rc < 0) {
102  *              fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
103  *              exit(1);
104  *      }
105  *      printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
106  *      printf("Input device ID: bus %#x vendor %#x product %#x\n",
107  *                      libevdev_get_bustype(dev),
108  *                      libevdev_get_vendor_id(dev),
109  *                      libevdev_get_product_id(dev));
110  *      if (!libevdev_has_event_type(dev, EV_REL) ||
111  *          !libevdev_has_event_code(dev, EV_KEY, BTN_LEFT)) {
112  *              printf("This device does not look like a mouse\n");
113  *              exit(1);
114  *      }
115  *
116  *      do {
117  *              struct input_event ev;
118  *              rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
119  *              if (rc == 0)
120  *                      printf("Event: %s %s %d\n",
121  *                                      libevdev_get_event_type_name(ev.type),
122  *                                      libevdev_get_event_code_name(ev.type, ev.code),
123  *                                      ev.value);
124  *      } while (rc == 1 || rc == 0 || rc == -EAGAIN);
125  *
126  * A more complete example is available with the libevdev-events tool here:
127  * https://github.com/whot/libevdev/blob/master/tools/libevdev-events.c
128  */
129
130 /**
131  * @defgroup init Initialization and setup
132  *
133  * Initialization, initial setup and file descriptor handling.
134  * These functions are the main entry points for users of libevdev, usually a
135  * caller will use this series of calls:
136  *
137  * @code
138  * struct libevdev *dev;
139  * int err;
140  *
141  * dev = libevdev_new();
142  * if (!dev)
143  *    return ENOSPC;
144
145  * err = libevdev_set_fd(dev, fd);
146  * if (err < 0) {
147  *      printf("Failed (errno %d): %s\n", -err, strerror(-err));
148  *
149  * libevdev_free(dev);
150  * @endcode
151  *
152  * libevdev_set_fd() is the central call and initializes the internal structs
153  * for the device at the given fd. libevdev functions will fail if called
154  * before libevdev_set_fd() unless documented otherwise.
155  */
156
157 /**
158  * @defgroup bits Querying device capabilities
159  *
160  * Abstraction functions to handle device capabilities, specificially
161  * device propeties such as the name of the device and the bits
162  * representing the events suppported by this device.
163  *
164  * The logical state returned may lag behind the physical state of the device.
165  * libevdev queries the device state on libevdev_set_fd() and then relies on
166  * the caller to parse events through libevdev_next_fd(). If a caller does not
167  * use libevdev_next_fd(), libevdev will not update the internal state of the
168  * device and thus returns outdated values.
169  */
170
171 /**
172  * @defgroup mt Multi-touch related functions
173  * Functions for querying multi-touch-related capabilities. MT devices
174  * following the kernel protocol B (using ABS_MT_SLOT) provide multiple touch
175  * points through so-called slots on the same axis. The slots are enumerated,
176  * a client reading from the device will first get an ABS_MT_SLOT event, then
177  * the values of axes changed in this slot. Multiple slots may be provided in
178  * before an EV_SYN event.
179  *
180  * As with @ref bits, the logical state of the device as seen by the library
181  * depends on the caller using libevdev_next_event().
182  */
183
184 /**
185  * @defgroup kernel Modifying the appearance or capabilities of the device
186  *
187  * Modifying the set of events reported by this device. By default, the
188  * libevdev device mirrors the kernel device, enabling only those bits
189  * exported by the kernel. This set of functions enable or disable bits as
190  * seen from the caller.
191  *
192  * Enabling an event type or code does not affect event reporting - a
193  * software-enabled event will not be generated by the physical hardware.
194  * Disabling an event will prevent libevdev from routing such events to the
195  * caller. Enabling and disabling event types and codes is at the library
196  * level and thus only affects the caller.
197  *
198  * If an event type or code is enabled at kernel-level, future users of this
199  * device will see this event enabled. Currently there is no option of
200  * disabling an event type or code at kernel-level.
201  */
202
203 /**
204  * @defgroup misc Miscellaneous helper functions
205  *
206  * Functions for printing or querying event ranges. The list of names is
207  * compiled into libevdev and will not change when the kernel changes. Adding
208  * or removing names requires a re-compilation of libevdev. Likewise, the max
209  * for each event type is compiled in and does not check the underlying
210  * kernel.
211  */
212
213 /**
214  * @defgroup events Event handling
215  *
216  * Functions to handle events and fetch the current state of the event. Generally,
217  * libevdev updates its internal state as the event is processed and forwarded
218  * to the caller. Thus, the libevdev state of the device should always be identical
219  * to the caller's state. It may however lag behind the actual state of the device.
220  */
221
222 /**
223  * @ingroup init
224  *
225  * Opaque struct representing an evdev device.
226  */
227 struct libevdev;
228
229 enum EvdevReadFlags {
230         LIBEVDEV_READ_SYNC              = 1, /**< Process data in sync mode */
231         LIBEVDEV_READ_NORMAL            = 2, /**< Process data in normal mode */
232         LIBEVDEV_FORCE_SYNC             = 4, /**< Pretend the next event is a SYN_DROPPED. There is
233                                                   no reason to ever use this except for
234                                                   automated tests, so don't. */
235         LIBEVDEV_READ_BLOCKING          = 8, /**< The fd is not in O_NONBLOCK and a read may block */
236 };
237
238 /**
239  * @ingroup init
240  *
241  * Initialize a new libevdev device. This function only allocates the
242  * required memory and initializes the struct to sane default values.
243  * To actually hook up the device to a kernel device, use
244  * libevdev_set_fd().
245  *
246  * Memory allocated through libevdev_new() must be released by the
247  * caller with libevdev_free().
248  *
249  * @see libevdev_set_fd
250  * @see libevdev_free
251  */
252 struct libevdev* libevdev_new(void);
253
254 /**
255  * @ingroup init
256  *
257  * Initialize a new libevdev device from the given fd.
258  *
259  * This is a shortcut for
260  *
261  * @code
262  * int err;
263  * struct libevdev *dev = libevdev_new();
264  * err = libevdev_set_fd(dev, fd);
265  * @endcode
266  *
267  * @param fd A file descriptor to the device in O_RDWR or O_RDONLY mode.
268  * @param[out] dev The newly initialized evdev device.
269  *
270  * @return On success, zero is returned and dev is set to the newly
271  * allocated struct. On failure, a negative errno is returned and the value
272  * of dev is undefined.
273  *
274  * @see libevdev_free
275  */
276 int libevdev_new_from_fd(int fd, struct libevdev **dev);
277
278 /**
279  * @ingroup init
280  *
281  * Clean up and free the libevdev struct. After completion, the <code>struct
282  * libevdev</code> is invalid and must not be used.
283  *
284  * @param dev The evdev device
285  *
286  * @note This function may be called before libevdev_set_fd().
287  */
288 void libevdev_free(struct libevdev *dev);
289
290 /**
291  * Logging function called by library-internal logging.
292  * This function is expected to treat it's input like printf would.
293  *
294  * @param format printf-style format string
295  * @param args List of arguments
296  *
297  * @see libevdev_set_log_handler
298  */
299 typedef void (*libevdev_log_func_t)(const char *format, va_list args);
300
301 /**
302  * Set a printf-style logging handler for library-internal logging. The default
303  * logging function is a noop.
304  *
305  * @param dev The evdev device
306  * @param logfunc The logging function for this device. If NULL, the current
307  * logging function is unset.
308  *
309  * @note This function may be called before libevdev_set_fd().
310  */
311 void libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc);
312
313
314 enum EvdevGrabModes {
315         LIBEVDEV_GRAB = 3,
316         LIBEVDEV_UNGRAB = 4,
317 };
318
319 /**
320  * Grab or ungrab the device through a kernel EVIOCGRAB. This prevents other
321  * clients (including kernel-internal ones such as rfkill) from receiving
322  * events from this device.
323  *
324  * This is generally a bad idea. Don't do this.
325  *
326  * Grabbing an already grabbed device, or ungrabbing an ungrabbed device is
327  * a noop and always succeeds.
328  *
329  * @param dev The evdev device, already initialized with libevdev_set_fd()
330  * @param grab If true, grab the device. Otherwise ungrab the device.
331  *
332  * @return 0 if the device was successfull grabbed or ungrabbed, or a
333  * negative errno in case of failure.
334  */
335 int libevdev_grab(struct libevdev *dev, int grab);
336
337 /**
338  * @ingroup init
339  *
340  * Set the fd for this struct and initialize internal data.
341  * The fd must be in O_RDONLY or O_RDWR mode.
342  *
343  * This function may only be called once per device. If the device changed and
344  * you need to re-read a device, use libevdev_free() and libevdev_new(). If
345  * you need to change the fd after closing and re-opening the same device, use
346  * libevdev_change_fd().
347  *
348  * Unless otherwise specified, libevdev function behavior is undefined until
349  * a successfull call to libevdev_set_fd().
350  *
351  * @param dev The evdev device
352  * @param fd The file descriptor for the device
353  *
354  * @return 0 on success, or a negative error code on failure
355  *
356  * @see libevdev_change_fd
357  * @see libevdev_new
358  * @see libevdev_free
359  */
360 int libevdev_set_fd(struct libevdev* dev, int fd);
361
362 /**
363  * @ingroup init
364  *
365  * Change the fd for this device, without re-reading the actual device. If the fd
366  * changes after initializing the device, for example after a VT-switch in the
367  * X.org X server, this function updates the internal fd to the newly opened.
368  * No check is made that new fd points to the same device. If the device has
369  * changed, libevdev's behavior is undefined.
370  *
371  * The fd may be open in O_RDONLY or O_RDWR.
372  *
373  * It is an error to call this function before calling libevdev_set_fd().
374  *
375  * @param dev The evdev device, already initialized with libevdev_set_fd()
376  * @param fd The new fd
377  *
378  * @return 0 on success, or -1 on failure.
379  *
380  * @see libevdev_set_fd
381  */
382 int libevdev_change_fd(struct libevdev* dev, int fd);
383
384 /**
385  * @param dev The evdev device
386  *
387  * @return The previously set fd, or -1 if none had been set previously.
388  * @note This function may be called before libevdev_set_fd().
389  */
390 int libevdev_get_fd(const struct libevdev* dev);
391
392 /**
393  * @ingroup events
394  *
395  * Get the next event from the device. This function operates in two different
396  * modes: normal mode or sync mode.
397  *
398  * In normal mode, this function returns 0 and returns the event in the
399  * parameter ev. If no events are available at this time, it returns -EAGAIN
400  * and ev is undefined.
401  *
402  * If a SYN_DROPPED is read from the device, this function returns 1. The
403  * caller should now call this function with the LIBEVDEV_READ_SYNC flag set,
404  * to get the set of events that make up the device state delta. This function
405  * returns 1 for each event part of that delta, until it returns -EAGAIN once
406  * all events have been synced.
407  *
408  * If a device needs to be synced by the caller but the caller does not call
409  * with the LIBEVDEV_READ_SYNC flag set, all events from the diff are dropped
410  * and event processing continues as normal.
411  *
412  * @param dev The evdev device, already initialized with libevdev_set_fd()
413  * @param flags Set of flags to determine behaviour. If LIBEVDEV_READ_NORMAL
414  * is set, the next event is read in normal mode. If LIBEVDEV_READ_SYNC is
415  * set, the next event is read in sync mode.
416  * @param ev On success, set to the current event.
417  * @return On failure, a negative errno is returned.
418  * @retval 0 One or more events where read of the device
419  * @retval -EAGAIN No events are currently available on the device
420  * @retval 1 A SYN_DROPPED event was received, or a synced event was
421  * returned.
422  *
423  * @note This function is signal-safe.
424  */
425 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev);
426
427 /**
428  * @ingroup bits
429  *
430  * @param dev The evdev device, already initialized with libevdev_set_fd()
431  *
432  * @return The device name as read off the kernel device. The name is never
433  * NULL but it may be the empty string.
434  *
435  * @note This function is signal-safe.
436  */
437 const char* libevdev_get_name(const struct libevdev *dev);
438
439 /**
440  * @ingroup bits
441  *
442  * Virtual devices such as uinput devices have no phys location.
443  *
444  * @param dev The evdev device, already initialized with libevdev_set_fd()
445  *
446  * @return The physical location of this device, or NULL if there is none
447  *
448  * @note This function is signal safe.
449  */
450 const char * libevdev_get_phys(const struct libevdev *dev);
451
452 /**
453  * @ingroup bits
454  *
455  * @param dev The evdev device, already initialized with libevdev_set_fd()
456  *
457  * @return The unique identifier for this device, or NULL if there is none
458  *
459  * @note This function is signal safe.
460  */
461 const char * libevdev_get_uniq(const struct libevdev *dev);
462
463 /**
464  * @ingroup bits
465  *
466  * @param dev The evdev device, already initialized with libevdev_set_fd()
467  *
468  * @return The device's product ID
469  *
470  * @note This function is signal-safe.
471  */
472 int libevdev_get_product_id(const struct libevdev *dev);
473
474 /**
475  * @ingroup bits
476  *
477  * @param dev The evdev device, already initialized with libevdev_set_fd()
478  *
479  * @return The device's vendor ID
480  *
481  * @note This function is signal-safe.
482  */
483 int libevdev_get_vendor_id(const struct libevdev *dev);
484
485 /**
486  * @ingroup bits
487  *
488  * @param dev The evdev device, already initialized with libevdev_set_fd()
489  *
490  * @return The device's bus type
491  *
492  * @note This function is signal-safe.
493  */
494 int libevdev_get_bustype(const struct libevdev *dev);
495
496 /**
497  * @ingroup bits
498  *
499  * @param dev The evdev device, already initialized with libevdev_set_fd()
500  *
501  * @return The device's firmware version
502  *
503  * @note This function is signal-safe.
504  */
505 int libevdev_get_version(const struct libevdev *dev);
506
507 /**
508  * @ingroup bits
509  *
510  * @param dev The evdev device, already initialized with libevdev_set_fd()
511  *
512  * @return The driver version for this device
513  *
514  * @note This function is signal-safe.
515  */
516 int libevdev_get_driver_version(const struct libevdev *dev);
517
518 /**
519  * @ingroup bits
520  *
521  * @param dev The evdev device, already initialized with libevdev_set_fd()
522  * @param prop The input property to query for, one of INPUT_PROP_...
523  *
524  * @return 1 if the device provides this input property, or 0 otherwise.
525  *
526  * @note This function is signal-safe
527  */
528 int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
529
530 /**
531  * @ingroup bits
532  *
533  * @param dev The evdev device, already initialized with libevdev_set_fd()
534  * @param type The event type to query for, one of EV_SYN, EV_REL, etc.
535  *
536  * @return 1 if the device supports this event type, or 0 otherwise.
537  *
538  * @note This function is signal-safe.
539  */
540 int libevdev_has_event_type(const struct libevdev *dev, unsigned int type);
541
542 /**
543  * @ingroup bits
544  *
545  * @param dev The evdev device, already initialized with libevdev_set_fd()
546  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
547  * @param code The event code to query for, one of ABS_X, REL_X, etc.
548  *
549  * @return 1 if the device supports this event type and code, or 0 otherwise.
550  *
551  * @note This function is signal-safe.
552  */
553 int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code);
554
555 /**
556  * @ingroup bits
557  *
558  * Get the minimum axis value for the given axis, as advertised by the kernel.
559  *
560  * @param dev The evdev device, already initialized with libevdev_set_fd()
561  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
562  *
563  * @return axis minimum for the given axis or 0 if the axis is invalid
564  */
565 int libevdev_get_abs_min(const struct libevdev *dev, unsigned int code);
566 /**
567  * @ingroup bits
568  *
569  * Get the maximum axis value for the given axis, as advertised by the kernel.
570  *
571  * @param dev The evdev device, already initialized with libevdev_set_fd()
572  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
573  *
574  * @return axis maximum for the given axis or 0 if the axis is invalid
575  */
576 int libevdev_get_abs_max(const struct libevdev *dev, unsigned int code);
577 /**
578  * @ingroup bits
579  *
580  * Get the axis fuzz for the given axis, as advertised by the kernel.
581  *
582  * @param dev The evdev device, already initialized with libevdev_set_fd()
583  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
584  *
585  * @return axis fuzz for the given axis or 0 if the axis is invalid
586  */
587 int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code);
588 /**
589  * @ingroup bits
590  *
591  * Get the axis flat for the given axis, as advertised by the kernel.
592  *
593  * @param dev The evdev device, already initialized with libevdev_set_fd()
594  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
595  *
596  * @return axis flat for the given axis or 0 if the axis is invalid
597  */
598 int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code);
599 /**
600  * @ingroup bits
601  *
602  * Get the axis resolution for the given axis, as advertised by the kernel.
603  *
604  * @param dev The evdev device, already initialized with libevdev_set_fd()
605  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
606  *
607  * @return axis resolution for the given axis or 0 if the axis is invalid
608  */
609 int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code);
610
611 /**
612  * @ingroup bits
613  *
614  * Get the axis info for the given axis, as advertised by the kernel.
615  *
616  * @param dev The evdev device, already initialized with libevdev_set_fd()
617  * @param code The EV_ABS event code to query for, one of ABS_X, ABS_Y, etc.
618  *
619  * @return The input_absinfo for the given code, or NULL if the device does
620  * not support this event code.
621  */
622 const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, unsigned int code);
623
624 /**
625  * @ingroup bits
626  *
627  * Behaviour of this function is undefined if the device does not provide
628  * the event.
629  *
630  * @param dev The evdev device, already initialized with libevdev_set_fd()
631  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
632  * @param code The event code to query for, one of ABS_X, REL_X, etc.
633  *
634  * @return The current value of the event.
635  *
636  * @note This function is signal-safe.
637  * @note The value for ABS_MT_ events is undefined, use
638  * libevdev_get_slot_value() instead
639  *
640  * @see libevdev_get_slot_value
641  */
642 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
643
644 /**
645  * @ingroup bits
646  *
647  * Fetch the current value of the event type. This is a shortcut for
648  *
649  * @code
650  *   if (libevdev_has_event_type(dev, t) && libevdev_has_event_code(dev, t, c))
651  *       val = libevdev_get_event_value(dev, t, c);
652  * @endcode
653  *
654  * @param dev The evdev device, already initialized with libevdev_set_fd()
655  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
656  * @param code The event code to query for, one of ABS_X, REL_X, etc.
657  * @param[out] value The current value of this axis returned.
658  *
659  * @return If the device supports this event type and code, the return value is
660  * non-zero and value is set to the current value of this axis. Otherwise,
661  * zero is returned and value is unmodified.
662  *
663  * @note This function is signal-safe.
664  * @note The value for ABS_MT_ events is undefined, use
665  * libevdev_fetch_slot_value() instead
666  *
667  * @see libevdev_fetch_slot_value
668  */
669 int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value);
670
671 /**
672  * @ingroup mt
673  *
674  * Return the current value of the code for the given slot.
675  *
676  * The return value is undefined for a slot exceeding the available slots on
677  * the device, for a code that is not in the permitted ABS_MT range or for a
678  * device that does not have slots.
679  *
680  * @param dev The evdev device, already initialized with libevdev_set_fd()
681  * @param slot The numerical slot number, must be smaller than the total number
682  * of slots on this * device
683  * @param code The event code to query for, one of ABS_MT_POSITION_X, etc.
684  *
685  * @note This function is signal-safe.
686  * @note The value for events other than ABS_MT_ is undefined, use
687  * libevdev_fetch_value() instead
688  *
689  * @see libevdev_get_value
690  */
691 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
692
693 /**
694  * @ingroup mt
695  *
696  * Fetch the current value of the code for the given slot. This is a shortcut for
697  *
698  * @code
699  *   if (libevdev_has_event_type(dev, EV_ABS) &&
700  *       libevdev_has_event_code(dev, EV_ABS, c) &&
701  *       slot < device->number_of_slots)
702  *       val = libevdev_get_slot_value(dev, slot, c);
703  * @endcode
704  *
705  * @param dev The evdev device, already initialized with libevdev_set_fd()
706  * @param slot The numerical slot number, must be smaller than the total number
707  * of slots on this * device
708  * @param[out] value The current value of this axis returned.
709  *
710  * @param code The event code to query for, one of ABS_MT_POSITION_X, etc.
711  * @return If the device supports this event code, the return value is
712  * non-zero and value is set to the current value of this axis. Otherwise, or
713  * if the event code is not an ABS_MT_* event code, zero is returned and value
714  * is unmodified.
715  *
716  * @note This function is signal-safe.
717  */
718 int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value);
719
720 /**
721  * @ingroup mt
722  *
723  * Get the number of slots supported by this device.
724  *
725  * @param dev The evdev device, already initialized with libevdev_set_fd()
726  *
727  * @return The number of slots supported, or -1 if the device does not provide
728  * any slots
729  *
730  * @note A device may provide ABS_MT_SLOT but a total number of 0 slots. Hence
731  * the return value of -1 for "device does not provide slots at all"
732  */
733 int libevdev_get_num_slots(const struct libevdev *dev);
734
735 /**
736  * @ingroup mt
737  *
738  * Get the currently active slot. This may differ from the value
739  * an ioctl may return at this time as events may have been read off the fd
740  * since changing the slot value but those events are still in the buffer
741  * waiting to be processed. The returned value is the value a caller would
742  * see if it were to process events manually one-by-one.
743  *
744  * @param dev The evdev device, already initialized with libevdev_set_fd()
745  *
746  * @return the currently active slot (logically)
747  */
748 int libevdev_get_current_slot(const struct libevdev *dev);
749
750 /**
751  * @ingroup kernel
752  *
753  * Forcibly enable an event type on this device, even if the underlying
754  * device does not support it. While this cannot make the device actually
755  * report such events, it will now return true for libevdev_has_event_type().
756  *
757  * This is a local modification only affecting only this representation of
758  * this device.
759  *
760  * @param dev The evdev device, already initialized with libevdev_set_fd()
761  * @param type The event type to enable (EV_ABS, EV_KEY, ...)
762  *
763  * @return 0 on success or -1 otherwise
764  *
765  * @see libevdev_has_event_type
766  */
767 int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
768
769 /**
770  * @ingroup kernel
771  *
772  * Forcibly disable an event type on this device, even if the underlying
773  * device provides it, effectively muting all keys or axes. libevdev will
774  * filter any events matching this type and none will reach the caller.
775  * libevdev_has_event_type() will return false for this type.
776  *
777  * In most cases, a caller likely only wants to disable a single code, not
778  * the whole type. Use libevdev_disable_event_code() for that.
779  *
780  * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
781  * It hurts.
782  *
783  * This is a local modification only affecting only this representation of
784  * this device.
785  *
786  * @param dev The evdev device, already initialized with libevdev_set_fd()
787  * @param type The event type to disable (EV_ABS, EV_KEY, ...)
788  *
789  * @return 0 on success or -1 otherwise
790  *
791  * @see libevdev_has_event_type
792  * @see libevdev_disable_event_type
793  */
794 int libevdev_disable_event_type(struct libevdev *dev, unsigned int type);
795
796 /**
797  * @ingroup kernel
798  *
799  * Forcibly enable an event type on this device, even if the underlying
800  * device does not support it. While this cannot make the device actually
801  * report such events, it will now return true for libevdev_has_event_code().
802  *
803  * The last argument depends on the type and code:
804  * - If type is EV_ABS, data must be a pointer to a struct input_absinfo
805  * containing the data for this axis.
806  * - For all other types, the argument must be NULL.
807  *
808  * This function calls libevdev_enable_event_type() if necessary.
809  *
810  * This is a local modification only affecting only this representation of
811  * this device.
812  *
813  * @param dev The evdev device, already initialized with libevdev_set_fd()
814  * @param type The event type to enable (EV_ABS, EV_KEY, ...)
815  * @param code The event code to enable (ABS_X, REL_X, etc.)
816  * @param data If type is EV_ABS, data points to a struct input_absinfo. Otherwise, data must be
817  * NULL
818  *
819  * @return 0 on success or -1 otherwise
820  *
821  * @see libevdev_enable_event_type
822  */
823 int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data);
824
825 /**
826  * @ingroup kernel
827  *
828  * Forcibly disable an event code on this device, even if the underlying
829  * device provides it, effectively muting this key or axis. libevdev will
830  * filter any events matching this type and code and none will reach the
831  * caller.
832  * libevdev_has_event_code() will return false for this code combination.
833  *
834  * Disabling all event codes for a given type will not disable the event
835  * type. Use libevdev_disable_event_type() for that.
836  *
837  * This is a local modification only affecting only this representation of
838  * this device.
839  *
840  * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
841  * It hurts.
842  *
843  * @param dev The evdev device, already initialized with libevdev_set_fd()
844  * @param type The event type to disable (EV_ABS, EV_KEY, ...)
845  * @param code The event code to disable (ABS_X, REL_X, etc.)
846  *
847  * @return 0 on success or -1 otherwise
848  *
849  * @see libevdev_has_event_code
850  * @see libevdev_disable_event_type
851  */
852 int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code);
853
854 /**
855  * @ingroup kernel
856  *
857  * Set the device's EV_ABS axis to the value defined in the abs
858  * parameter. This will be written to the kernel.
859  *
860  * @param dev The evdev device, already initialized with libevdev_set_fd()
861  * @param code The EV_ABS event code to modify, one of ABS_X, ABS_Y, etc.
862  * @param abs Axis info to set the kernel axis to
863  *
864  * @return zero on success, or a negative errno on failure
865  *
866  * @see libevdev_enable_event_code
867  */
868 int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
869
870 /**
871  * @ingroup misc
872  *
873  * @param type The event type to return the name for.
874  *
875  * @return The name of the given event type (e.g. EV_ABS) or NULL for an
876  * invalid type
877  *
878  * @note The list of names is compiled into libevdev. If the kernel adds new
879  * defines for new properties libevdev will not automatically pick these up.
880  */
881 const char * libevdev_get_event_type_name(unsigned int type);
882 /**
883  * @ingroup misc
884  *
885  * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
886  * @param code The event code to return the name for (e.g. ABS_X)
887  *
888  * @return The name of the given event code (e.g. ABS_X) or NULL for an
889  * invalid type or code
890  *
891  * @note The list of names is compiled into libevdev. If the kernel adds new
892  * defines for new properties libevdev will not automatically pick these up.
893  */
894 const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
895
896 /**
897  * @ingroup misc
898  *
899  * @param prop The input prop to return the name for (e.g. INPUT_PROP_BUTTONPAD)
900  *
901  * @return The name of the given input prop (e.g. INPUT_PROP_BUTTONPAD) or NULL for an
902  * invalid property
903  *
904  * @note The list of names is compiled into libevdev. If the kernel adds new
905  * defines for new properties libevdev will not automatically pick these up.
906  * @note On older kernels input properties may not be defined and
907  * libevdev_get_input_prop_name() will always return NULL
908  */
909 const char * libevdev_get_input_prop_name(unsigned int prop);
910
911 /**
912  * @ingroup misc
913  *
914  * @param type The event type to return the maximum for (EV_ABS, EV_REL, etc.). No max is defined for
915  * EV_SYN.
916  *
917  * @return The max value defined for the given event type, e.g. ABS_MAX for a type of EV_ABS, or -1
918  * for an invalid type.
919  *
920  * @note The max value is compiled into libevdev. If the kernel changes the
921  * max value, libevdev will not automatically pick these up.
922  */
923 int libevdev_get_event_type_max(unsigned int type);
924
925 /**
926  * @ingroup bits
927  *
928  * Get the repeat delay and repeat period values for this device.
929  *
930  * @param dev The evdev device, already initialized with libevdev_set_fd()
931  * @param delay If not null, set to the repeat delay value
932  * @param period If not null, set to the repeat period value
933  *
934  * @return 0 on success, -1 if this device does not have repeat settings.
935  *
936  * @note This function is signal-safe
937  */
938 int libevdev_get_repeat(struct libevdev *dev, int *delay, int *period);
939
940 #endif /* libevdev_H */