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);
244 * @defgroup event_added_seat Added seat event
247 struct libinput_seat *
248 libinput_event_added_seat_get_seat(struct libinput_event_added_seat *event);
251 * @defgroup event_removed_seat Removed seat event
254 struct libinput_seat *
255 libinput_event_removed_seat_get_seat(struct libinput_event_removed_seat *event);
258 * @defgroup event_added_device Added device event
261 struct libinput_device *
262 libinput_event_added_device_get_device(
263 struct libinput_event_added_device *event);
266 * @defgroup event_removed_device Removed device event
269 struct libinput_device *
270 libinput_event_removed_device_get_device(
271 struct libinput_event_removed_device *event);
274 * @defgroup event_keyboard_key Keyboard key event
278 libinput_event_keyboard_key_get_time(
279 struct libinput_event_keyboard_key *event);
282 libinput_event_keyboard_key_get_key(
283 struct libinput_event_keyboard_key *event);
285 enum libinput_keyboard_key_state
286 libinput_event_keyboard_key_get_state(
287 struct libinput_event_keyboard_key *event);
290 * @defgroup event_pointer_motion Pointer motion event
294 libinput_event_pointer_motion_get_time(
295 struct libinput_event_pointer_motion *event);
298 libinput_event_pointer_motion_get_dx(
299 struct libinput_event_pointer_motion *event);
302 libinput_event_pointer_motion_get_dy(
303 struct libinput_event_pointer_motion *event);
306 * @defgroup event_pointer_motion_absolute Absolute pointer motion event
310 libinput_event_pointer_motion_absolute_get_time(
311 struct libinput_event_pointer_motion_absolute *event);
314 libinput_event_pointer_motion_absolute_get_x(
315 struct libinput_event_pointer_motion_absolute *event);
318 libinput_event_pointer_motion_absolute_get_y(
319 struct libinput_event_pointer_motion_absolute *event);
322 * @defgroup event_pointer_button Pointer button event
326 libinput_event_pointer_button_get_time(
327 struct libinput_event_pointer_button *event);
330 libinput_event_pointer_button_get_button(
331 struct libinput_event_pointer_button *event);
333 enum libinput_pointer_button_state
334 libinput_event_pointer_button_get_state(
335 struct libinput_event_pointer_button *event);
338 * @defgroup event_pointer_axis Pointer axis event
342 libinput_event_pointer_axis_get_time(
343 struct libinput_event_pointer_axis *event);
345 enum libinput_pointer_axis
346 libinput_event_pointer_axis_get_axis(
347 struct libinput_event_pointer_axis *event);
350 libinput_event_pointer_axis_get_value(
351 struct libinput_event_pointer_axis *event);
354 * @defgroup event_pointer_button Pointer button event
358 libinput_event_touch_touch_get_time(
359 struct libinput_event_touch_touch *event);
362 libinput_event_touch_touch_get_slot(
363 struct libinput_event_touch_touch *event);
366 libinput_event_touch_touch_get_x(
367 struct libinput_event_touch_touch *event);
370 libinput_event_touch_touch_get_y(
371 struct libinput_event_touch_touch *event);
373 enum libinput_touch_type
374 libinput_event_touch_touch_get_touch_type(
375 struct libinput_event_touch_touch *event);
378 * @defgroup base Initialization and manipulation of libinput contexts
381 struct libinput_interface {
383 * Open the device at the given path with the flags provided and
386 * @param path The device path to open
387 * @param flags Flags as defined by open(2)
388 * @param user_data The user_data provided in
389 * libinput_create_from_udev()
391 * @return the file descriptor, or a negative errno on failure.
393 int (*open_restricted)(const char *path, int flags, void *user_data);
395 * Close the file descriptor.
397 * @param fd The file descriptor to close
398 * @param user_data The user_data provided in
399 * libinput_create_from_udev()
401 void (*close_restricted)(int fd, void *user_data);
403 void (*get_current_screen_dimensions)(struct libinput_device *device,
412 * Create a new libinput context from udev, for input devices matching
413 * the given seat ID. New devices or devices removed will appear as events
414 * during libinput_dispatch.
416 * @param interface The callback interface
417 * @param user_data Caller-specific data passed to the various callback
419 * @param udev An already initialized udev context
420 * @param seat_id A seat identifier. This string must not be NULL.
422 * @return An initialized libinput context, ready to handle events or NULL on
426 libinput_create_from_udev(const struct libinput_interface *interface,
429 const char *seat_id);
433 * Create a new libinput context from the given path. This context
434 * represents one single device only, it will not respond to new devices
435 * being added and reading from the device after it was removed will fail.
437 * @param interface The callback interface
438 * @param user_data Caller-specific data passed to the various callback
440 * @param path Path to an input device
442 * @return An initialized libinput context, ready to handle events or NULL on
446 libinput_create_from_path(const struct libinput_interface *interface,
453 * libinput keeps a single file descriptor for all events. Call into
454 * libinput_dispatch() if any events become available on this fd.
456 * @return the file descriptor used to notify of pending events.
459 libinput_get_fd(struct libinput *libinput);
464 * Main event dispatchment function. Reads events of the file descriptors
465 * and processes them internally. Use libinput_get_event() to retrieve the
468 * Dispatching does not necessarily queue libinput events.
470 * @param libinput A previously initialized libinput context
472 * @return 0 on success, or a negative errno on failure
475 libinput_dispatch(struct libinput *libinput);
480 * Retrieve the next event from libinput's internal event queue.
482 * After handling the retrieved event, the caller must destroy it using
483 * libinput_event_destroy().
485 * @param libinput A previously initialized libinput context
486 * @return The next available event, or NULL if no event is available.
488 struct libinput_event *
489 libinput_get_event(struct libinput *libinput);
494 * Return the type of the next event in the internal queue. This function
495 * does not pop the event off the queue and the next call to
496 * libinput_get_event() returns that event.
498 * @param libinput A previously initialized libinput context
499 * @return The event type of the next available event or LIBINPUT_EVENT_NONE
500 * if no event is availble.
502 enum libinput_event_type
503 libinput_next_event_type(struct libinput *libinput);
508 * @param libinput A previously initialized libinput context
509 * @return the caller-specific data previously assigned in
510 * libinput_create_udev().
513 libinput_get_user_data(struct libinput *libinput);
518 * Resume a suspended libinput context. This re-enables device
519 * monitoring and adds existing devices.
521 * @param libinput A previously initialized libinput context
522 * @see libinput_suspend
524 * @return 0 on success or -1 on failure
527 libinput_resume(struct libinput *libinput);
532 * Suspend monitoring for new devices and close existing devices.
533 * This all but terminates libinput but does keep the context
534 * valid to be resumed with libinput_resume().
536 * @param libinput A previously initialized libinput context
539 libinput_suspend(struct libinput *libinput);
544 * Destroy the libinput context. After this, object references associated with
545 * the destroyed context are invalid and may not be interacted with.
547 * @param libinput A previously initialized libinput context
550 libinput_destroy(struct libinput *libinput);
553 * @defgroup seat Initialization and manipulation of seats
559 * Increase the refcount of the seat. A seat will be freed whenever the
560 * refcount reaches 0. This may happen during dispatch if the
561 * seat was removed from the system. A caller must ensure to reference
562 * the seat correctly to avoid dangling pointers.
564 * @param seat A previously obtained seat
567 libinput_seat_ref(struct libinput_seat *seat);
572 * Decrease the refcount of the seat. A seat will be freed whenever the
573 * refcount reaches 0. This may happen during dispatch if the
574 * seat was removed from the system. A caller must ensure to reference
575 * the seat correctly to avoid dangling pointers.
577 * @param seat A previously obtained seat
580 libinput_seat_unref(struct libinput_seat *seat);
585 * Set caller-specific data associated with this seat. libinput does
586 * not manage, look at, or modify this data. The caller must ensure the
589 * @param seat A previously obtained seat
590 * @param user_data Caller-specific data pointer
591 * @see libinput_seat_get_user_data
594 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
599 * Get the caller-specific data associated with this seat, if any.
601 * @param seat A previously obtained seat
602 * @return Caller-specific data pointer or NULL if none was set
603 * @see libinput_seat_set_user_data
606 libinput_seat_get_user_data(struct libinput_seat *seat);
611 * @param seat A previously obtained seat
612 * @return the name of this seat
615 libinput_seat_get_name(struct libinput_seat *seat);
618 * @defgroup device Initialization and manipulation of input devices
624 * Increase the refcount of the input device. An input device will be freed
625 * whenever the refcount reaches 0. This may happen during dispatch if the
626 * device was removed from the system. A caller must ensure to reference
627 * the device correctly to avoid dangling pointers.
629 * @param device A previously obtained device
632 libinput_device_ref(struct libinput_device *device);
637 * Decrease the refcount of the input device. An input device will be freed
638 * whenever the refcount reaches 0. This may happen during dispatch if the
639 * device was removed from the system. A caller must ensure to reference
640 * the device correctly to avoid dangling pointers.
642 * @param device A previously obtained device
645 libinput_device_unref(struct libinput_device *device);
650 * Set caller-specific data associated with this input device. libinput does
651 * not manage, look at, or modify this data. The caller must ensure the
654 * @param device A previously obtained device
655 * @param user_data Caller-specific data pointer
656 * @see libinput_device_get_user_data
659 libinput_device_set_user_data(struct libinput_device *device, void *user_data);
664 * Get the caller-specific data associated with this input device, if any.
666 * @param device A previously obtained device
667 * @return Caller-specific data pointer or NULL if none was set
668 * @see libinput_device_set_user_data
671 libinput_device_get_user_data(struct libinput_device *device);
676 * Get the system name of the device.
678 * @param device A previously obtained device
679 * @return System name of the device
682 libinput_device_get_sysname(struct libinput_device *device);
687 * A device may be mapped to a single output, or all available outputs. If a
688 * device is mapped to a single output only, a relative device may not move
689 * beyond the boundaries of this output. An absolute device has its input
690 * coordinates mapped to the extents of this output.
692 * @return the name of the output this device is mapped to, or NULL if no
696 libinput_device_get_output_name(struct libinput_device *device);
701 * Get the seat associated with this input device.
703 * @param device A previously obtained device
704 * @return The seat this input device belongs to
706 struct libinput_seat *
707 libinput_device_get_seat(struct libinput_device *device);
712 * Update the LEDs on the device, if any. If the device does not have
713 * LEDs, or does not have one or more of the LEDs given in the mask, this
714 * function does nothing.
716 * @param device A previously obtained device
717 * @param leds A mask of the LEDs to set, or unset.
720 libinput_device_led_update(struct libinput_device *device,
721 enum libinput_led leds);
726 * Set the bitmask in keys to the bitmask of the keys present on the device
727 * (see linux/input.h), up to size characters.
729 * @param device A current input device
730 * @param keys An array filled with the bitmask for the keys
731 * @param size Size of the keys array
734 libinput_device_get_keys(struct libinput_device *device,
735 char *keys, size_t size);
740 * Apply the 3x3 transformation matrix to absolute device coordinates. This
741 * matrix has no effect on relative events.
743 * Given a 6-element array [a, b, c, d, e, f], the matrix is applied as
751 libinput_device_calibrate(struct libinput_device *device,
752 float calibration[6]);
757 * Check if the given device has the specified capability
759 * @return 1 if the given device has the capability or 0 if not
762 libinput_device_has_capability(struct libinput_device *device,
763 enum libinput_device_capability capability);
765 #endif /* LIBINPUT_H */