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