2 * Copyright © 2013 Red Hat, Inc.
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.
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
27 #include <linux/input.h>
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.
37 * Handling events and SYN_DROPPED
38 * ===============================
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.
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>
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
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.
68 * Where does libevdev sit?
69 * ========================
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:
76 * kernel → libevdev → evtest
78 * For X.Org input modules, the stack would look like this:
80 * kernel → libevdev → xf86-input-evdev → X server → X client
82 * For Weston/Wayland, the stack would look like this:
84 * kernel → libevdev → Weston → Wayland client
86 * libevdev does **not** have knowledge of X clients or Wayland clients, it is
87 * too low in the stack.
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.
95 * struct libevdev *dev = NULL;
99 * fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK);
100 * rc = libevdev_new_from_fd(fd, &dev);
102 * fprintf(stderr, "Failed to init libevdev (%s)\n", strerror(-rc));
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");
117 * struct input_event ev;
118 * rc = libevdev_next_event(dev, LIBEVDEV_READ_NORMAL, &ev);
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),
124 * } while (rc == 1 || rc == 0 || rc == -EAGAIN);
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
131 * @defgroup init Initialization and setup
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:
138 * struct libevdev *dev;
141 * dev = libevdev_new();
145 * err = libevdev_set_fd(dev, fd);
147 * printf("Failed (errno %d): %s\n", -err, strerror(-err));
149 * libevdev_free(dev);
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.
158 * @defgroup bits Querying device capabilities
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.
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.
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.
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().
185 * @defgroup kernel Modifying the appearance or capabilities of the device
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.
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.
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.
204 * @defgroup misc Miscellaneous helper functions
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
214 * @defgroup events Event handling
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.
225 * Opaque struct representing an evdev device.
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 */
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
246 * Memory allocated through libevdev_new() must be released by the
247 * caller with libevdev_free().
249 * @see libevdev_set_fd
252 struct libevdev* libevdev_new(void);
257 * Initialize a new libevdev device from the given fd.
259 * This is a shortcut for
263 * struct libevdev *dev = libevdev_new();
264 * err = libevdev_set_fd(dev, fd);
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.
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.
276 int libevdev_new_from_fd(int fd, struct libevdev **dev);
281 * Clean up and free the libevdev struct. After completion, the <code>struct
282 * libevdev</code> is invalid and must not be used.
284 * @param dev The evdev device
286 * @note This function may be called before libevdev_set_fd().
288 void libevdev_free(struct libevdev *dev);
291 * Logging function called by library-internal logging.
292 * This function is expected to treat it's input like printf would.
294 * @param format printf-style format string
295 * @param args List of arguments
297 * @see libevdev_set_log_handler
299 typedef void (*libevdev_log_func_t)(const char *format, va_list args);
302 * Set a printf-style logging handler for library-internal logging. The default
303 * logging function is a noop.
305 * @param dev The evdev device
306 * @param logfunc The logging function for this device. If NULL, the current
307 * logging function is unset.
309 * @note This function may be called before libevdev_set_fd().
311 void libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc);
314 enum EvdevGrabModes {
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.
324 * This is generally a bad idea. Don't do this.
326 * Grabbing an already grabbed device, or ungrabbing an ungrabbed device is
327 * a noop and always succeeds.
329 * @param dev The evdev device, already initialized with libevdev_set_fd()
330 * @param grab If true, grab the device. Otherwise ungrab the device.
332 * @return 0 if the device was successfull grabbed or ungrabbed, or a
333 * negative errno in case of failure.
335 int libevdev_grab(struct libevdev *dev, int grab);
340 * Set the fd for this struct and initialize internal data.
341 * The fd must be in O_RDONLY or O_RDWR mode.
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().
348 * Unless otherwise specified, libevdev function behavior is undefined until
349 * a successfull call to libevdev_set_fd().
351 * @param dev The evdev device
352 * @param fd The file descriptor for the device
354 * @return 0 on success, or a negative error code on failure
356 * @see libevdev_change_fd
360 int libevdev_set_fd(struct libevdev* dev, int fd);
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.
371 * The fd may be open in O_RDONLY or O_RDWR.
373 * It is an error to call this function before calling libevdev_set_fd().
375 * @param dev The evdev device, already initialized with libevdev_set_fd()
376 * @param fd The new fd
378 * @return 0 on success, or -1 on failure.
380 * @see libevdev_set_fd
382 int libevdev_change_fd(struct libevdev* dev, int fd);
385 * @param dev The evdev device
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().
390 int libevdev_get_fd(const struct libevdev* dev);
395 * Get the next event from the device. This function operates in two different
396 * modes: normal mode or sync mode.
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.
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.
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.
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
423 * @note This function is signal-safe.
425 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev);
430 * @param dev The evdev device, already initialized with libevdev_set_fd()
432 * @return The device name as read off the kernel device. The name is never
433 * NULL but it may be the empty string.
435 * @note This function is signal-safe.
437 const char* libevdev_get_name(const struct libevdev *dev);
442 * Virtual devices such as uinput devices have no phys location.
444 * @param dev The evdev device, already initialized with libevdev_set_fd()
446 * @return The physical location of this device, or NULL if there is none
448 * @note This function is signal safe.
450 const char * libevdev_get_phys(const struct libevdev *dev);
455 * @param dev The evdev device, already initialized with libevdev_set_fd()
457 * @return The unique identifier for this device, or NULL if there is none
459 * @note This function is signal safe.
461 const char * libevdev_get_uniq(const struct libevdev *dev);
466 * @param dev The evdev device, already initialized with libevdev_set_fd()
468 * @return The device's product ID
470 * @note This function is signal-safe.
472 int libevdev_get_product_id(const struct libevdev *dev);
477 * @param dev The evdev device, already initialized with libevdev_set_fd()
479 * @return The device's vendor ID
481 * @note This function is signal-safe.
483 int libevdev_get_vendor_id(const struct libevdev *dev);
488 * @param dev The evdev device, already initialized with libevdev_set_fd()
490 * @return The device's bus type
492 * @note This function is signal-safe.
494 int libevdev_get_bustype(const struct libevdev *dev);
499 * @param dev The evdev device, already initialized with libevdev_set_fd()
501 * @return The device's firmware version
503 * @note This function is signal-safe.
505 int libevdev_get_version(const struct libevdev *dev);
510 * @param dev The evdev device, already initialized with libevdev_set_fd()
512 * @return The driver version for this device
514 * @note This function is signal-safe.
516 int libevdev_get_driver_version(const struct libevdev *dev);
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_...
524 * @return 1 if the device provides this input property, or 0 otherwise.
526 * @note This function is signal-safe
528 int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
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.
536 * @return 1 if the device supports this event type, or 0 otherwise.
538 * @note This function is signal-safe.
540 int libevdev_has_event_type(const struct libevdev *dev, unsigned int type);
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.
549 * @return 1 if the device supports this event type and code, or 0 otherwise.
551 * @note This function is signal-safe.
553 int libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code);
558 * Get the minimum axis value for the given axis, as advertised by the kernel.
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.
563 * @return axis minimum for the given axis or 0 if the axis is invalid
565 int libevdev_get_abs_min(const struct libevdev *dev, unsigned int code);
569 * Get the maximum axis value for the given axis, as advertised by the kernel.
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.
574 * @return axis maximum for the given axis or 0 if the axis is invalid
576 int libevdev_get_abs_max(const struct libevdev *dev, unsigned int code);
580 * Get the axis fuzz for the given axis, as advertised by the kernel.
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.
585 * @return axis fuzz for the given axis or 0 if the axis is invalid
587 int libevdev_get_abs_fuzz(const struct libevdev *dev, unsigned int code);
591 * Get the axis flat for the given axis, as advertised by the kernel.
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.
596 * @return axis flat for the given axis or 0 if the axis is invalid
598 int libevdev_get_abs_flat(const struct libevdev *dev, unsigned int code);
602 * Get the axis resolution for the given axis, as advertised by the kernel.
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.
607 * @return axis resolution for the given axis or 0 if the axis is invalid
609 int libevdev_get_abs_resolution(const struct libevdev *dev, unsigned int code);
614 * Get the axis info for the given axis, as advertised by the kernel.
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.
619 * @return The input_absinfo for the given code, or NULL if the device does
620 * not support this event code.
622 const struct input_absinfo* libevdev_get_abs_info(const struct libevdev *dev, unsigned int code);
627 * Behaviour of this function is undefined if the device does not provide
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.
634 * @return The current value of the event.
636 * @note This function is signal-safe.
637 * @note The value for ABS_MT_ events is undefined, use
638 * libevdev_get_slot_value() instead
640 * @see libevdev_get_slot_value
642 int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
647 * Fetch the current value of the event type. This is a shortcut for
650 * if (libevdev_has_event_type(dev, t) && libevdev_has_event_code(dev, t, c))
651 * val = libevdev_get_event_value(dev, t, c);
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.
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.
663 * @note This function is signal-safe.
664 * @note The value for ABS_MT_ events is undefined, use
665 * libevdev_fetch_slot_value() instead
667 * @see libevdev_fetch_slot_value
669 int libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value);
674 * Return the current value of the code for the given slot.
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.
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.
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
689 * @see libevdev_get_value
691 int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
696 * Fetch the current value of the code for the given slot. This is a shortcut for
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);
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.
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
716 * @note This function is signal-safe.
718 int libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value);
723 * Get the number of slots supported by this device.
725 * @param dev The evdev device, already initialized with libevdev_set_fd()
727 * @return The number of slots supported, or -1 if the device does not provide
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"
733 int libevdev_get_num_slots(const struct libevdev *dev);
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.
744 * @param dev The evdev device, already initialized with libevdev_set_fd()
746 * @return the currently active slot (logically)
748 int libevdev_get_current_slot(const struct libevdev *dev);
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().
757 * This is a local modification only affecting only this representation of
760 * @param dev The evdev device, already initialized with libevdev_set_fd()
761 * @param type The event type to enable (EV_ABS, EV_KEY, ...)
763 * @return 0 on success or -1 otherwise
765 * @see libevdev_has_event_type
767 int libevdev_enable_event_type(struct libevdev *dev, unsigned int type);
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.
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.
780 * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
783 * This is a local modification only affecting only this representation of
786 * @param dev The evdev device, already initialized with libevdev_set_fd()
787 * @param type The event type to disable (EV_ABS, EV_KEY, ...)
789 * @return 0 on success or -1 otherwise
791 * @see libevdev_has_event_type
792 * @see libevdev_disable_event_type
794 int libevdev_disable_event_type(struct libevdev *dev, unsigned int type);
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().
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.
808 * This function calls libevdev_enable_event_type() if necessary.
810 * This is a local modification only affecting only this representation of
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
819 * @return 0 on success or -1 otherwise
821 * @see libevdev_enable_event_type
823 int libevdev_enable_event_code(struct libevdev *dev, unsigned int type, unsigned int code, const void *data);
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
832 * libevdev_has_event_code() will return false for this code combination.
834 * Disabling all event codes for a given type will not disable the event
835 * type. Use libevdev_disable_event_type() for that.
837 * This is a local modification only affecting only this representation of
840 * Disabling EV_SYN will not work. Don't shoot yourself in the foot.
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.)
847 * @return 0 on success or -1 otherwise
849 * @see libevdev_has_event_code
850 * @see libevdev_disable_event_type
852 int libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code);
857 * Set the device's EV_ABS axis to the value defined in the abs
858 * parameter. This will be written to the kernel.
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
864 * @return zero on success, or a negative errno on failure
866 * @see libevdev_enable_event_code
868 int libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs);
873 * @param type The event type to return the name for.
875 * @return The name of the given event type (e.g. EV_ABS) or NULL for an
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.
881 const char * libevdev_get_event_type_name(unsigned int type);
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)
888 * @return The name of the given event code (e.g. ABS_X) or NULL for an
889 * invalid type or code
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.
894 const char * libevdev_get_event_code_name(unsigned int type, unsigned int code);
899 * @param prop The input prop to return the name for (e.g. INPUT_PROP_BUTTONPAD)
901 * @return The name of the given input prop (e.g. INPUT_PROP_BUTTONPAD) or NULL for an
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
909 const char * libevdev_get_input_prop_name(unsigned int prop);
914 * @param type The event type to return the maximum for (EV_ABS, EV_REL, etc.). No max is defined for
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.
920 * @note The max value is compiled into libevdev. If the kernel changes the
921 * max value, libevdev will not automatically pick these up.
923 int libevdev_get_event_type_max(unsigned int type);
928 * Get the repeat delay and repeat period values for this device.
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
934 * @return 0 on success, -1 if this device does not have repeat settings.
936 * @note This function is signal-safe
938 int libevdev_get_repeat(struct libevdev *dev, int *delay, int *period);
940 #endif /* libevdev_H */