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.
29 #include <sys/epoll.h>
34 #include "libinput-private.h"
38 struct libinput_source {
39 libinput_source_dispatch_t dispatch;
45 struct libinput_event {
46 enum libinput_event_type type;
47 struct libinput_device *device;
50 struct libinput_event_device_notify {
51 struct libinput_event base;
54 struct libinput_event_keyboard {
55 struct libinput_event base;
58 uint32_t seat_key_count;
59 enum libinput_keyboard_key_state state;
62 struct libinput_event_pointer {
63 struct libinput_event base;
68 uint32_t seat_button_count;
69 enum libinput_button_state state;
70 enum libinput_pointer_axis axis;
74 struct libinput_event_touch {
75 struct libinput_event base;
84 libinput_default_log_func(enum libinput_log_priority priority,
86 const char *format, va_list args)
91 case LIBINPUT_LOG_PRIORITY_DEBUG: prefix = "debug"; break;
92 case LIBINPUT_LOG_PRIORITY_INFO: prefix = "info"; break;
93 case LIBINPUT_LOG_PRIORITY_ERROR: prefix = "error"; break;
94 default: prefix="<invalid priority>"; break;
97 fprintf(stderr, "libinput %s: ", prefix);
98 vfprintf(stderr, format, args);
102 enum libinput_log_priority priority;
103 libinput_log_handler handler;
107 static struct log_data log_data = {
108 .priority = LIBINPUT_LOG_PRIORITY_ERROR,
109 .handler = libinput_default_log_func,
114 log_msg_va(enum libinput_log_priority priority,
118 if (log_data.handler && log_data.priority <= priority)
119 log_data.handler(priority, log_data.user_data, format, args);
123 log_msg(enum libinput_log_priority priority, const char *format, ...)
127 va_start(args, format);
128 log_msg_va(priority, format, args);
133 libinput_log_set_priority(enum libinput_log_priority priority)
135 log_data.priority = priority;
138 LIBINPUT_EXPORT enum libinput_log_priority
139 libinput_log_get_priority(void)
141 return log_data.priority;
145 libinput_log_set_handler(libinput_log_handler log_handler,
148 log_data.handler = log_handler;
149 log_data.user_data = user_data;
153 libinput_post_event(struct libinput *libinput,
154 struct libinput_event *event);
156 LIBINPUT_EXPORT enum libinput_event_type
157 libinput_event_get_type(struct libinput_event *event)
162 LIBINPUT_EXPORT struct libinput *
163 libinput_event_get_context(struct libinput_event *event)
165 return event->device->seat->libinput;
168 LIBINPUT_EXPORT struct libinput_device *
169 libinput_event_get_device(struct libinput_event *event)
171 return event->device;
174 LIBINPUT_EXPORT struct libinput_event_pointer *
175 libinput_event_get_pointer_event(struct libinput_event *event)
177 switch (event->type) {
178 case LIBINPUT_EVENT_NONE:
179 abort(); /* not used as actual event type */
180 case LIBINPUT_EVENT_DEVICE_ADDED:
181 case LIBINPUT_EVENT_DEVICE_REMOVED:
182 case LIBINPUT_EVENT_KEYBOARD_KEY:
184 case LIBINPUT_EVENT_POINTER_MOTION:
185 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
186 case LIBINPUT_EVENT_POINTER_BUTTON:
187 case LIBINPUT_EVENT_POINTER_AXIS:
188 return (struct libinput_event_pointer *) event;
189 case LIBINPUT_EVENT_TOUCH_DOWN:
190 case LIBINPUT_EVENT_TOUCH_UP:
191 case LIBINPUT_EVENT_TOUCH_MOTION:
192 case LIBINPUT_EVENT_TOUCH_CANCEL:
193 case LIBINPUT_EVENT_TOUCH_FRAME:
200 LIBINPUT_EXPORT struct libinput_event_keyboard *
201 libinput_event_get_keyboard_event(struct libinput_event *event)
203 switch (event->type) {
204 case LIBINPUT_EVENT_NONE:
205 abort(); /* not used as actual event type */
206 case LIBINPUT_EVENT_DEVICE_ADDED:
207 case LIBINPUT_EVENT_DEVICE_REMOVED:
209 case LIBINPUT_EVENT_KEYBOARD_KEY:
210 return (struct libinput_event_keyboard *) event;
211 case LIBINPUT_EVENT_POINTER_MOTION:
212 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
213 case LIBINPUT_EVENT_POINTER_BUTTON:
214 case LIBINPUT_EVENT_POINTER_AXIS:
215 case LIBINPUT_EVENT_TOUCH_DOWN:
216 case LIBINPUT_EVENT_TOUCH_UP:
217 case LIBINPUT_EVENT_TOUCH_MOTION:
218 case LIBINPUT_EVENT_TOUCH_CANCEL:
219 case LIBINPUT_EVENT_TOUCH_FRAME:
226 LIBINPUT_EXPORT struct libinput_event_touch *
227 libinput_event_get_touch_event(struct libinput_event *event)
229 switch (event->type) {
230 case LIBINPUT_EVENT_NONE:
231 abort(); /* not used as actual event type */
232 case LIBINPUT_EVENT_DEVICE_ADDED:
233 case LIBINPUT_EVENT_DEVICE_REMOVED:
234 case LIBINPUT_EVENT_KEYBOARD_KEY:
235 case LIBINPUT_EVENT_POINTER_MOTION:
236 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
237 case LIBINPUT_EVENT_POINTER_BUTTON:
238 case LIBINPUT_EVENT_POINTER_AXIS:
240 case LIBINPUT_EVENT_TOUCH_DOWN:
241 case LIBINPUT_EVENT_TOUCH_UP:
242 case LIBINPUT_EVENT_TOUCH_MOTION:
243 case LIBINPUT_EVENT_TOUCH_CANCEL:
244 case LIBINPUT_EVENT_TOUCH_FRAME:
245 return (struct libinput_event_touch *) event;
251 LIBINPUT_EXPORT struct libinput_event_device_notify *
252 libinput_event_get_device_notify_event(struct libinput_event *event)
254 switch (event->type) {
255 case LIBINPUT_EVENT_NONE:
256 abort(); /* not used as actual event type */
257 case LIBINPUT_EVENT_DEVICE_ADDED:
258 case LIBINPUT_EVENT_DEVICE_REMOVED:
259 return (struct libinput_event_device_notify *) event;
260 case LIBINPUT_EVENT_KEYBOARD_KEY:
261 case LIBINPUT_EVENT_POINTER_MOTION:
262 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
263 case LIBINPUT_EVENT_POINTER_BUTTON:
264 case LIBINPUT_EVENT_POINTER_AXIS:
265 case LIBINPUT_EVENT_TOUCH_DOWN:
266 case LIBINPUT_EVENT_TOUCH_UP:
267 case LIBINPUT_EVENT_TOUCH_MOTION:
268 case LIBINPUT_EVENT_TOUCH_CANCEL:
269 case LIBINPUT_EVENT_TOUCH_FRAME:
276 LIBINPUT_EXPORT uint32_t
277 libinput_event_keyboard_get_time(struct libinput_event_keyboard *event)
282 LIBINPUT_EXPORT uint32_t
283 libinput_event_keyboard_get_key(struct libinput_event_keyboard *event)
288 LIBINPUT_EXPORT enum libinput_keyboard_key_state
289 libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event)
294 LIBINPUT_EXPORT uint32_t
295 libinput_event_keyboard_get_seat_key_count(
296 struct libinput_event_keyboard *event)
298 return event->seat_key_count;
301 LIBINPUT_EXPORT uint32_t
302 libinput_event_pointer_get_time(struct libinput_event_pointer *event)
307 LIBINPUT_EXPORT double
308 libinput_event_pointer_get_dx(struct libinput_event_pointer *event)
313 LIBINPUT_EXPORT double
314 libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
319 LIBINPUT_EXPORT double
320 libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
325 LIBINPUT_EXPORT double
326 libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
331 LIBINPUT_EXPORT double
332 libinput_event_pointer_get_absolute_x_transformed(
333 struct libinput_event_pointer *event,
336 struct evdev_device *device =
337 (struct evdev_device *) event->base.device;
339 return evdev_device_transform_x(device, event->x, width);
342 LIBINPUT_EXPORT double
343 libinput_event_pointer_get_absolute_y_transformed(
344 struct libinput_event_pointer *event,
347 struct evdev_device *device =
348 (struct evdev_device *) event->base.device;
350 return evdev_device_transform_y(device, event->y, height);
353 LIBINPUT_EXPORT uint32_t
354 libinput_event_pointer_get_button(struct libinput_event_pointer *event)
356 return event->button;
359 LIBINPUT_EXPORT enum libinput_button_state
360 libinput_event_pointer_get_button_state(struct libinput_event_pointer *event)
365 LIBINPUT_EXPORT uint32_t
366 libinput_event_pointer_get_seat_button_count(
367 struct libinput_event_pointer *event)
369 return event->seat_button_count;
372 LIBINPUT_EXPORT enum libinput_pointer_axis
373 libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
378 LIBINPUT_EXPORT double
379 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
384 LIBINPUT_EXPORT uint32_t
385 libinput_event_touch_get_time(struct libinput_event_touch *event)
390 LIBINPUT_EXPORT int32_t
391 libinput_event_touch_get_slot(struct libinput_event_touch *event)
396 LIBINPUT_EXPORT int32_t
397 libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
399 return event->seat_slot;
402 LIBINPUT_EXPORT double
403 libinput_event_touch_get_x(struct libinput_event_touch *event)
408 LIBINPUT_EXPORT double
409 libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
412 struct evdev_device *device =
413 (struct evdev_device *) event->base.device;
415 return evdev_device_transform_x(device, event->x, width);
418 LIBINPUT_EXPORT double
419 libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
422 struct evdev_device *device =
423 (struct evdev_device *) event->base.device;
425 return evdev_device_transform_y(device, event->y, height);
428 LIBINPUT_EXPORT double
429 libinput_event_touch_get_y(struct libinput_event_touch *event)
434 struct libinput_source *
435 libinput_add_fd(struct libinput *libinput,
437 libinput_source_dispatch_t dispatch,
440 struct libinput_source *source;
441 struct epoll_event ep;
443 source = malloc(sizeof *source);
447 source->dispatch = dispatch;
448 source->user_data = user_data;
451 memset(&ep, 0, sizeof ep);
453 ep.data.ptr = source;
455 if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
465 libinput_remove_source(struct libinput *libinput,
466 struct libinput_source *source)
468 epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL);
470 list_insert(&libinput->source_destroy_list, &source->link);
474 libinput_init(struct libinput *libinput,
475 const struct libinput_interface *interface,
476 const struct libinput_interface_backend *interface_backend,
479 libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
480 if (libinput->epoll_fd < 0)
483 libinput->events_len = 4;
484 libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
485 if (!libinput->events) {
486 close(libinput->epoll_fd);
490 libinput->interface = interface;
491 libinput->interface_backend = interface_backend;
492 libinput->user_data = user_data;
493 list_init(&libinput->source_destroy_list);
494 list_init(&libinput->seat_list);
496 if (libinput_timer_subsys_init(libinput) != 0) {
497 free(libinput->events);
498 close(libinput->epoll_fd);
506 libinput_device_destroy(struct libinput_device *device);
509 libinput_seat_destroy(struct libinput_seat *seat);
512 libinput_drop_destroyed_sources(struct libinput *libinput)
514 struct libinput_source *source, *next;
516 list_for_each_safe(source, next, &libinput->source_destroy_list, link)
518 list_init(&libinput->source_destroy_list);
522 libinput_destroy(struct libinput *libinput)
524 struct libinput_event *event;
525 struct libinput_device *device, *next_device;
526 struct libinput_seat *seat, *next_seat;
528 if (libinput == NULL)
531 libinput_suspend(libinput);
533 libinput->interface_backend->destroy(libinput);
535 while ((event = libinput_get_event(libinput)))
536 libinput_event_destroy(event);
538 free(libinput->events);
540 list_for_each_safe(seat, next_seat, &libinput->seat_list, link) {
541 list_for_each_safe(device, next_device,
544 libinput_device_destroy(device);
546 libinput_seat_destroy(seat);
549 libinput_timer_subsys_destroy(libinput);
550 libinput_drop_destroyed_sources(libinput);
551 close(libinput->epoll_fd);
556 libinput_event_destroy(struct libinput_event *event)
562 libinput_device_unref(event->device);
568 open_restricted(struct libinput *libinput,
569 const char *path, int flags)
571 return libinput->interface->open_restricted(path,
573 libinput->user_data);
577 close_restricted(struct libinput *libinput, int fd)
579 return libinput->interface->close_restricted(fd, libinput->user_data);
583 libinput_seat_init(struct libinput_seat *seat,
584 struct libinput *libinput,
585 const char *physical_name,
586 const char *logical_name,
587 libinput_seat_destroy_func destroy)
590 seat->libinput = libinput;
591 seat->physical_name = strdup(physical_name);
592 seat->logical_name = strdup(logical_name);
593 seat->destroy = destroy;
594 list_init(&seat->devices_list);
595 list_insert(&libinput->seat_list, &seat->link);
599 libinput_seat_ref(struct libinput_seat *seat)
605 libinput_seat_destroy(struct libinput_seat *seat)
607 list_remove(&seat->link);
608 free(seat->logical_name);
609 free(seat->physical_name);
614 libinput_seat_unref(struct libinput_seat *seat)
616 assert(seat->refcount > 0);
618 if (seat->refcount == 0)
619 libinput_seat_destroy(seat);
623 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
625 seat->user_data = user_data;
628 LIBINPUT_EXPORT void *
629 libinput_seat_get_user_data(struct libinput_seat *seat)
631 return seat->user_data;
634 LIBINPUT_EXPORT const char *
635 libinput_seat_get_physical_name(struct libinput_seat *seat)
637 return seat->physical_name;
640 LIBINPUT_EXPORT const char *
641 libinput_seat_get_logical_name(struct libinput_seat *seat)
643 return seat->logical_name;
647 libinput_device_init(struct libinput_device *device,
648 struct libinput_seat *seat)
651 device->refcount = 1;
655 libinput_device_ref(struct libinput_device *device)
661 libinput_device_destroy(struct libinput_device *device)
663 evdev_device_destroy((struct evdev_device *) device);
667 libinput_device_unref(struct libinput_device *device)
669 assert(device->refcount > 0);
671 if (device->refcount == 0)
672 libinput_device_destroy(device);
676 libinput_get_fd(struct libinput *libinput)
678 return libinput->epoll_fd;
682 libinput_dispatch(struct libinput *libinput)
684 struct libinput_source *source;
685 struct epoll_event ep[32];
688 count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0);
692 for (i = 0; i < count; ++i) {
693 source = ep[i].data.ptr;
694 if (source->fd == -1)
697 source->dispatch(source->user_data);
700 libinput_drop_destroyed_sources(libinput);
706 update_seat_key_count(struct libinput_seat *seat,
708 enum libinput_keyboard_key_state state)
710 assert(key >= 0 && key <= KEY_MAX);
713 case LIBINPUT_KEYBOARD_KEY_STATE_PRESSED:
714 return ++seat->button_count[key];
715 case LIBINPUT_KEYBOARD_KEY_STATE_RELEASED:
716 /* We might not have received the first PRESSED event. */
717 if (seat->button_count[key] == 0)
720 return --seat->button_count[key];
727 update_seat_button_count(struct libinput_seat *seat,
729 enum libinput_button_state state)
731 assert(button >= 0 && button <= KEY_MAX);
734 case LIBINPUT_BUTTON_STATE_PRESSED:
735 return ++seat->button_count[button];
736 case LIBINPUT_BUTTON_STATE_RELEASED:
737 /* We might not have received the first PRESSED event. */
738 if (seat->button_count[button] == 0)
741 return --seat->button_count[button];
748 init_event_base(struct libinput_event *event,
749 struct libinput_device *device,
750 enum libinput_event_type type)
753 event->device = device;
757 post_base_event(struct libinput_device *device,
758 enum libinput_event_type type,
759 struct libinput_event *event)
761 struct libinput *libinput = device->seat->libinput;
762 init_event_base(event, device, type);
763 libinput_post_event(libinput, event);
767 post_device_event(struct libinput_device *device,
768 enum libinput_event_type type,
769 struct libinput_event *event)
771 init_event_base(event, device, type);
772 libinput_post_event(device->seat->libinput, event);
776 notify_added_device(struct libinput_device *device)
778 struct libinput_event_device_notify *added_device_event;
780 added_device_event = zalloc(sizeof *added_device_event);
781 if (!added_device_event)
784 post_base_event(device,
785 LIBINPUT_EVENT_DEVICE_ADDED,
786 &added_device_event->base);
790 notify_removed_device(struct libinput_device *device)
792 struct libinput_event_device_notify *removed_device_event;
794 removed_device_event = zalloc(sizeof *removed_device_event);
795 if (!removed_device_event)
798 post_base_event(device,
799 LIBINPUT_EVENT_DEVICE_REMOVED,
800 &removed_device_event->base);
804 keyboard_notify_key(struct libinput_device *device,
807 enum libinput_keyboard_key_state state)
809 struct libinput_event_keyboard *key_event;
810 uint32_t seat_key_count;
812 key_event = zalloc(sizeof *key_event);
816 seat_key_count = update_seat_key_count(device->seat, key, state);
818 *key_event = (struct libinput_event_keyboard) {
822 .seat_key_count = seat_key_count,
825 post_device_event(device,
826 LIBINPUT_EVENT_KEYBOARD_KEY,
831 pointer_notify_motion(struct libinput_device *device,
836 struct libinput_event_pointer *motion_event;
838 motion_event = zalloc(sizeof *motion_event);
842 *motion_event = (struct libinput_event_pointer) {
848 post_device_event(device,
849 LIBINPUT_EVENT_POINTER_MOTION,
850 &motion_event->base);
854 pointer_notify_motion_absolute(struct libinput_device *device,
859 struct libinput_event_pointer *motion_absolute_event;
861 motion_absolute_event = zalloc(sizeof *motion_absolute_event);
862 if (!motion_absolute_event)
865 *motion_absolute_event = (struct libinput_event_pointer) {
871 post_device_event(device,
872 LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
873 &motion_absolute_event->base);
877 pointer_notify_button(struct libinput_device *device,
880 enum libinput_button_state state)
882 struct libinput_event_pointer *button_event;
883 int32_t seat_button_count;
885 button_event = zalloc(sizeof *button_event);
889 seat_button_count = update_seat_button_count(device->seat,
893 *button_event = (struct libinput_event_pointer) {
897 .seat_button_count = seat_button_count,
900 post_device_event(device,
901 LIBINPUT_EVENT_POINTER_BUTTON,
902 &button_event->base);
906 pointer_notify_axis(struct libinput_device *device,
908 enum libinput_pointer_axis axis,
911 struct libinput_event_pointer *axis_event;
913 axis_event = zalloc(sizeof *axis_event);
917 *axis_event = (struct libinput_event_pointer) {
923 post_device_event(device,
924 LIBINPUT_EVENT_POINTER_AXIS,
929 touch_notify_touch_down(struct libinput_device *device,
936 struct libinput_event_touch *touch_event;
938 touch_event = zalloc(sizeof *touch_event);
942 *touch_event = (struct libinput_event_touch) {
945 .seat_slot = seat_slot,
950 post_device_event(device,
951 LIBINPUT_EVENT_TOUCH_DOWN,
956 touch_notify_touch_motion(struct libinput_device *device,
963 struct libinput_event_touch *touch_event;
965 touch_event = zalloc(sizeof *touch_event);
969 *touch_event = (struct libinput_event_touch) {
972 .seat_slot = seat_slot,
977 post_device_event(device,
978 LIBINPUT_EVENT_TOUCH_MOTION,
983 touch_notify_touch_up(struct libinput_device *device,
988 struct libinput_event_touch *touch_event;
990 touch_event = zalloc(sizeof *touch_event);
994 *touch_event = (struct libinput_event_touch) {
997 .seat_slot = seat_slot,
1000 post_device_event(device,
1001 LIBINPUT_EVENT_TOUCH_UP,
1002 &touch_event->base);
1006 touch_notify_frame(struct libinput_device *device,
1009 struct libinput_event_touch *touch_event;
1011 touch_event = zalloc(sizeof *touch_event);
1015 *touch_event = (struct libinput_event_touch) {
1019 post_device_event(device,
1020 LIBINPUT_EVENT_TOUCH_FRAME,
1021 &touch_event->base);
1026 libinput_post_event(struct libinput *libinput,
1027 struct libinput_event *event)
1029 struct libinput_event **events = libinput->events;
1030 size_t events_len = libinput->events_len;
1031 size_t events_count = libinput->events_count;
1036 if (events_count > events_len) {
1038 events = realloc(events, events_len * sizeof *events);
1040 fprintf(stderr, "Failed to reallocate event ring "
1045 if (libinput->events_count > 0 && libinput->events_in == 0) {
1046 libinput->events_in = libinput->events_len;
1047 } else if (libinput->events_count > 0 &&
1048 libinput->events_out >= libinput->events_in) {
1049 move_len = libinput->events_len - libinput->events_out;
1050 new_out = events_len - move_len;
1051 memmove(events + new_out,
1052 events + libinput->events_out,
1053 move_len * sizeof *events);
1054 libinput->events_out = new_out;
1057 libinput->events = events;
1058 libinput->events_len = events_len;
1062 libinput_device_ref(event->device);
1064 libinput->events_count = events_count;
1065 events[libinput->events_in] = event;
1066 libinput->events_in = (libinput->events_in + 1) % libinput->events_len;
1069 LIBINPUT_EXPORT struct libinput_event *
1070 libinput_get_event(struct libinput *libinput)
1072 struct libinput_event *event;
1074 if (libinput->events_count == 0)
1077 event = libinput->events[libinput->events_out];
1078 libinput->events_out =
1079 (libinput->events_out + 1) % libinput->events_len;
1080 libinput->events_count--;
1085 LIBINPUT_EXPORT enum libinput_event_type
1086 libinput_next_event_type(struct libinput *libinput)
1088 struct libinput_event *event;
1090 if (libinput->events_count == 0)
1091 return LIBINPUT_EVENT_NONE;
1093 event = libinput->events[libinput->events_out];
1097 LIBINPUT_EXPORT void *
1098 libinput_get_user_data(struct libinput *libinput)
1100 return libinput->user_data;
1104 libinput_resume(struct libinput *libinput)
1106 return libinput->interface_backend->resume(libinput);
1109 LIBINPUT_EXPORT void
1110 libinput_suspend(struct libinput *libinput)
1112 libinput->interface_backend->suspend(libinput);
1115 LIBINPUT_EXPORT void
1116 libinput_device_set_user_data(struct libinput_device *device, void *user_data)
1118 device->user_data = user_data;
1121 LIBINPUT_EXPORT void *
1122 libinput_device_get_user_data(struct libinput_device *device)
1124 return device->user_data;
1127 LIBINPUT_EXPORT const char *
1128 libinput_device_get_sysname(struct libinput_device *device)
1130 return evdev_device_get_sysname((struct evdev_device *) device);
1133 LIBINPUT_EXPORT const char *
1134 libinput_device_get_output_name(struct libinput_device *device)
1136 return evdev_device_get_output((struct evdev_device *) device);
1139 LIBINPUT_EXPORT struct libinput_seat *
1140 libinput_device_get_seat(struct libinput_device *device)
1142 return device->seat;
1145 LIBINPUT_EXPORT void
1146 libinput_device_led_update(struct libinput_device *device,
1147 enum libinput_led leds)
1149 evdev_device_led_update((struct evdev_device *) device, leds);
1153 libinput_device_get_keys(struct libinput_device *device,
1154 char *keys, size_t size)
1156 return evdev_device_get_keys((struct evdev_device *) device,
1161 LIBINPUT_EXPORT void
1162 libinput_device_calibrate(struct libinput_device *device,
1163 float calibration[6])
1165 evdev_device_calibrate((struct evdev_device *) device, calibration);
1169 libinput_device_has_capability(struct libinput_device *device,
1170 enum libinput_device_capability capability)
1172 return evdev_device_has_capability((struct evdev_device *) device,
1176 LIBINPUT_EXPORT struct libinput_event *
1177 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
1179 return &event->base;
1182 LIBINPUT_EXPORT struct libinput_event *
1183 libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
1185 return &event->base;
1188 LIBINPUT_EXPORT struct libinput_event *
1189 libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
1191 return &event->base;
1194 LIBINPUT_EXPORT struct libinput_event *
1195 libinput_event_touch_get_base_event(struct libinput_event_touch *event)
1197 return &event->base;