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)
322 struct evdev_device *device =
323 (struct evdev_device *) event->base.device;
325 return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
328 LIBINPUT_EXPORT double
329 libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
331 struct evdev_device *device =
332 (struct evdev_device *) event->base.device;
334 return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
337 LIBINPUT_EXPORT double
338 libinput_event_pointer_get_absolute_x_transformed(
339 struct libinput_event_pointer *event,
342 struct evdev_device *device =
343 (struct evdev_device *) event->base.device;
345 return evdev_device_transform_x(device, event->x, width);
348 LIBINPUT_EXPORT double
349 libinput_event_pointer_get_absolute_y_transformed(
350 struct libinput_event_pointer *event,
353 struct evdev_device *device =
354 (struct evdev_device *) event->base.device;
356 return evdev_device_transform_y(device, event->y, height);
359 LIBINPUT_EXPORT uint32_t
360 libinput_event_pointer_get_button(struct libinput_event_pointer *event)
362 return event->button;
365 LIBINPUT_EXPORT enum libinput_button_state
366 libinput_event_pointer_get_button_state(struct libinput_event_pointer *event)
371 LIBINPUT_EXPORT uint32_t
372 libinput_event_pointer_get_seat_button_count(
373 struct libinput_event_pointer *event)
375 return event->seat_button_count;
378 LIBINPUT_EXPORT enum libinput_pointer_axis
379 libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
384 LIBINPUT_EXPORT double
385 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
390 LIBINPUT_EXPORT uint32_t
391 libinput_event_touch_get_time(struct libinput_event_touch *event)
396 LIBINPUT_EXPORT int32_t
397 libinput_event_touch_get_slot(struct libinput_event_touch *event)
402 LIBINPUT_EXPORT int32_t
403 libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
405 return event->seat_slot;
408 LIBINPUT_EXPORT double
409 libinput_event_touch_get_x(struct libinput_event_touch *event)
411 struct evdev_device *device =
412 (struct evdev_device *) event->base.device;
414 return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
417 LIBINPUT_EXPORT double
418 libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
421 struct evdev_device *device =
422 (struct evdev_device *) event->base.device;
424 return evdev_device_transform_x(device, event->x, width);
427 LIBINPUT_EXPORT double
428 libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
431 struct evdev_device *device =
432 (struct evdev_device *) event->base.device;
434 return evdev_device_transform_y(device, event->y, height);
437 LIBINPUT_EXPORT double
438 libinput_event_touch_get_y(struct libinput_event_touch *event)
440 struct evdev_device *device =
441 (struct evdev_device *) event->base.device;
443 return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
446 struct libinput_source *
447 libinput_add_fd(struct libinput *libinput,
449 libinput_source_dispatch_t dispatch,
452 struct libinput_source *source;
453 struct epoll_event ep;
455 source = malloc(sizeof *source);
459 source->dispatch = dispatch;
460 source->user_data = user_data;
463 memset(&ep, 0, sizeof ep);
465 ep.data.ptr = source;
467 if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
477 libinput_remove_source(struct libinput *libinput,
478 struct libinput_source *source)
480 epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL);
482 list_insert(&libinput->source_destroy_list, &source->link);
486 libinput_init(struct libinput *libinput,
487 const struct libinput_interface *interface,
488 const struct libinput_interface_backend *interface_backend,
491 libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
492 if (libinput->epoll_fd < 0)
495 libinput->events_len = 4;
496 libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
497 if (!libinput->events) {
498 close(libinput->epoll_fd);
502 libinput->interface = interface;
503 libinput->interface_backend = interface_backend;
504 libinput->user_data = user_data;
505 libinput->refcount = 1;
506 list_init(&libinput->source_destroy_list);
507 list_init(&libinput->seat_list);
509 if (libinput_timer_subsys_init(libinput) != 0) {
510 free(libinput->events);
511 close(libinput->epoll_fd);
519 libinput_device_destroy(struct libinput_device *device);
522 libinput_seat_destroy(struct libinput_seat *seat);
525 libinput_drop_destroyed_sources(struct libinput *libinput)
527 struct libinput_source *source, *next;
529 list_for_each_safe(source, next, &libinput->source_destroy_list, link)
531 list_init(&libinput->source_destroy_list);
534 LIBINPUT_EXPORT struct libinput *
535 libinput_ref(struct libinput *libinput)
537 libinput->refcount++;
541 LIBINPUT_EXPORT struct libinput *
542 libinput_unref(struct libinput *libinput)
544 struct libinput_event *event;
545 struct libinput_device *device, *next_device;
546 struct libinput_seat *seat, *next_seat;
548 if (libinput == NULL)
551 assert(libinput->refcount > 0);
552 libinput->refcount--;
553 if (libinput->refcount > 0)
556 libinput_suspend(libinput);
558 libinput->interface_backend->destroy(libinput);
560 while ((event = libinput_get_event(libinput)))
561 libinput_event_destroy(event);
563 free(libinput->events);
565 list_for_each_safe(seat, next_seat, &libinput->seat_list, link) {
566 list_for_each_safe(device, next_device,
569 libinput_device_destroy(device);
571 libinput_seat_destroy(seat);
574 libinput_timer_subsys_destroy(libinput);
575 libinput_drop_destroyed_sources(libinput);
576 close(libinput->epoll_fd);
583 libinput_event_destroy(struct libinput_event *event)
589 libinput_device_unref(event->device);
595 open_restricted(struct libinput *libinput,
596 const char *path, int flags)
598 return libinput->interface->open_restricted(path,
600 libinput->user_data);
604 close_restricted(struct libinput *libinput, int fd)
606 return libinput->interface->close_restricted(fd, libinput->user_data);
610 libinput_seat_init(struct libinput_seat *seat,
611 struct libinput *libinput,
612 const char *physical_name,
613 const char *logical_name,
614 libinput_seat_destroy_func destroy)
617 seat->libinput = libinput;
618 seat->physical_name = strdup(physical_name);
619 seat->logical_name = strdup(logical_name);
620 seat->destroy = destroy;
621 list_init(&seat->devices_list);
622 list_insert(&libinput->seat_list, &seat->link);
625 LIBINPUT_EXPORT struct libinput_seat *
626 libinput_seat_ref(struct libinput_seat *seat)
633 libinput_seat_destroy(struct libinput_seat *seat)
635 list_remove(&seat->link);
636 free(seat->logical_name);
637 free(seat->physical_name);
641 LIBINPUT_EXPORT struct libinput_seat *
642 libinput_seat_unref(struct libinput_seat *seat)
644 assert(seat->refcount > 0);
646 if (seat->refcount == 0) {
647 libinput_seat_destroy(seat);
655 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
657 seat->user_data = user_data;
660 LIBINPUT_EXPORT void *
661 libinput_seat_get_user_data(struct libinput_seat *seat)
663 return seat->user_data;
666 LIBINPUT_EXPORT const char *
667 libinput_seat_get_physical_name(struct libinput_seat *seat)
669 return seat->physical_name;
672 LIBINPUT_EXPORT const char *
673 libinput_seat_get_logical_name(struct libinput_seat *seat)
675 return seat->logical_name;
679 libinput_device_init(struct libinput_device *device,
680 struct libinput_seat *seat)
683 device->refcount = 1;
686 LIBINPUT_EXPORT struct libinput_device *
687 libinput_device_ref(struct libinput_device *device)
694 libinput_device_destroy(struct libinput_device *device)
696 evdev_device_destroy((struct evdev_device *) device);
699 LIBINPUT_EXPORT struct libinput_device *
700 libinput_device_unref(struct libinput_device *device)
702 assert(device->refcount > 0);
704 if (device->refcount == 0) {
705 libinput_device_destroy(device);
713 libinput_get_fd(struct libinput *libinput)
715 return libinput->epoll_fd;
719 libinput_dispatch(struct libinput *libinput)
721 struct libinput_source *source;
722 struct epoll_event ep[32];
725 count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0);
729 for (i = 0; i < count; ++i) {
730 source = ep[i].data.ptr;
731 if (source->fd == -1)
734 source->dispatch(source->user_data);
737 libinput_drop_destroyed_sources(libinput);
743 update_seat_key_count(struct libinput_seat *seat,
745 enum libinput_keyboard_key_state state)
747 assert(key >= 0 && key <= KEY_MAX);
750 case LIBINPUT_KEYBOARD_KEY_STATE_PRESSED:
751 return ++seat->button_count[key];
752 case LIBINPUT_KEYBOARD_KEY_STATE_RELEASED:
753 /* We might not have received the first PRESSED event. */
754 if (seat->button_count[key] == 0)
757 return --seat->button_count[key];
764 update_seat_button_count(struct libinput_seat *seat,
766 enum libinput_button_state state)
768 assert(button >= 0 && button <= KEY_MAX);
771 case LIBINPUT_BUTTON_STATE_PRESSED:
772 return ++seat->button_count[button];
773 case LIBINPUT_BUTTON_STATE_RELEASED:
774 /* We might not have received the first PRESSED event. */
775 if (seat->button_count[button] == 0)
778 return --seat->button_count[button];
785 init_event_base(struct libinput_event *event,
786 struct libinput_device *device,
787 enum libinput_event_type type)
790 event->device = device;
794 post_base_event(struct libinput_device *device,
795 enum libinput_event_type type,
796 struct libinput_event *event)
798 struct libinput *libinput = device->seat->libinput;
799 init_event_base(event, device, type);
800 libinput_post_event(libinput, event);
804 post_device_event(struct libinput_device *device,
805 enum libinput_event_type type,
806 struct libinput_event *event)
808 init_event_base(event, device, type);
809 libinput_post_event(device->seat->libinput, event);
813 notify_added_device(struct libinput_device *device)
815 struct libinput_event_device_notify *added_device_event;
817 added_device_event = zalloc(sizeof *added_device_event);
818 if (!added_device_event)
821 post_base_event(device,
822 LIBINPUT_EVENT_DEVICE_ADDED,
823 &added_device_event->base);
827 notify_removed_device(struct libinput_device *device)
829 struct libinput_event_device_notify *removed_device_event;
831 removed_device_event = zalloc(sizeof *removed_device_event);
832 if (!removed_device_event)
835 post_base_event(device,
836 LIBINPUT_EVENT_DEVICE_REMOVED,
837 &removed_device_event->base);
841 keyboard_notify_key(struct libinput_device *device,
844 enum libinput_keyboard_key_state state)
846 struct libinput_event_keyboard *key_event;
847 uint32_t seat_key_count;
849 key_event = zalloc(sizeof *key_event);
853 seat_key_count = update_seat_key_count(device->seat, key, state);
855 *key_event = (struct libinput_event_keyboard) {
859 .seat_key_count = seat_key_count,
862 post_device_event(device,
863 LIBINPUT_EVENT_KEYBOARD_KEY,
868 pointer_notify_motion(struct libinput_device *device,
873 struct libinput_event_pointer *motion_event;
875 motion_event = zalloc(sizeof *motion_event);
879 *motion_event = (struct libinput_event_pointer) {
885 post_device_event(device,
886 LIBINPUT_EVENT_POINTER_MOTION,
887 &motion_event->base);
891 pointer_notify_motion_absolute(struct libinput_device *device,
896 struct libinput_event_pointer *motion_absolute_event;
898 motion_absolute_event = zalloc(sizeof *motion_absolute_event);
899 if (!motion_absolute_event)
902 *motion_absolute_event = (struct libinput_event_pointer) {
908 post_device_event(device,
909 LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
910 &motion_absolute_event->base);
914 pointer_notify_button(struct libinput_device *device,
917 enum libinput_button_state state)
919 struct libinput_event_pointer *button_event;
920 int32_t seat_button_count;
922 button_event = zalloc(sizeof *button_event);
926 seat_button_count = update_seat_button_count(device->seat,
930 *button_event = (struct libinput_event_pointer) {
934 .seat_button_count = seat_button_count,
937 post_device_event(device,
938 LIBINPUT_EVENT_POINTER_BUTTON,
939 &button_event->base);
943 pointer_notify_axis(struct libinput_device *device,
945 enum libinput_pointer_axis axis,
948 struct libinput_event_pointer *axis_event;
950 axis_event = zalloc(sizeof *axis_event);
954 *axis_event = (struct libinput_event_pointer) {
960 post_device_event(device,
961 LIBINPUT_EVENT_POINTER_AXIS,
966 touch_notify_touch_down(struct libinput_device *device,
973 struct libinput_event_touch *touch_event;
975 touch_event = zalloc(sizeof *touch_event);
979 *touch_event = (struct libinput_event_touch) {
982 .seat_slot = seat_slot,
987 post_device_event(device,
988 LIBINPUT_EVENT_TOUCH_DOWN,
993 touch_notify_touch_motion(struct libinput_device *device,
1000 struct libinput_event_touch *touch_event;
1002 touch_event = zalloc(sizeof *touch_event);
1006 *touch_event = (struct libinput_event_touch) {
1009 .seat_slot = seat_slot,
1014 post_device_event(device,
1015 LIBINPUT_EVENT_TOUCH_MOTION,
1016 &touch_event->base);
1020 touch_notify_touch_up(struct libinput_device *device,
1025 struct libinput_event_touch *touch_event;
1027 touch_event = zalloc(sizeof *touch_event);
1031 *touch_event = (struct libinput_event_touch) {
1034 .seat_slot = seat_slot,
1037 post_device_event(device,
1038 LIBINPUT_EVENT_TOUCH_UP,
1039 &touch_event->base);
1043 touch_notify_frame(struct libinput_device *device,
1046 struct libinput_event_touch *touch_event;
1048 touch_event = zalloc(sizeof *touch_event);
1052 *touch_event = (struct libinput_event_touch) {
1056 post_device_event(device,
1057 LIBINPUT_EVENT_TOUCH_FRAME,
1058 &touch_event->base);
1063 libinput_post_event(struct libinput *libinput,
1064 struct libinput_event *event)
1066 struct libinput_event **events = libinput->events;
1067 size_t events_len = libinput->events_len;
1068 size_t events_count = libinput->events_count;
1073 if (events_count > events_len) {
1075 events = realloc(events, events_len * sizeof *events);
1077 fprintf(stderr, "Failed to reallocate event ring "
1082 if (libinput->events_count > 0 && libinput->events_in == 0) {
1083 libinput->events_in = libinput->events_len;
1084 } else if (libinput->events_count > 0 &&
1085 libinput->events_out >= libinput->events_in) {
1086 move_len = libinput->events_len - libinput->events_out;
1087 new_out = events_len - move_len;
1088 memmove(events + new_out,
1089 events + libinput->events_out,
1090 move_len * sizeof *events);
1091 libinput->events_out = new_out;
1094 libinput->events = events;
1095 libinput->events_len = events_len;
1099 libinput_device_ref(event->device);
1101 libinput->events_count = events_count;
1102 events[libinput->events_in] = event;
1103 libinput->events_in = (libinput->events_in + 1) % libinput->events_len;
1106 LIBINPUT_EXPORT struct libinput_event *
1107 libinput_get_event(struct libinput *libinput)
1109 struct libinput_event *event;
1111 if (libinput->events_count == 0)
1114 event = libinput->events[libinput->events_out];
1115 libinput->events_out =
1116 (libinput->events_out + 1) % libinput->events_len;
1117 libinput->events_count--;
1122 LIBINPUT_EXPORT enum libinput_event_type
1123 libinput_next_event_type(struct libinput *libinput)
1125 struct libinput_event *event;
1127 if (libinput->events_count == 0)
1128 return LIBINPUT_EVENT_NONE;
1130 event = libinput->events[libinput->events_out];
1134 LIBINPUT_EXPORT void *
1135 libinput_get_user_data(struct libinput *libinput)
1137 return libinput->user_data;
1141 libinput_resume(struct libinput *libinput)
1143 return libinput->interface_backend->resume(libinput);
1146 LIBINPUT_EXPORT void
1147 libinput_suspend(struct libinput *libinput)
1149 libinput->interface_backend->suspend(libinput);
1152 LIBINPUT_EXPORT void
1153 libinput_device_set_user_data(struct libinput_device *device, void *user_data)
1155 device->user_data = user_data;
1158 LIBINPUT_EXPORT void *
1159 libinput_device_get_user_data(struct libinput_device *device)
1161 return device->user_data;
1164 LIBINPUT_EXPORT const char *
1165 libinput_device_get_sysname(struct libinput_device *device)
1167 return evdev_device_get_sysname((struct evdev_device *) device);
1170 LIBINPUT_EXPORT const char *
1171 libinput_device_get_output_name(struct libinput_device *device)
1173 return evdev_device_get_output((struct evdev_device *) device);
1176 LIBINPUT_EXPORT struct libinput_seat *
1177 libinput_device_get_seat(struct libinput_device *device)
1179 return device->seat;
1182 LIBINPUT_EXPORT void
1183 libinput_device_led_update(struct libinput_device *device,
1184 enum libinput_led leds)
1186 evdev_device_led_update((struct evdev_device *) device, leds);
1190 libinput_device_get_keys(struct libinput_device *device,
1191 char *keys, size_t size)
1193 return evdev_device_get_keys((struct evdev_device *) device,
1198 LIBINPUT_EXPORT void
1199 libinput_device_calibrate(struct libinput_device *device,
1200 float calibration[6])
1202 evdev_device_calibrate((struct evdev_device *) device, calibration);
1206 libinput_device_has_capability(struct libinput_device *device,
1207 enum libinput_device_capability capability)
1209 return evdev_device_has_capability((struct evdev_device *) device,
1214 libinput_device_get_size(struct libinput_device *device,
1218 return evdev_device_get_size((struct evdev_device *)device,
1223 LIBINPUT_EXPORT struct libinput_event *
1224 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
1226 return &event->base;
1229 LIBINPUT_EXPORT struct libinput_event *
1230 libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
1232 return &event->base;
1235 LIBINPUT_EXPORT struct libinput_event *
1236 libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
1238 return &event->base;
1241 LIBINPUT_EXPORT struct libinput_event *
1242 libinput_event_touch_get_base_event(struct libinput_event_touch *event)
1244 return &event->base;