c19460b0a09e9b57943c83bf62da1523f5f0f71d
[platform/upstream/libinput.git] / src / libinput.h
1 /*
2  * Copyright © 2013 Jonas Ådahl
3  *
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.
13  *
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.
21  */
22
23 #ifndef LIBINPUT_H
24 #define LIBINPUT_H
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdlib.h>
31 #include <stdint.h>
32 #include <libudev.h>
33
34 #define LIBINPUT_ATTRIBUTE_PRINTF(_format, _args) \
35         __attribute__ ((format (printf, _format, _args)))
36
37 /**
38  * @mainpage
39  * libinput is a generic input device handling library. It abstracts
40  * commonly-used concepts such as keyboard, pointer and touchpad handling
41  * behind an API.
42  */
43
44 /**
45  * @page tpbuttons Touchpad button behavior
46  *
47  * For touchpad devices without physical buttons, libinput enables an
48  * emulated right button area through either of two methods.
49  *
50  * Software button areas
51  * =====================
52  * On most touchpads, the bottom area of the touchpad is split into a a left
53  * and a right-button area. Pressing the touchpad down with a finger in
54  * those areas will generate clicks as shown in the diagram below:
55  *
56  * @code
57     +------------------------+
58     |                        |
59     |                        |
60     |          LEFT          |
61     |                        |
62     |                        |
63     +------------------------+
64     |    LEFT    |   RIGHT   |
65     +------------------------+
66  * @endcode
67  *
68  * Generally, the touchpad will emulate a right-button click if the finger
69  * was set down in the right button area and did not leave the
70  * right button area before clicking, even if another finger was already
71  * down on the touchpad in another area.
72  * A middle click is generated by clicking the touchpad when one finger is
73  * in the bottom left button area, and one finger is in the botton right
74  * button area.
75  * The exact behavior of the touchpad is implementation-dependent.
76  *
77  * Top software button area
78  * ========================
79  * On selected touchpads, the top area of the touchpad is a separate set of
80  * software buttons split into a left, middle and right button area.
81  * Pressing the touchpad down with a finger in those areas will generate
82  * clicks as shown in the diagram below:
83  *
84  * @code
85     +------------------------+
86     |  LEFT | MIDDLE | RIGHT |
87     +------------------------+
88     |                        |
89     |          LEFT          |
90     |                        |
91     +------------------------+
92     |    LEFT    |   RIGHT   |
93     +------------------------+
94  * @endcode
95  * This behavior is enabled on the Lenovo *40 series (T440, T540, T240...)
96  * and the Lenovo Helix, Yoga S1 and Carbon X1 2nd.
97  *
98  * Clickfinger
99  * ===========
100  * On Apple touchpads, no button areas are provided. Instead, use a
101  * two-finger click for a right button click, and a three-finger click for a
102  * middle button click.
103  */
104
105 /**
106  * Log priority for internal logging messages.
107  */
108 enum libinput_log_priority {
109         LIBINPUT_LOG_PRIORITY_DEBUG = 10,
110         LIBINPUT_LOG_PRIORITY_INFO = 20,
111         LIBINPUT_LOG_PRIORITY_ERROR = 30,
112 };
113
114 /**
115  * @ingroup device
116  *
117  * Capabilities on a device. A device may have one or more capabilities
118  * at a time, and capabilities may appear or disappear during the
119  * lifetime of the device.
120  */
121 enum libinput_device_capability {
122         LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
123         LIBINPUT_DEVICE_CAP_POINTER = 1,
124         LIBINPUT_DEVICE_CAP_TOUCH = 2
125 };
126
127 /**
128  * @ingroup device
129  *
130  * Logical state of a key. Note that the logical state may not represent
131  * the physical state of the key.
132  */
133 enum libinput_keyboard_key_state {
134         LIBINPUT_KEYBOARD_KEY_STATE_RELEASED = 0,
135         LIBINPUT_KEYBOARD_KEY_STATE_PRESSED = 1
136 };
137
138 /**
139  * @ingroup device
140  *
141  * Mask reflecting LEDs on a device.
142  */
143 enum libinput_led {
144         LIBINPUT_LED_NUM_LOCK = (1 << 0),
145         LIBINPUT_LED_CAPS_LOCK = (1 << 1),
146         LIBINPUT_LED_SCROLL_LOCK = (1 << 2)
147 };
148
149 /**
150  * @ingroup device
151  *
152  * Logical state of a physical button. Note that the logical state may not
153  * represent the physical state of the button.
154  */
155 enum libinput_button_state {
156         LIBINPUT_BUTTON_STATE_RELEASED = 0,
157         LIBINPUT_BUTTON_STATE_PRESSED = 1
158 };
159
160
161 /**
162  * @ingroup device
163  *
164  * Axes on a device that are not x or y coordinates.
165  */
166 enum libinput_pointer_axis {
167         LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL = 0,
168         LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1
169 };
170
171 /**
172  * @ingroup base
173  *
174  * Event type for events returned by libinput_get_event().
175  */
176 enum libinput_event_type {
177         /**
178          * This is not a real event type, and is only used to tell the user that
179          * no new event is available in the queue. See
180          * libinput_next_event_type().
181          */
182         LIBINPUT_EVENT_NONE = 0,
183
184         /**
185          * Signals that a device has been added to the context. The device will
186          * not be read until the next time the user calls libinput_dispatch()
187          * and data is available.
188          *
189          * This allows setting up initial device configuration before any events
190          * are created.
191          */
192         LIBINPUT_EVENT_DEVICE_ADDED,
193
194         /**
195          * Signals that a device has been removed. No more events from the
196          * associated device will be in the queue or be queued after this event.
197          */
198         LIBINPUT_EVENT_DEVICE_REMOVED,
199
200         LIBINPUT_EVENT_KEYBOARD_KEY = 300,
201
202         LIBINPUT_EVENT_POINTER_MOTION = 400,
203         LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
204         LIBINPUT_EVENT_POINTER_BUTTON,
205         LIBINPUT_EVENT_POINTER_AXIS,
206
207         LIBINPUT_EVENT_TOUCH_DOWN = 500,
208         LIBINPUT_EVENT_TOUCH_UP,
209         LIBINPUT_EVENT_TOUCH_MOTION,
210         LIBINPUT_EVENT_TOUCH_CANCEL,
211         /**
212          * Signals the end of a set of touchpoints at one device sample
213          * time. This event has no coordinate information attached.
214          */
215         LIBINPUT_EVENT_TOUCH_FRAME
216 };
217
218 struct libinput;
219 struct libinput_device;
220 struct libinput_seat;
221
222 struct libinput_event;
223 struct libinput_event_device_notify;
224 struct libinput_event_keyboard;
225 struct libinput_event_pointer;
226
227 /**
228  * @ingroup event_touch
229  * @struct libinput_event_touch
230  *
231  * Touch event representing a touch down, move or up, as well as a touch
232  * cancel and touch frame events. Valid event types for this event are @ref
233  * LIBINPUT_EVENT_TOUCH_DOWN, @ref LIBINPUT_EVENT_TOUCH_MOTION, @ref
234  * LIBINPUT_EVENT_TOUCH_UP, @ref LIBINPUT_EVENT_TOUCH_CANCEL and @ref
235  * LIBINPUT_EVENT_TOUCH_FRAME.
236  */
237 struct libinput_event_touch;
238
239 /**
240  * @defgroup event Accessing and destruction of events
241  */
242
243 /**
244  * @ingroup event
245  *
246  * Destroy the event.
247  *
248  * @param event An event retrieved by libinput_get_event().
249  */
250 void
251 libinput_event_destroy(struct libinput_event *event);
252
253 /**
254  * @ingroup event
255  *
256  * Get the type of the event.
257  *
258  * @param event An event retrieved by libinput_get_event().
259  */
260 enum libinput_event_type
261 libinput_event_get_type(struct libinput_event *event);
262
263 /**
264  * @ingroup event
265  *
266  * Get the libinput context from the event.
267  *
268  * @param event The libinput event
269  * @return The libinput context for this event.
270  */
271 struct libinput *
272 libinput_event_get_context(struct libinput_event *event);
273
274 /**
275  * @ingroup event
276  *
277  * Return the device associated with this event, if applicable. For device
278  * added/removed events this is the device added or removed. For all other
279  * device events, this is the device that generated the event.
280  *
281  * This device is not refcounted and its lifetime is that of the event. Use
282  * libinput_device_ref() before using the device outside of this scope.
283  *
284  * @return The device associated with this event
285  */
286
287 struct libinput_device *
288 libinput_event_get_device(struct libinput_event *event);
289
290 /**
291  * @ingroup event
292  *
293  * Return the pointer event that is this input event. If the event type does
294  * not match the pointer event types, this function returns NULL.
295  *
296  * The inverse of this function is libinput_event_pointer_get_base_event().
297  *
298  * @return A pointer event, or NULL for other events
299  */
300 struct libinput_event_pointer *
301 libinput_event_get_pointer_event(struct libinput_event *event);
302
303 /**
304  * @ingroup event
305  *
306  * Return the keyboard event that is this input event. If the event type does
307  * not match the keyboard event types, this function returns NULL.
308  *
309  * The inverse of this function is libinput_event_keyboard_get_base_event().
310  *
311  * @return A keyboard event, or NULL for other events
312  */
313 struct libinput_event_keyboard *
314 libinput_event_get_keyboard_event(struct libinput_event *event);
315
316 /**
317  * @ingroup event
318  *
319  * Return the touch event that is this input event. If the event type does
320  * not match the touch event types, this function returns NULL.
321  *
322  * The inverse of this function is libinput_event_touch_get_base_event().
323  *
324  * @return A touch event, or NULL for other events
325  */
326 struct libinput_event_touch *
327 libinput_event_get_touch_event(struct libinput_event *event);
328
329 /**
330  * @ingroup event
331  *
332  * Return the device event that is this input event. If the event type does
333  * not match the device event types, this function returns NULL.
334  *
335  * The inverse of this function is
336  * libinput_event_device_notify_get_base_event().
337  *
338  * @return A device event, or NULL for other events
339  */
340 struct libinput_event_device_notify *
341 libinput_event_get_device_notify_event(struct libinput_event *event);
342
343 /**
344  * @ingroup event
345  *
346  * @return The generic libinput_event of this event
347  */
348 struct libinput_event *
349 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event);
350
351 /**
352  * @defgroup event_keyboard Keyboard events
353  *
354  * Key events are generated when a key changes its logical state, usually by
355  * being pressed or released.
356  */
357
358 /**
359  * @ingroup event_keyboard
360  *
361  * @return The event time for this event
362  */
363 uint32_t
364 libinput_event_keyboard_get_time(struct libinput_event_keyboard *event);
365
366 /**
367  * @ingroup event_keyboard
368  *
369  * @return The keycode that triggered this key event
370  */
371 uint32_t
372 libinput_event_keyboard_get_key(struct libinput_event_keyboard *event);
373
374 /**
375  * @ingroup event_keyboard
376  *
377  * @return The state change of the key
378  */
379 enum libinput_keyboard_key_state
380 libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event);
381
382
383 /**
384  * @ingroup event_keyboard
385  *
386  * @return The generic libinput_event of this event
387  */
388 struct libinput_event *
389 libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event);
390
391 /**
392  * @ingroup event_keyboard
393  *
394  * For the key of a LIBINPUT_EVENT_KEYBOARD_KEY event, return the total number
395  * of keys pressed on all devices on the associated seat after the event was
396  * triggered.
397  *
398  " @note It is an application bug to call this function for events other than
399  * LIBINPUT_EVENT_KEYBOARD_KEY. For other events, this function returns 0.
400  *
401  * @return the seat wide pressed key count for the key of this event
402  */
403 uint32_t
404 libinput_event_keyboard_get_seat_key_count(
405         struct libinput_event_keyboard *event);
406
407 /**
408  * @defgroup event_pointer Pointer events
409  *
410  * Pointer events reflect motion, button and scroll events, as well as
411  * events from other axes.
412  */
413
414 /**
415  * @ingroup event_pointer
416  *
417  * @return The event time for this event
418  */
419 uint32_t
420 libinput_event_pointer_get_time(struct libinput_event_pointer *event);
421
422 /**
423  * @ingroup event_pointer
424  *
425  * Return the delta between the last event and the current event. For pointer
426  * events that are not of type LIBINPUT_EVENT_POINTER_MOTION, this function
427  * returns 0.
428  *
429  * @note It is an application bug to call this function for events other than
430  * LIBINPUT_EVENT_POINTER_MOTION.
431  *
432  * @return the relative x movement since the last event
433  */
434 double
435 libinput_event_pointer_get_dx(struct libinput_event_pointer *event);
436
437 /**
438  * @ingroup event_pointer
439  *
440  * Return the delta between the last event and the current event. For pointer
441  * events that are not of type LIBINPUT_EVENT_POINTER_MOTION, this function
442  * returns 0.
443  *
444  * @note It is an application bug to call this function for events other than
445  * LIBINPUT_EVENT_POINTER_MOTION.
446  *
447  * @return the relative y movement since the last event
448  */
449 double
450 libinput_event_pointer_get_dy(struct libinput_event_pointer *event);
451
452 /**
453  * @ingroup event_pointer
454  *
455  * Return the current absolute x coordinate of the pointer event, in mm from
456  * the top left corner of the device. To get the corresponding output screen
457  * coordinate, use libinput_event_pointer_get_x_transformed().
458  *
459  * For pointer events that are not of type
460  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
461  *
462  * @note It is an application bug to call this function for events other than
463  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE.
464  *
465  * @return the current absolute x coordinate
466  */
467 double
468 libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event);
469
470 /**
471  * @ingroup event_pointer
472  *
473  * Return the current absolute y coordinate of the pointer event, in mm from
474  * the top left corner of the device. To get the corresponding output screen
475  * coordinate, use libinput_event_pointer_get_x_transformed().
476  *
477  * For pointer events that are not of type
478  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, this function returns 0.
479  *
480  * @note It is an application bug to call this function for events other than
481  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE.
482  *
483  * @return the current absolute y coordinate
484  */
485 double
486 libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event);
487
488 /**
489  * @ingroup event_pointer
490  *
491  * Return the current absolute x coordinate of the pointer event, transformed to
492  * screen coordinates.
493  *
494  * For pointer events that are not of type
495  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, the return value of this function is
496  * undefined.
497  *
498  * @note It is an application bug to call this function for events other than
499  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE.
500  *
501  * @param event The libinput pointer event
502  * @param width The current output screen width
503  * @return the current absolute x coordinate transformed to a screen coordinate
504  */
505 double
506 libinput_event_pointer_get_absolute_x_transformed(
507         struct libinput_event_pointer *event,
508         uint32_t width);
509
510 /**
511  * @ingroup event_pointer
512  *
513  * Return the current absolute y coordinate of the pointer event, transformed to
514  * screen coordinates.
515  *
516  * For pointer events that are not of type
517  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE, the return value of this function is
518  * undefined.
519  *
520  * @note It is an application bug to call this function for events other than
521  * LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE.
522  *
523  * @param event The libinput pointer event
524  * @param height The current output screen height
525  * @return the current absolute y coordinate transformed to a screen coordinate
526  */
527 double
528 libinput_event_pointer_get_absolute_y_transformed(
529         struct libinput_event_pointer *event,
530         uint32_t height);
531
532 /**
533  * @ingroup event_pointer
534  *
535  * Return the button that triggered this event.
536  * For pointer events that are not of type LIBINPUT_EVENT_POINTER_BUTTON,
537  * this function returns 0.
538  *
539  * @note It is an application bug to call this function for events other than
540  * LIBINPUT_EVENT_POINTER_BUTTON.
541  *
542  * @return the button triggering this event
543  */
544 uint32_t
545 libinput_event_pointer_get_button(struct libinput_event_pointer *event);
546
547 /**
548  * @ingroup event_pointer
549  *
550  * Return the button state that triggered this event.
551  * For pointer events that are not of type LIBINPUT_EVENT_POINTER_BUTTON,
552  * this function returns 0.
553  *
554  * @note It is an application bug to call this function for events other than
555  * LIBINPUT_EVENT_POINTER_BUTTON.
556  *
557  * @return the button state triggering this event
558  */
559 enum libinput_button_state
560 libinput_event_pointer_get_button_state(struct libinput_event_pointer *event);
561
562 /**
563  * @ingroup event_pointer
564  *
565  * For the button of a LIBINPUT_EVENT_POINTER_BUTTON event, return the total
566  * number of buttons pressed on all devices on the associated seat after the
567  * the event was triggered.
568  *
569  " @note It is an application bug to call this function for events other than
570  * LIBINPUT_EVENT_POINTER_BUTTON. For other events, this function returns 0.
571  *
572  * @return the seat wide pressed button count for the key of this event
573  */
574 uint32_t
575 libinput_event_pointer_get_seat_button_count(
576         struct libinput_event_pointer *event);
577
578 /**
579  * @ingroup event_pointer
580  *
581  * Return the axis that triggered this event.
582  * For pointer events that are not of type LIBINPUT_EVENT_POINTER_AXIS,
583  * this function returns 0.
584  *
585  * @note It is an application bug to call this function for events other than
586  * LIBINPUT_EVENT_POINTER_AXIS.
587  *
588  * @return the axis triggering this event
589  */
590 enum libinput_pointer_axis
591 libinput_event_pointer_get_axis(struct libinput_event_pointer *event);
592
593 /**
594  * @ingroup event_pointer
595  *
596  * Return the axis value of the given axis. The interpretation of the value
597  * is dependent on the axis. For the two scrolling axes
598  * LIBINPUT_POINTER_AXIS_VERTICAL_SCROLL and
599  * LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL, the value of the event is in
600  * relative scroll units, with the positive direction being down or right,
601  * respectively. The dimension of a scroll unit is equal to one unit of
602  * motion in the respective axis, where applicable (e.g. touchpad two-finger
603  * scrolling).
604  *
605  * For pointer events that are not of type LIBINPUT_EVENT_POINTER_AXIS,
606  * this function returns 0.
607  *
608  * @note It is an application bug to call this function for events other than
609  * LIBINPUT_EVENT_POINTER_AXIS.
610  *
611  * @return the axis value of this event
612  */
613 double
614 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event);
615
616 /**
617  * @ingroup event_pointer
618  *
619  * @return The generic libinput_event of this event
620  */
621 struct libinput_event *
622 libinput_event_pointer_get_base_event(struct libinput_event_pointer *event);
623
624
625 /**
626  * @defgroup event_touch Touch events
627  *
628  * Events from absolute touch devices.
629  */
630
631 /**
632  * @ingroup event_touch
633  *
634  * @return The event time for this event
635  */
636 uint32_t
637 libinput_event_touch_get_time(struct libinput_event_touch *event);
638
639 /**
640  * @ingroup event_touch
641  *
642  * Get the slot of this touch event. See the kernel's multitouch
643  * protocol B documentation for more information.
644  *
645  * If the touch event has no assigned slot, for example if it is from a
646  * single touch device, this function returns -1.
647  *
648  * @note this function should not be called for LIBINPUT_EVENT_TOUCH_CANCEL or
649  * LIBINPUT_EVENT_TOUCH_FRAME.
650  *
651  * @return The slot of this touch event
652  */
653 int32_t
654 libinput_event_touch_get_slot(struct libinput_event_touch *event);
655
656 /**
657  * @ingroup event_touch
658  *
659  * Get the seat slot of the touch event. A seat slot is a non-negative seat
660  * wide unique identifier of an active touch point.
661  *
662  * Events from single touch devices will be represented as one individual
663  * touch point per device.
664  *
665  * @note this function should not be called for LIBINPUT_EVENT_TOUCH_CANCEL or
666  * LIBINPUT_EVENT_TOUCH_FRAME.
667  *
668  * @return The seat slot of the touch event
669  */
670 int32_t
671 libinput_event_touch_get_seat_slot(struct libinput_event_touch *event);
672
673 /**
674  * @ingroup event_touch
675  *
676  * Return the current absolute x coordinate of the touch event, in mm from
677  * the top left corner of the device. To get the corresponding output screen
678  * coordinate, use libinput_event_touch_get_x_transformed().
679  *
680  * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
681  * LIBINPUT_EVENT_TOUCH_MOTION.
682  *
683  * @param event The libinput touch event
684  * @return the current absolute x coordinate
685  */
686 double
687 libinput_event_touch_get_x(struct libinput_event_touch *event);
688
689 /**
690  * @ingroup event_touch
691  *
692  * Return the current absolute y coordinate of the touch event, in mm from
693  * the top left corner of the device. To get the corresponding output screen
694  * coordinate, use libinput_event_touch_get_y_transformed().
695  *
696  * For LIBINPUT_EVENT_TOUCH_UP 0 is returned.
697  *
698  * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
699  * LIBINPUT_EVENT_TOUCH_MOTION.
700  *
701  * @param event The libinput touch event
702  * @return the current absolute y coordinate
703  */
704 double
705 libinput_event_touch_get_y(struct libinput_event_touch *event);
706
707 /**
708  * @ingroup event_touch
709  *
710  * Return the current absolute x coordinate of the touch event, transformed to
711  * screen coordinates.
712  *
713  * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
714  * LIBINPUT_EVENT_TOUCH_MOTION.
715  *
716  * @param event The libinput touch event
717  * @param width The current output screen width
718  * @return the current absolute x coordinate transformed to a screen coordinate
719  */
720 double
721 libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
722                                        uint32_t width);
723
724 /**
725  * @ingroup event_touch
726  *
727  * Return the current absolute y coordinate of the touch event, transformed to
728  * screen coordinates.
729  *
730  * @note this function should only be called for LIBINPUT_EVENT_TOUCH_DOWN and
731  * LIBINPUT_EVENT_TOUCH_MOTION.
732  *
733  * @param event The libinput touch event
734  * @param height The current output screen height
735  * @return the current absolute y coordinate transformed to a screen coordinate
736  */
737 double
738 libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
739                                        uint32_t height);
740
741 /**
742  * @ingroup event_touch
743  *
744  * @return The generic libinput_event of this event
745  */
746 struct libinput_event *
747 libinput_event_touch_get_base_event(struct libinput_event_touch *event);
748
749 /**
750  * @defgroup base Initialization and manipulation of libinput contexts
751  */
752
753 struct libinput_interface {
754         /**
755          * Open the device at the given path with the flags provided and
756          * return the fd.
757          *
758          * @param path The device path to open
759          * @param flags Flags as defined by open(2)
760          * @param user_data The user_data provided in
761          * libinput_udev_create_for_seat()
762          *
763          * @return the file descriptor, or a negative errno on failure.
764          */
765         int (*open_restricted)(const char *path, int flags, void *user_data);
766         /**
767          * Close the file descriptor.
768          *
769          * @param fd The file descriptor to close
770          * @param user_data The user_data provided in
771          * libinput_udev_create_for_seat()
772          */
773         void (*close_restricted)(int fd, void *user_data);
774 };
775
776 /**
777  * @ingroup base
778  *
779  * Create a new libinput context from udev, for input devices matching
780  * the given seat ID. New devices or devices removed will appear as events
781  * during libinput_dispatch.
782  *
783  * libinput_udev_create_for_seat() succeeds even if no input device is
784  * available in this seat, or if devices are available but fail to open in
785  * @ref libinput_interface::open_restricted. Devices that do not have the
786  * minimum capabilities to be recognized as pointer, keyboard or touch
787  * device are ignored. Such devices and those that failed to open
788  * ignored until the next call to libinput_resume().
789  *
790  * @param interface The callback interface
791  * @param user_data Caller-specific data passed to the various callback
792  * interfaces.
793  * @param udev An already initialized udev context
794  * @param seat_id A seat identifier. This string must not be NULL.
795  *
796  * @return An initialized libinput context, ready to handle events or NULL on
797  * error.
798  */
799 struct libinput *
800 libinput_udev_create_for_seat(const struct libinput_interface *interface,
801                               void *user_data,
802                               struct udev *udev,
803                               const char *seat_id);
804
805 /**
806  * @ingroup base
807  *
808  * Create a new libinput context that requires the caller to manually add or
809  * remove devices with libinput_path_add_device() and
810  * libinput_path_remove_device().
811  *
812  * The context is fully initialized but will not generate events until at
813  * least one device has been added.
814  *
815  * @param interface The callback interface
816  * @param user_data Caller-specific data passed to the various callback
817  * interfaces.
818  *
819  * @return An initialized, empty libinput context.
820  */
821 struct libinput *
822 libinput_path_create_context(const struct libinput_interface *interface,
823                              void *user_data);
824
825 /**
826  * @ingroup base
827  *
828  * Add a device to a libinput context initialized with
829  * libinput_path_create_context(). If successful, the device will be
830  * added to the internal list and re-opened on libinput_resume(). The device
831  * can be removed with libinput_path_remove_device().
832  *
833  * If the device was successfully initialized, it is returned in the device
834  * argument. The lifetime of the returned device pointer is limited until
835  * the next libinput_dispatch(), use libinput_device_ref() to keep a permanent
836  * reference.
837  *
838  * @param libinput A previously initialized libinput context
839  * @param path Path to an input device
840  * @return The newly initiated device on success, or NULL on failure.
841  *
842  * @note It is an application bug to call this function on a libinput
843  * context initialized with libinput_udev_create_for_seat().
844  */
845 struct libinput_device *
846 libinput_path_add_device(struct libinput *libinput,
847                          const char *path);
848
849 /**
850  * @ingroup base
851  *
852  * Remove a device from a libinput context initialized with
853  * libinput_path_create_context() or added to such a context with
854  * libinput_path_add_device().
855  *
856  * Events already processed from this input device are kept in the queue,
857  * the LIBINPUT_EVENT_DEVICE_REMOVED event marks the end of events for this
858  * device.
859  *
860  * If no matching device exists, this function does nothing.
861  *
862  * @param device A libinput device
863  *
864  * @note It is an application bug to call this function on a libinput
865  * context initialized with libinput_udev_create_for_seat().
866  */
867 void
868 libinput_path_remove_device(struct libinput_device *device);
869
870 /**
871  * @ingroup base
872  *
873  * libinput keeps a single file descriptor for all events. Call into
874  * libinput_dispatch() if any events become available on this fd.
875  *
876  * @return the file descriptor used to notify of pending events.
877  */
878 int
879 libinput_get_fd(struct libinput *libinput);
880
881 /**
882  * @ingroup base
883  *
884  * Main event dispatchment function. Reads events of the file descriptors
885  * and processes them internally. Use libinput_get_event() to retrieve the
886  * events.
887  *
888  * Dispatching does not necessarily queue libinput events.
889  *
890  * @param libinput A previously initialized libinput context
891  *
892  * @return 0 on success, or a negative errno on failure
893  */
894 int
895 libinput_dispatch(struct libinput *libinput);
896
897 /**
898  * @ingroup base
899  *
900  * Retrieve the next event from libinput's internal event queue.
901  *
902  * After handling the retrieved event, the caller must destroy it using
903  * libinput_event_destroy().
904  *
905  * @param libinput A previously initialized libinput context
906  * @return The next available event, or NULL if no event is available.
907  */
908 struct libinput_event *
909 libinput_get_event(struct libinput *libinput);
910
911 /**
912  * @ingroup base
913  *
914  * Return the type of the next event in the internal queue. This function
915  * does not pop the event off the queue and the next call to
916  * libinput_get_event() returns that event.
917  *
918  * @param libinput A previously initialized libinput context
919  * @return The event type of the next available event or LIBINPUT_EVENT_NONE
920  * if no event is availble.
921  */
922 enum libinput_event_type
923 libinput_next_event_type(struct libinput *libinput);
924
925 /**
926  * @ingroup base
927  *
928  * @param libinput A previously initialized libinput context
929  * @return the caller-specific data previously assigned in
930  * libinput_create_udev().
931  */
932 void *
933 libinput_get_user_data(struct libinput *libinput);
934
935 /**
936  * @ingroup base
937  *
938  * Resume a suspended libinput context. This re-enables device
939  * monitoring and adds existing devices.
940  *
941  * @param libinput A previously initialized libinput context
942  * @see libinput_suspend
943  *
944  * @return 0 on success or -1 on failure
945  */
946 int
947 libinput_resume(struct libinput *libinput);
948
949 /**
950  * @ingroup base
951  *
952  * Suspend monitoring for new devices and close existing devices.
953  * This all but terminates libinput but does keep the context
954  * valid to be resumed with libinput_resume().
955  *
956  * @param libinput A previously initialized libinput context
957  */
958 void
959 libinput_suspend(struct libinput *libinput);
960
961 /**
962  * @ingroup base
963  *
964  * Destroy the libinput context. After this, object references associated with
965  * the destroyed context are invalid and may not be interacted with.
966  *
967  * @param libinput A previously initialized libinput context
968  */
969 void
970 libinput_destroy(struct libinput *libinput);
971
972 /**
973  * @ingroup base
974  *
975  * Set the global log priority. Messages with priorities equal to or
976  * higher than the argument will be printed to the current log handler.
977  *
978  * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
979  *
980  * @param priority The minimum priority of log messages to print.
981  *
982  * @see libinput_log_set_handler
983  * @see libinput_log_get_priority
984  */
985 void
986 libinput_log_set_priority(enum libinput_log_priority priority);
987
988 /**
989  * @ingroup base
990  *
991  * Get the global log priority. Messages with priorities equal to or
992  * higher than the argument will be printed to the current log handler.
993  *
994  * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
995  *
996  * @return The minimum priority of log messages to print.
997  *
998  * @see libinput_log_set_handler
999  * @see libinput_log_set_priority
1000  */
1001 enum libinput_log_priority
1002 libinput_log_get_priority(void);
1003
1004 /**
1005  * @ingroup base
1006  *
1007  * Log handler type for custom logging.
1008  *
1009  * @param priority The priority of the current message
1010  * @param user_data Caller-specific data pointer as previously passed into
1011  * libinput_log_set_handler()
1012  * @param format Message format in printf-style
1013  * @param args Message arguments
1014  *
1015  * @see libinput_set_log_priority
1016  * @see libinput_log_set_handler
1017  */
1018 typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
1019                                      void *user_data,
1020                                      const char *format, va_list args)
1021            LIBINPUT_ATTRIBUTE_PRINTF(3, 0);
1022
1023 /**
1024  * @ingroup base
1025  *
1026  * Set the global log handler. Messages with priorities equal to or higher
1027  * than the current log priority will be passed to the given
1028  * log handler.
1029  *
1030  * The default log handler prints to stderr.
1031  *
1032  * @param log_handler The log handler for library messages.
1033  * @param user_data Caller-specific data pointer, passed into the log
1034  * handler.
1035  *
1036  * @see libinput_log_set_handler
1037  */
1038 void
1039 libinput_log_set_handler(libinput_log_handler log_handler,
1040                          void *user_data);
1041
1042 /**
1043  * @defgroup seat Initialization and manipulation of seats
1044  *
1045  * A seat has two identifiers, the physical name and the logical name. The
1046  * physical name is summarized as the list of devices a process on the same
1047  * physical seat has access to.
1048  *
1049  * The logical seat name is the seat name for a logical group of devices. A
1050  * compositor may use that to create additonal seats as independent device
1051  * sets. Alternatively, a compositor may limit itself to a single logical
1052  * seat, leaving a second compositor to manage devices on the other logical
1053  * seats.
1054  *
1055  * @code
1056  * +---+--------+------------+------------------------+------------+
1057  * |   | event0 |            |                        | log seat A |
1058  * | K +--------+            |                        +------------+
1059  * | e | event1 | phys seat0 |    libinput context 1  |            |
1060  * | r +--------+            |                        | log seat B |
1061  * | n | event2 |            |                        |            |
1062  * | e +--------+------------+------------------------+------------+
1063  * | l | event3 | phys seat1 |    libinput context 2  | log seat C |
1064  * +---+--------+------------+------------------------+------------+
1065  * @endcode
1066  */
1067
1068 /**
1069  * @ingroup seat
1070  *
1071  * Increase the refcount of the seat. A seat will be freed whenever the
1072  * refcount reaches 0. This may happen during dispatch if the
1073  * seat was removed from the system. A caller must ensure to reference
1074  * the seat correctly to avoid dangling pointers.
1075  *
1076  * @param seat A previously obtained seat
1077  */
1078 void
1079 libinput_seat_ref(struct libinput_seat *seat);
1080
1081 /**
1082  * @ingroup seat
1083  *
1084  * Decrease the refcount of the seat. A seat will be freed whenever the
1085  * refcount reaches 0. This may happen during dispatch if the
1086  * seat was removed from the system. A caller must ensure to reference
1087  * the seat correctly to avoid dangling pointers.
1088  *
1089  * @param seat A previously obtained seat
1090  */
1091 void
1092 libinput_seat_unref(struct libinput_seat *seat);
1093
1094 /**
1095  * @ingroup seat
1096  *
1097  * Set caller-specific data associated with this seat. libinput does
1098  * not manage, look at, or modify this data. The caller must ensure the
1099  * data is valid.
1100  *
1101  * @param seat A previously obtained seat
1102  * @param user_data Caller-specific data pointer
1103  * @see libinput_seat_get_user_data
1104  */
1105 void
1106 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data);
1107
1108 /**
1109  * @ingroup seat
1110  *
1111  * Get the caller-specific data associated with this seat, if any.
1112  *
1113  * @param seat A previously obtained seat
1114  * @return Caller-specific data pointer or NULL if none was set
1115  * @see libinput_seat_set_user_data
1116  */
1117 void *
1118 libinput_seat_get_user_data(struct libinput_seat *seat);
1119
1120 /**
1121  * @ingroup seat
1122  *
1123  * Return the physical name of the seat. For libinput contexts created from
1124  * udev, this is always the same value as passed into
1125  * libinput_udev_create_for_seat() and all seats from that context will have
1126  * the same physical name.
1127  *
1128  * The physical name of the seat is one that is usually set by the system or
1129  * lower levels of the stack. In most cases, this is the base filter for
1130  * devices - devices assigned to seats outside the current seat will not
1131  * be available to the caller.
1132  *
1133  * @param seat A previously obtained seat
1134  * @return the physical name of this seat
1135  */
1136 const char *
1137 libinput_seat_get_physical_name(struct libinput_seat *seat);
1138
1139 /**
1140  * @ingroup seat
1141  *
1142  * Return the logical name of the seat. This is an identifier to group sets
1143  * of devices within the compositor.
1144  *
1145  * @param seat A previously obtained seat
1146  * @return the logical name of this seat
1147  */
1148 const char *
1149 libinput_seat_get_logical_name(struct libinput_seat *seat);
1150
1151 /**
1152  * @defgroup device Initialization and manipulation of input devices
1153  */
1154
1155 /**
1156  * @ingroup device
1157  *
1158  * Increase the refcount of the input device. An input device will be freed
1159  * whenever the refcount reaches 0. This may happen during dispatch if the
1160  * device was removed from the system. A caller must ensure to reference
1161  * the device correctly to avoid dangling pointers.
1162  *
1163  * @param device A previously obtained device
1164  */
1165 void
1166 libinput_device_ref(struct libinput_device *device);
1167
1168 /**
1169  * @ingroup device
1170  *
1171  * Decrease the refcount of the input device. An input device will be freed
1172  * whenever the refcount reaches 0. This may happen during dispatch if the
1173  * device was removed from the system. A caller must ensure to reference
1174  * the device correctly to avoid dangling pointers.
1175  *
1176  * @param device A previously obtained device
1177  */
1178 void
1179 libinput_device_unref(struct libinput_device *device);
1180
1181 /**
1182  * @ingroup device
1183  *
1184  * Set caller-specific data associated with this input device. libinput does
1185  * not manage, look at, or modify this data. The caller must ensure the
1186  * data is valid.
1187  *
1188  * @param device A previously obtained device
1189  * @param user_data Caller-specific data pointer
1190  * @see libinput_device_get_user_data
1191  */
1192 void
1193 libinput_device_set_user_data(struct libinput_device *device, void *user_data);
1194
1195 /**
1196  * @ingroup device
1197  *
1198  * Get the caller-specific data associated with this input device, if any.
1199  *
1200  * @param device A previously obtained device
1201  * @return Caller-specific data pointer or NULL if none was set
1202  * @see libinput_device_set_user_data
1203  */
1204 void *
1205 libinput_device_get_user_data(struct libinput_device *device);
1206
1207 /**
1208  * @ingroup device
1209  *
1210  * Get the system name of the device.
1211  *
1212  * @param device A previously obtained device
1213  * @return System name of the device
1214  */
1215 const char *
1216 libinput_device_get_sysname(struct libinput_device *device);
1217
1218 /**
1219  * @ingroup device
1220  *
1221  * A device may be mapped to a single output, or all available outputs. If a
1222  * device is mapped to a single output only, a relative device may not move
1223  * beyond the boundaries of this output. An absolute device has its input
1224  * coordinates mapped to the extents of this output.
1225  *
1226  * @return the name of the output this device is mapped to, or NULL if no
1227  * output is set
1228  */
1229 const char *
1230 libinput_device_get_output_name(struct libinput_device *device);
1231
1232 /**
1233  * @ingroup device
1234  *
1235  * Get the seat associated with this input device.
1236  *
1237  * A seat can be uniquely identified by the physical and logical seat name.
1238  * There will ever be only one seat instance with a given physical and logical
1239  * seat name pair at any given time, but if no external reference is kept, it
1240  * may be destroyed if no device belonging to it is left.
1241  *
1242  * @param device A previously obtained device
1243  * @return The seat this input device belongs to
1244  */
1245 struct libinput_seat *
1246 libinput_device_get_seat(struct libinput_device *device);
1247
1248 /**
1249  * @ingroup device
1250  *
1251  * Update the LEDs on the device, if any. If the device does not have
1252  * LEDs, or does not have one or more of the LEDs given in the mask, this
1253  * function does nothing.
1254  *
1255  * @param device A previously obtained device
1256  * @param leds A mask of the LEDs to set, or unset.
1257  */
1258 void
1259 libinput_device_led_update(struct libinput_device *device,
1260                            enum libinput_led leds);
1261
1262 /**
1263  * @ingroup device
1264  *
1265  * Set the bitmask in keys to the bitmask of the keys present on the device
1266  * (see linux/input.h), up to size characters.
1267  *
1268  * @param device A current input device
1269  * @param keys An array filled with the bitmask for the keys
1270  * @param size Size of the keys array
1271  *
1272  * @return The number of valid bytes in keys, or a negative errno on failure
1273  */
1274 int
1275 libinput_device_get_keys(struct libinput_device *device,
1276                          char *keys, size_t size);
1277
1278 /**
1279  * @ingroup device
1280  *
1281  * Apply the 3x3 transformation matrix to absolute device coordinates. This
1282  * matrix has no effect on relative events.
1283  *
1284  * Given a 6-element array [a, b, c, d, e, f], the matrix is applied as
1285  * @code
1286  * [ a  b  c ]   [ x ]
1287  * [ d  e  f ] * [ y ]
1288  * [ 0  0  1 ]   [ 1 ]
1289  * @endcode
1290  */
1291 void
1292 libinput_device_calibrate(struct libinput_device *device,
1293                           float calibration[6]);
1294
1295 /**
1296  * @ingroup device
1297  *
1298  * Check if the given device has the specified capability
1299  *
1300  * @return 1 if the given device has the capability or 0 if not
1301  */
1302 int
1303 libinput_device_has_capability(struct libinput_device *device,
1304                                enum libinput_device_capability capability);
1305
1306 #ifdef __cplusplus
1307 }
1308 #endif
1309
1310 #endif /* LIBINPUT_H */