2 * Copyright © 2013 Jonas Ådahl
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 * libinput is a generic input device handling library. It abstracts
33 * commonly-used concepts such as keyboard, pointer and touchpad handling
38 * @ingroup fixed_point
40 * libinput 24.8 fixed point real number.
42 typedef int32_t li_fixed_t;
47 * Capabilities on a device. A device may have one or more capabilities
48 * at a time, and capabilities may appear or disappear during the
49 * lifteime of the device.
51 enum libinput_device_capability {
52 LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
53 LIBINPUT_DEVICE_CAP_POINTER = 1,
54 LIBINPUT_DEVICE_CAP_TOUCH = 2
60 * Logical state of a key. Note that the logical state may not represent
61 * the physical state of the key.
63 enum libinput_keyboard_key_state {
64 LIBINPUT_KEYBOARD_KEY_STATE_RELEASED = 0,
65 LIBINPUT_KEYBOARD_KEY_STATE_PRESSED = 1
71 * Mask reflecting LEDs on a device.
74 LIBINPUT_LED_NUM_LOCK = (1 << 0),
75 LIBINPUT_LED_CAPS_LOCK = (1 << 1),
76 LIBINPUT_LED_SCROLL_LOCK = (1 << 2)
82 * Logical state of a physical button. Note that the logical state may not
83 * represent the physical state of the button.
85 enum libinput_pointer_button_state {
86 LIBINPUT_POINTER_BUTTON_STATE_RELEASED = 0,
87 LIBINPUT_POINTER_BUTTON_STATE_PRESSED = 1
94 * Axes on a device that are not x or y coordinates.
96 enum libinput_pointer_axis {
97 LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL = 0,
98 LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1
104 * Logical touch state of a touch point. A touch point usually follows the
105 * sequence down, motion, up, with the number of motion events being zero or
106 * greater. If a touch point was used for gesture interpretation internally
107 * and will not generate any further events, the touchpoint is cancelled.
109 * A frame event is set after a set of touchpoints that constitute one
110 * logical set of points at a sampling point.
112 enum libinput_touch_type {
113 LIBINPUT_TOUCH_TYPE_DOWN = 0,
114 LIBINPUT_TOUCH_TYPE_UP = 1,
115 LIBINPUT_TOUCH_TYPE_MOTION = 2,
116 LIBINPUT_TOUCH_TYPE_FRAME = 3,
117 LIBINPUT_TOUCH_TYPE_CANCEL = 4
123 * Event type for events returned by libinput_get_event().
125 enum libinput_event_type {
126 LIBINPUT_EVENT_NONE = 0,
127 LIBINPUT_EVENT_ADDED_SEAT,
128 LIBINPUT_EVENT_REMOVED_SEAT,
129 LIBINPUT_EVENT_ADDED_DEVICE,
130 LIBINPUT_EVENT_REMOVED_DEVICE,
132 LIBINPUT_EVENT_KEYBOARD_KEY = 300,
134 LIBINPUT_EVENT_POINTER_MOTION = 400,
135 LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
136 LIBINPUT_EVENT_POINTER_BUTTON,
137 LIBINPUT_EVENT_POINTER_AXIS,
139 LIBINPUT_EVENT_TOUCH_TOUCH = 500
143 struct libinput_device;
144 struct libinput_seat;
146 union libinput_event_target {
147 struct libinput *libinput;
148 struct libinput_seat *seat;
149 struct libinput_device *device;
152 struct libinput_event;
153 struct libinput_event_added_seat;
154 struct libinput_event_removed_seat;
155 struct libinput_event_added_device;
156 struct libinput_event_removed_device;
157 struct libinput_event_keyboard_key;
158 struct libinput_event_pointer_motion;
159 struct libinput_event_pointer_motion_absolute;
160 struct libinput_event_pointer_button;
161 struct libinput_event_pointer_axis;
162 struct libinput_event_touch_touch;
165 * @defgroup fixed_point Fixed point utilities
169 * @ingroup fixed_point
171 * Convert li_fixed_t to a double
173 * @param f fixed point number
174 * @return Converted double
177 li_fixed_to_double (li_fixed_t f)
184 u.i = ((1023LL + 44LL) << 52) + (1LL << 51) + f;
186 return u.d - (3LL << 43);
190 * @ingroup fixed_point
192 * Convert li_fixed_t to a int. The fraction part is discarded.
194 * @param f fixed point number
195 * @return Converted int
198 li_fixed_to_int(li_fixed_t f)
204 * @defgroup event Acessing and destruction of events
212 * @param event An event retrieved by libinput_get_event().
215 libinput_event_destroy(struct libinput_event *event);
220 * Get the type of the event.
222 * @param event An event retrieved by libinput_get_event().
224 enum libinput_event_type
225 libinput_event_get_type(struct libinput_event *event);
230 * Get get the target union of the event.
232 * The valid union member depends on the event type. For global events not
233 * related to some seat or device, the target is a libinput struct pointer.
234 * For events associated with a seat, the target is a libinput_seat pointer
235 * and for events associated with a device, the target is a libinput_device
238 * @param event An event retrieved by libinput_get_event().
240 union libinput_event_target
241 libinput_event_get_target(struct libinput_event *event);
246 * Get the libinput context from the event.
248 * @param event The libinput event
249 * @return The libinput context for this event.
252 libinput_event_get_context(struct libinput_event *event);
255 * @defgroup event_added_seat Added seat event
258 struct libinput_seat *
259 libinput_event_added_seat_get_seat(struct libinput_event_added_seat *event);
262 * @defgroup event_removed_seat Removed seat event
265 struct libinput_seat *
266 libinput_event_removed_seat_get_seat(struct libinput_event_removed_seat *event);
269 * @defgroup event_added_device Added device event
272 struct libinput_device *
273 libinput_event_added_device_get_device(
274 struct libinput_event_added_device *event);
277 * @defgroup event_removed_device Removed device event
280 struct libinput_device *
281 libinput_event_removed_device_get_device(
282 struct libinput_event_removed_device *event);
285 * @defgroup event_keyboard_key Keyboard key event
289 libinput_event_keyboard_key_get_time(
290 struct libinput_event_keyboard_key *event);
293 libinput_event_keyboard_key_get_key(
294 struct libinput_event_keyboard_key *event);
296 enum libinput_keyboard_key_state
297 libinput_event_keyboard_key_get_state(
298 struct libinput_event_keyboard_key *event);
301 * @defgroup event_pointer_motion Pointer motion event
305 libinput_event_pointer_motion_get_time(
306 struct libinput_event_pointer_motion *event);
309 libinput_event_pointer_motion_get_dx(
310 struct libinput_event_pointer_motion *event);
313 libinput_event_pointer_motion_get_dy(
314 struct libinput_event_pointer_motion *event);
317 * @defgroup event_pointer_motion_absolute Absolute pointer motion event
321 libinput_event_pointer_motion_absolute_get_time(
322 struct libinput_event_pointer_motion_absolute *event);
325 libinput_event_pointer_motion_absolute_get_x(
326 struct libinput_event_pointer_motion_absolute *event);
329 libinput_event_pointer_motion_absolute_get_y(
330 struct libinput_event_pointer_motion_absolute *event);
333 * @defgroup event_pointer_button Pointer button event
337 libinput_event_pointer_button_get_time(
338 struct libinput_event_pointer_button *event);
341 libinput_event_pointer_button_get_button(
342 struct libinput_event_pointer_button *event);
344 enum libinput_pointer_button_state
345 libinput_event_pointer_button_get_state(
346 struct libinput_event_pointer_button *event);
349 * @defgroup event_pointer_axis Pointer axis event
353 libinput_event_pointer_axis_get_time(
354 struct libinput_event_pointer_axis *event);
356 enum libinput_pointer_axis
357 libinput_event_pointer_axis_get_axis(
358 struct libinput_event_pointer_axis *event);
361 libinput_event_pointer_axis_get_value(
362 struct libinput_event_pointer_axis *event);
365 * @defgroup event_pointer_button Pointer button event
369 libinput_event_touch_touch_get_time(
370 struct libinput_event_touch_touch *event);
373 libinput_event_touch_touch_get_slot(
374 struct libinput_event_touch_touch *event);
377 libinput_event_touch_touch_get_x(
378 struct libinput_event_touch_touch *event);
381 libinput_event_touch_touch_get_y(
382 struct libinput_event_touch_touch *event);
384 enum libinput_touch_type
385 libinput_event_touch_touch_get_touch_type(
386 struct libinput_event_touch_touch *event);
389 * @defgroup base Initialization and manipulation of libinput contexts
392 struct libinput_interface {
394 * Open the device at the given path with the flags provided and
397 * @param path The device path to open
398 * @param flags Flags as defined by open(2)
399 * @param user_data The user_data provided in
400 * libinput_create_from_udev()
402 * @return the file descriptor, or a negative errno on failure.
404 int (*open_restricted)(const char *path, int flags, void *user_data);
406 * Close the file descriptor.
408 * @param fd The file descriptor to close
409 * @param user_data The user_data provided in
410 * libinput_create_from_udev()
412 void (*close_restricted)(int fd, void *user_data);
414 void (*get_current_screen_dimensions)(struct libinput_device *device,
423 * Create a new libinput context from udev, for input devices matching
424 * the given seat ID. New devices or devices removed will appear as events
425 * during libinput_dispatch.
427 * @param interface The callback interface
428 * @param user_data Caller-specific data passed to the various callback
430 * @param udev An already initialized udev context
431 * @param seat_id A seat identifier. This string must not be NULL.
433 * @return An initialized libinput context, ready to handle events or NULL on
437 libinput_create_from_udev(const struct libinput_interface *interface,
440 const char *seat_id);
444 * Create a new libinput context from the given path. This context
445 * represents one single device only, it will not respond to new devices
446 * being added and reading from the device after it was removed will fail.
448 * @param interface The callback interface
449 * @param user_data Caller-specific data passed to the various callback
451 * @param path Path to an input device
453 * @return An initialized libinput context, ready to handle events or NULL on
457 libinput_create_from_path(const struct libinput_interface *interface,
464 * libinput keeps a single file descriptor for all events. Call into
465 * libinput_dispatch() if any events become available on this fd.
467 * @return the file descriptor used to notify of pending events.
470 libinput_get_fd(struct libinput *libinput);
475 * Main event dispatchment function. Reads events of the file descriptors
476 * and processes them internally. Use libinput_get_event() to retrieve the
479 * Dispatching does not necessarily queue libinput events.
481 * @param libinput A previously initialized libinput context
483 * @return 0 on success, or a negative errno on failure
486 libinput_dispatch(struct libinput *libinput);
491 * Retrieve the next event from libinput's internal event queue.
493 * After handling the retrieved event, the caller must destroy it using
494 * libinput_event_destroy().
496 * @param libinput A previously initialized libinput context
497 * @return The next available event, or NULL if no event is available.
499 struct libinput_event *
500 libinput_get_event(struct libinput *libinput);
505 * Return the type of the next event in the internal queue. This function
506 * does not pop the event off the queue and the next call to
507 * libinput_get_event() returns that event.
509 * @param libinput A previously initialized libinput context
510 * @return The event type of the next available event or LIBINPUT_EVENT_NONE
511 * if no event is availble.
513 enum libinput_event_type
514 libinput_next_event_type(struct libinput *libinput);
519 * @param libinput A previously initialized libinput context
520 * @return the caller-specific data previously assigned in
521 * libinput_create_udev().
524 libinput_get_user_data(struct libinput *libinput);
529 * Resume a suspended libinput context. This re-enables device
530 * monitoring and adds existing devices.
532 * @param libinput A previously initialized libinput context
533 * @see libinput_suspend
535 * @return 0 on success or -1 on failure
538 libinput_resume(struct libinput *libinput);
543 * Suspend monitoring for new devices and close existing devices.
544 * This all but terminates libinput but does keep the context
545 * valid to be resumed with libinput_resume().
547 * @param libinput A previously initialized libinput context
550 libinput_suspend(struct libinput *libinput);
555 * Destroy the libinput context. After this, object references associated with
556 * the destroyed context are invalid and may not be interacted with.
558 * @param libinput A previously initialized libinput context
561 libinput_destroy(struct libinput *libinput);
564 * @defgroup seat Initialization and manipulation of seats
570 * Increase the refcount of the seat. A seat will be freed whenever the
571 * refcount reaches 0. This may happen during dispatch if the
572 * seat was removed from the system. A caller must ensure to reference
573 * the seat correctly to avoid dangling pointers.
575 * @param seat A previously obtained seat
578 libinput_seat_ref(struct libinput_seat *seat);
583 * Decrease the refcount of the seat. A seat will be freed whenever the
584 * refcount reaches 0. This may happen during dispatch if the
585 * seat was removed from the system. A caller must ensure to reference
586 * the seat correctly to avoid dangling pointers.
588 * @param seat A previously obtained seat
591 libinput_seat_unref(struct libinput_seat *seat);
596 * Set caller-specific data associated with this seat. libinput does
597 * not manage, look at, or modify this data. The caller must ensure the
600 * @param seat A previously obtained seat
601 * @param user_data Caller-specific data pointer
602 * @see libinput_seat_get_user_data
605 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
610 * Get the caller-specific data associated with this seat, if any.
612 * @param seat A previously obtained seat
613 * @return Caller-specific data pointer or NULL if none was set
614 * @see libinput_seat_set_user_data
617 libinput_seat_get_user_data(struct libinput_seat *seat);
622 * @param seat A previously obtained seat
623 * @return the name of this seat
626 libinput_seat_get_name(struct libinput_seat *seat);
629 * @defgroup device Initialization and manipulation of input devices
635 * Increase the refcount of the input device. An input device will be freed
636 * whenever the refcount reaches 0. This may happen during dispatch if the
637 * device was removed from the system. A caller must ensure to reference
638 * the device correctly to avoid dangling pointers.
640 * @param device A previously obtained device
643 libinput_device_ref(struct libinput_device *device);
648 * Decrease the refcount of the input device. An input device will be freed
649 * whenever the refcount reaches 0. This may happen during dispatch if the
650 * device was removed from the system. A caller must ensure to reference
651 * the device correctly to avoid dangling pointers.
653 * @param device A previously obtained device
656 libinput_device_unref(struct libinput_device *device);
661 * Set caller-specific data associated with this input device. libinput does
662 * not manage, look at, or modify this data. The caller must ensure the
665 * @param device A previously obtained device
666 * @param user_data Caller-specific data pointer
667 * @see libinput_device_get_user_data
670 libinput_device_set_user_data(struct libinput_device *device, void *user_data);
675 * Get the caller-specific data associated with this input device, if any.
677 * @param device A previously obtained device
678 * @return Caller-specific data pointer or NULL if none was set
679 * @see libinput_device_set_user_data
682 libinput_device_get_user_data(struct libinput_device *device);
687 * Get the system name of the device.
689 * @param device A previously obtained device
690 * @return System name of the device
693 libinput_device_get_sysname(struct libinput_device *device);
698 * A device may be mapped to a single output, or all available outputs. If a
699 * device is mapped to a single output only, a relative device may not move
700 * beyond the boundaries of this output. An absolute device has its input
701 * coordinates mapped to the extents of this output.
703 * @return the name of the output this device is mapped to, or NULL if no
707 libinput_device_get_output_name(struct libinput_device *device);
712 * Get the seat associated with this input device.
714 * @param device A previously obtained device
715 * @return The seat this input device belongs to
717 struct libinput_seat *
718 libinput_device_get_seat(struct libinput_device *device);
723 * Update the LEDs on the device, if any. If the device does not have
724 * LEDs, or does not have one or more of the LEDs given in the mask, this
725 * function does nothing.
727 * @param device A previously obtained device
728 * @param leds A mask of the LEDs to set, or unset.
731 libinput_device_led_update(struct libinput_device *device,
732 enum libinput_led leds);
737 * Set the bitmask in keys to the bitmask of the keys present on the device
738 * (see linux/input.h), up to size characters.
740 * @param device A current input device
741 * @param keys An array filled with the bitmask for the keys
742 * @param size Size of the keys array
745 libinput_device_get_keys(struct libinput_device *device,
746 char *keys, size_t size);
751 * Apply the 3x3 transformation matrix to absolute device coordinates. This
752 * matrix has no effect on relative events.
754 * Given a 6-element array [a, b, c, d, e, f], the matrix is applied as
762 libinput_device_calibrate(struct libinput_device *device,
763 float calibration[6]);
768 * Check if the given device has the specified capability
770 * @return 1 if the given device has the capability or 0 if not
773 libinput_device_has_capability(struct libinput_device *device,
774 enum libinput_device_capability capability);
776 #endif /* LIBINPUT_H */