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_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(struct libinput *libinput,
85 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 log_msg_va(struct libinput *libinput,
103 enum libinput_log_priority priority,
107 if (libinput->log_handler &&
108 libinput->log_priority <= priority)
109 libinput->log_handler(libinput, priority, format, args);
113 log_msg(struct libinput *libinput,
114 enum libinput_log_priority priority,
115 const char *format, ...)
119 va_start(args, format);
120 log_msg_va(libinput, priority, format, args);
125 libinput_log_set_priority(struct libinput *libinput,
126 enum libinput_log_priority priority)
128 libinput->log_priority = priority;
131 LIBINPUT_EXPORT enum libinput_log_priority
132 libinput_log_get_priority(const struct libinput *libinput)
134 return libinput->log_priority;
138 libinput_log_set_handler(struct libinput *libinput,
139 libinput_log_handler log_handler)
141 libinput->log_handler = log_handler;
145 libinput_post_event(struct libinput *libinput,
146 struct libinput_event *event);
148 LIBINPUT_EXPORT enum libinput_event_type
149 libinput_event_get_type(struct libinput_event *event)
154 LIBINPUT_EXPORT struct libinput *
155 libinput_event_get_context(struct libinput_event *event)
157 return event->device->seat->libinput;
160 LIBINPUT_EXPORT struct libinput_device *
161 libinput_event_get_device(struct libinput_event *event)
163 return event->device;
166 LIBINPUT_EXPORT struct libinput_event_pointer *
167 libinput_event_get_pointer_event(struct libinput_event *event)
169 switch (event->type) {
170 case LIBINPUT_EVENT_NONE:
171 abort(); /* not used as actual event type */
172 case LIBINPUT_EVENT_DEVICE_ADDED:
173 case LIBINPUT_EVENT_DEVICE_REMOVED:
174 case LIBINPUT_EVENT_KEYBOARD_KEY:
176 case LIBINPUT_EVENT_POINTER_MOTION:
177 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
178 case LIBINPUT_EVENT_POINTER_BUTTON:
179 case LIBINPUT_EVENT_POINTER_AXIS:
180 return (struct libinput_event_pointer *) event;
181 case LIBINPUT_EVENT_TOUCH_DOWN:
182 case LIBINPUT_EVENT_TOUCH_UP:
183 case LIBINPUT_EVENT_TOUCH_MOTION:
184 case LIBINPUT_EVENT_TOUCH_CANCEL:
185 case LIBINPUT_EVENT_TOUCH_FRAME:
192 LIBINPUT_EXPORT struct libinput_event_keyboard *
193 libinput_event_get_keyboard_event(struct libinput_event *event)
195 switch (event->type) {
196 case LIBINPUT_EVENT_NONE:
197 abort(); /* not used as actual event type */
198 case LIBINPUT_EVENT_DEVICE_ADDED:
199 case LIBINPUT_EVENT_DEVICE_REMOVED:
201 case LIBINPUT_EVENT_KEYBOARD_KEY:
202 return (struct libinput_event_keyboard *) event;
203 case LIBINPUT_EVENT_POINTER_MOTION:
204 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
205 case LIBINPUT_EVENT_POINTER_BUTTON:
206 case LIBINPUT_EVENT_POINTER_AXIS:
207 case LIBINPUT_EVENT_TOUCH_DOWN:
208 case LIBINPUT_EVENT_TOUCH_UP:
209 case LIBINPUT_EVENT_TOUCH_MOTION:
210 case LIBINPUT_EVENT_TOUCH_CANCEL:
211 case LIBINPUT_EVENT_TOUCH_FRAME:
218 LIBINPUT_EXPORT struct libinput_event_touch *
219 libinput_event_get_touch_event(struct libinput_event *event)
221 switch (event->type) {
222 case LIBINPUT_EVENT_NONE:
223 abort(); /* not used as actual event type */
224 case LIBINPUT_EVENT_DEVICE_ADDED:
225 case LIBINPUT_EVENT_DEVICE_REMOVED:
226 case LIBINPUT_EVENT_KEYBOARD_KEY:
227 case LIBINPUT_EVENT_POINTER_MOTION:
228 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
229 case LIBINPUT_EVENT_POINTER_BUTTON:
230 case LIBINPUT_EVENT_POINTER_AXIS:
232 case LIBINPUT_EVENT_TOUCH_DOWN:
233 case LIBINPUT_EVENT_TOUCH_UP:
234 case LIBINPUT_EVENT_TOUCH_MOTION:
235 case LIBINPUT_EVENT_TOUCH_CANCEL:
236 case LIBINPUT_EVENT_TOUCH_FRAME:
237 return (struct libinput_event_touch *) event;
243 LIBINPUT_EXPORT struct libinput_event_device_notify *
244 libinput_event_get_device_notify_event(struct libinput_event *event)
246 switch (event->type) {
247 case LIBINPUT_EVENT_NONE:
248 abort(); /* not used as actual event type */
249 case LIBINPUT_EVENT_DEVICE_ADDED:
250 case LIBINPUT_EVENT_DEVICE_REMOVED:
251 return (struct libinput_event_device_notify *) event;
252 case LIBINPUT_EVENT_KEYBOARD_KEY:
253 case LIBINPUT_EVENT_POINTER_MOTION:
254 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
255 case LIBINPUT_EVENT_POINTER_BUTTON:
256 case LIBINPUT_EVENT_POINTER_AXIS:
257 case LIBINPUT_EVENT_TOUCH_DOWN:
258 case LIBINPUT_EVENT_TOUCH_UP:
259 case LIBINPUT_EVENT_TOUCH_MOTION:
260 case LIBINPUT_EVENT_TOUCH_CANCEL:
261 case LIBINPUT_EVENT_TOUCH_FRAME:
268 LIBINPUT_EXPORT uint32_t
269 libinput_event_keyboard_get_time(struct libinput_event_keyboard *event)
274 LIBINPUT_EXPORT uint32_t
275 libinput_event_keyboard_get_key(struct libinput_event_keyboard *event)
280 LIBINPUT_EXPORT enum libinput_key_state
281 libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event)
286 LIBINPUT_EXPORT uint32_t
287 libinput_event_keyboard_get_seat_key_count(
288 struct libinput_event_keyboard *event)
290 return event->seat_key_count;
293 LIBINPUT_EXPORT uint32_t
294 libinput_event_pointer_get_time(struct libinput_event_pointer *event)
299 LIBINPUT_EXPORT double
300 libinput_event_pointer_get_dx(struct libinput_event_pointer *event)
305 LIBINPUT_EXPORT double
306 libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
311 LIBINPUT_EXPORT double
312 libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
314 struct evdev_device *device =
315 (struct evdev_device *) event->base.device;
317 return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
320 LIBINPUT_EXPORT double
321 libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
323 struct evdev_device *device =
324 (struct evdev_device *) event->base.device;
326 return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
329 LIBINPUT_EXPORT double
330 libinput_event_pointer_get_absolute_x_transformed(
331 struct libinput_event_pointer *event,
334 struct evdev_device *device =
335 (struct evdev_device *) event->base.device;
337 return evdev_device_transform_x(device, event->x, width);
340 LIBINPUT_EXPORT double
341 libinput_event_pointer_get_absolute_y_transformed(
342 struct libinput_event_pointer *event,
345 struct evdev_device *device =
346 (struct evdev_device *) event->base.device;
348 return evdev_device_transform_y(device, event->y, height);
351 LIBINPUT_EXPORT uint32_t
352 libinput_event_pointer_get_button(struct libinput_event_pointer *event)
354 return event->button;
357 LIBINPUT_EXPORT enum libinput_button_state
358 libinput_event_pointer_get_button_state(struct libinput_event_pointer *event)
363 LIBINPUT_EXPORT uint32_t
364 libinput_event_pointer_get_seat_button_count(
365 struct libinput_event_pointer *event)
367 return event->seat_button_count;
370 LIBINPUT_EXPORT enum libinput_pointer_axis
371 libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
376 LIBINPUT_EXPORT double
377 libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
382 LIBINPUT_EXPORT uint32_t
383 libinput_event_touch_get_time(struct libinput_event_touch *event)
388 LIBINPUT_EXPORT int32_t
389 libinput_event_touch_get_slot(struct libinput_event_touch *event)
394 LIBINPUT_EXPORT int32_t
395 libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
397 return event->seat_slot;
400 LIBINPUT_EXPORT double
401 libinput_event_touch_get_x(struct libinput_event_touch *event)
403 struct evdev_device *device =
404 (struct evdev_device *) event->base.device;
406 return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
409 LIBINPUT_EXPORT double
410 libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
413 struct evdev_device *device =
414 (struct evdev_device *) event->base.device;
416 return evdev_device_transform_x(device, event->x, width);
419 LIBINPUT_EXPORT double
420 libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
423 struct evdev_device *device =
424 (struct evdev_device *) event->base.device;
426 return evdev_device_transform_y(device, event->y, height);
429 LIBINPUT_EXPORT double
430 libinput_event_touch_get_y(struct libinput_event_touch *event)
432 struct evdev_device *device =
433 (struct evdev_device *) event->base.device;
435 return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
438 struct libinput_source *
439 libinput_add_fd(struct libinput *libinput,
441 libinput_source_dispatch_t dispatch,
444 struct libinput_source *source;
445 struct epoll_event ep;
447 source = malloc(sizeof *source);
451 source->dispatch = dispatch;
452 source->user_data = user_data;
455 memset(&ep, 0, sizeof ep);
457 ep.data.ptr = source;
459 if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
469 libinput_remove_source(struct libinput *libinput,
470 struct libinput_source *source)
472 epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL);
474 list_insert(&libinput->source_destroy_list, &source->link);
478 libinput_init(struct libinput *libinput,
479 const struct libinput_interface *interface,
480 const struct libinput_interface_backend *interface_backend,
483 libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
484 if (libinput->epoll_fd < 0)
487 libinput->events_len = 4;
488 libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
489 if (!libinput->events) {
490 close(libinput->epoll_fd);
494 libinput->log_handler = libinput_default_log_func;
495 libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR;
496 libinput->interface = interface;
497 libinput->interface_backend = interface_backend;
498 libinput->user_data = user_data;
499 libinput->refcount = 1;
500 list_init(&libinput->source_destroy_list);
501 list_init(&libinput->seat_list);
503 if (libinput_timer_subsys_init(libinput) != 0) {
504 free(libinput->events);
505 close(libinput->epoll_fd);
513 libinput_device_destroy(struct libinput_device *device);
516 libinput_seat_destroy(struct libinput_seat *seat);
519 libinput_drop_destroyed_sources(struct libinput *libinput)
521 struct libinput_source *source, *next;
523 list_for_each_safe(source, next, &libinput->source_destroy_list, link)
525 list_init(&libinput->source_destroy_list);
528 LIBINPUT_EXPORT struct libinput *
529 libinput_ref(struct libinput *libinput)
531 libinput->refcount++;
535 LIBINPUT_EXPORT struct libinput *
536 libinput_unref(struct libinput *libinput)
538 struct libinput_event *event;
539 struct libinput_device *device, *next_device;
540 struct libinput_seat *seat, *next_seat;
542 if (libinput == NULL)
545 assert(libinput->refcount > 0);
546 libinput->refcount--;
547 if (libinput->refcount > 0)
550 libinput_suspend(libinput);
552 libinput->interface_backend->destroy(libinput);
554 while ((event = libinput_get_event(libinput)))
555 libinput_event_destroy(event);
557 free(libinput->events);
559 list_for_each_safe(seat, next_seat, &libinput->seat_list, link) {
560 list_for_each_safe(device, next_device,
563 libinput_device_destroy(device);
565 libinput_seat_destroy(seat);
568 libinput_timer_subsys_destroy(libinput);
569 libinput_drop_destroyed_sources(libinput);
570 close(libinput->epoll_fd);
577 libinput_event_destroy(struct libinput_event *event)
583 libinput_device_unref(event->device);
589 open_restricted(struct libinput *libinput,
590 const char *path, int flags)
592 return libinput->interface->open_restricted(path,
594 libinput->user_data);
598 close_restricted(struct libinput *libinput, int fd)
600 return libinput->interface->close_restricted(fd, libinput->user_data);
604 libinput_seat_init(struct libinput_seat *seat,
605 struct libinput *libinput,
606 const char *physical_name,
607 const char *logical_name,
608 libinput_seat_destroy_func destroy)
611 seat->libinput = libinput;
612 seat->physical_name = strdup(physical_name);
613 seat->logical_name = strdup(logical_name);
614 seat->destroy = destroy;
615 list_init(&seat->devices_list);
616 list_insert(&libinput->seat_list, &seat->link);
619 LIBINPUT_EXPORT struct libinput_seat *
620 libinput_seat_ref(struct libinput_seat *seat)
627 libinput_seat_destroy(struct libinput_seat *seat)
629 list_remove(&seat->link);
630 free(seat->logical_name);
631 free(seat->physical_name);
635 LIBINPUT_EXPORT struct libinput_seat *
636 libinput_seat_unref(struct libinput_seat *seat)
638 assert(seat->refcount > 0);
640 if (seat->refcount == 0) {
641 libinput_seat_destroy(seat);
649 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
651 seat->user_data = user_data;
654 LIBINPUT_EXPORT void *
655 libinput_seat_get_user_data(struct libinput_seat *seat)
657 return seat->user_data;
660 LIBINPUT_EXPORT const char *
661 libinput_seat_get_physical_name(struct libinput_seat *seat)
663 return seat->physical_name;
666 LIBINPUT_EXPORT const char *
667 libinput_seat_get_logical_name(struct libinput_seat *seat)
669 return seat->logical_name;
673 libinput_device_init(struct libinput_device *device,
674 struct libinput_seat *seat)
677 device->refcount = 1;
680 LIBINPUT_EXPORT struct libinput_device *
681 libinput_device_ref(struct libinput_device *device)
688 libinput_device_destroy(struct libinput_device *device)
690 evdev_device_destroy((struct evdev_device *) device);
693 LIBINPUT_EXPORT struct libinput_device *
694 libinput_device_unref(struct libinput_device *device)
696 assert(device->refcount > 0);
698 if (device->refcount == 0) {
699 libinput_device_destroy(device);
707 libinput_get_fd(struct libinput *libinput)
709 return libinput->epoll_fd;
713 libinput_dispatch(struct libinput *libinput)
715 struct libinput_source *source;
716 struct epoll_event ep[32];
719 count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0);
723 for (i = 0; i < count; ++i) {
724 source = ep[i].data.ptr;
725 if (source->fd == -1)
728 source->dispatch(source->user_data);
731 libinput_drop_destroyed_sources(libinput);
737 update_seat_key_count(struct libinput_seat *seat,
739 enum libinput_key_state state)
741 assert(key >= 0 && key <= KEY_MAX);
744 case LIBINPUT_KEY_STATE_PRESSED:
745 return ++seat->button_count[key];
746 case LIBINPUT_KEY_STATE_RELEASED:
747 /* We might not have received the first PRESSED event. */
748 if (seat->button_count[key] == 0)
751 return --seat->button_count[key];
758 update_seat_button_count(struct libinput_seat *seat,
760 enum libinput_button_state state)
762 assert(button >= 0 && button <= KEY_MAX);
765 case LIBINPUT_BUTTON_STATE_PRESSED:
766 return ++seat->button_count[button];
767 case LIBINPUT_BUTTON_STATE_RELEASED:
768 /* We might not have received the first PRESSED event. */
769 if (seat->button_count[button] == 0)
772 return --seat->button_count[button];
779 init_event_base(struct libinput_event *event,
780 struct libinput_device *device,
781 enum libinput_event_type type)
784 event->device = device;
788 post_base_event(struct libinput_device *device,
789 enum libinput_event_type type,
790 struct libinput_event *event)
792 struct libinput *libinput = device->seat->libinput;
793 init_event_base(event, device, type);
794 libinput_post_event(libinput, event);
798 post_device_event(struct libinput_device *device,
799 enum libinput_event_type type,
800 struct libinput_event *event)
802 init_event_base(event, device, type);
803 libinput_post_event(device->seat->libinput, event);
807 notify_added_device(struct libinput_device *device)
809 struct libinput_event_device_notify *added_device_event;
811 added_device_event = zalloc(sizeof *added_device_event);
812 if (!added_device_event)
815 post_base_event(device,
816 LIBINPUT_EVENT_DEVICE_ADDED,
817 &added_device_event->base);
821 notify_removed_device(struct libinput_device *device)
823 struct libinput_event_device_notify *removed_device_event;
825 removed_device_event = zalloc(sizeof *removed_device_event);
826 if (!removed_device_event)
829 post_base_event(device,
830 LIBINPUT_EVENT_DEVICE_REMOVED,
831 &removed_device_event->base);
835 keyboard_notify_key(struct libinput_device *device,
838 enum libinput_key_state state)
840 struct libinput_event_keyboard *key_event;
841 uint32_t seat_key_count;
843 key_event = zalloc(sizeof *key_event);
847 seat_key_count = update_seat_key_count(device->seat, key, state);
849 *key_event = (struct libinput_event_keyboard) {
853 .seat_key_count = seat_key_count,
856 post_device_event(device,
857 LIBINPUT_EVENT_KEYBOARD_KEY,
862 pointer_notify_motion(struct libinput_device *device,
867 struct libinput_event_pointer *motion_event;
869 motion_event = zalloc(sizeof *motion_event);
873 *motion_event = (struct libinput_event_pointer) {
879 post_device_event(device,
880 LIBINPUT_EVENT_POINTER_MOTION,
881 &motion_event->base);
885 pointer_notify_motion_absolute(struct libinput_device *device,
890 struct libinput_event_pointer *motion_absolute_event;
892 motion_absolute_event = zalloc(sizeof *motion_absolute_event);
893 if (!motion_absolute_event)
896 *motion_absolute_event = (struct libinput_event_pointer) {
902 post_device_event(device,
903 LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
904 &motion_absolute_event->base);
908 pointer_notify_button(struct libinput_device *device,
911 enum libinput_button_state state)
913 struct libinput_event_pointer *button_event;
914 int32_t seat_button_count;
916 button_event = zalloc(sizeof *button_event);
920 seat_button_count = update_seat_button_count(device->seat,
924 *button_event = (struct libinput_event_pointer) {
928 .seat_button_count = seat_button_count,
931 post_device_event(device,
932 LIBINPUT_EVENT_POINTER_BUTTON,
933 &button_event->base);
937 pointer_notify_axis(struct libinput_device *device,
939 enum libinput_pointer_axis axis,
942 struct libinput_event_pointer *axis_event;
944 axis_event = zalloc(sizeof *axis_event);
948 *axis_event = (struct libinput_event_pointer) {
954 post_device_event(device,
955 LIBINPUT_EVENT_POINTER_AXIS,
960 touch_notify_touch_down(struct libinput_device *device,
967 struct libinput_event_touch *touch_event;
969 touch_event = zalloc(sizeof *touch_event);
973 *touch_event = (struct libinput_event_touch) {
976 .seat_slot = seat_slot,
981 post_device_event(device,
982 LIBINPUT_EVENT_TOUCH_DOWN,
987 touch_notify_touch_motion(struct libinput_device *device,
994 struct libinput_event_touch *touch_event;
996 touch_event = zalloc(sizeof *touch_event);
1000 *touch_event = (struct libinput_event_touch) {
1003 .seat_slot = seat_slot,
1008 post_device_event(device,
1009 LIBINPUT_EVENT_TOUCH_MOTION,
1010 &touch_event->base);
1014 touch_notify_touch_up(struct libinput_device *device,
1019 struct libinput_event_touch *touch_event;
1021 touch_event = zalloc(sizeof *touch_event);
1025 *touch_event = (struct libinput_event_touch) {
1028 .seat_slot = seat_slot,
1031 post_device_event(device,
1032 LIBINPUT_EVENT_TOUCH_UP,
1033 &touch_event->base);
1037 touch_notify_frame(struct libinput_device *device,
1040 struct libinput_event_touch *touch_event;
1042 touch_event = zalloc(sizeof *touch_event);
1046 *touch_event = (struct libinput_event_touch) {
1050 post_device_event(device,
1051 LIBINPUT_EVENT_TOUCH_FRAME,
1052 &touch_event->base);
1057 libinput_post_event(struct libinput *libinput,
1058 struct libinput_event *event)
1060 struct libinput_event **events = libinput->events;
1061 size_t events_len = libinput->events_len;
1062 size_t events_count = libinput->events_count;
1067 if (events_count > events_len) {
1069 events = realloc(events, events_len * sizeof *events);
1071 fprintf(stderr, "Failed to reallocate event ring "
1076 if (libinput->events_count > 0 && libinput->events_in == 0) {
1077 libinput->events_in = libinput->events_len;
1078 } else if (libinput->events_count > 0 &&
1079 libinput->events_out >= libinput->events_in) {
1080 move_len = libinput->events_len - libinput->events_out;
1081 new_out = events_len - move_len;
1082 memmove(events + new_out,
1083 events + libinput->events_out,
1084 move_len * sizeof *events);
1085 libinput->events_out = new_out;
1088 libinput->events = events;
1089 libinput->events_len = events_len;
1093 libinput_device_ref(event->device);
1095 libinput->events_count = events_count;
1096 events[libinput->events_in] = event;
1097 libinput->events_in = (libinput->events_in + 1) % libinput->events_len;
1100 LIBINPUT_EXPORT struct libinput_event *
1101 libinput_get_event(struct libinput *libinput)
1103 struct libinput_event *event;
1105 if (libinput->events_count == 0)
1108 event = libinput->events[libinput->events_out];
1109 libinput->events_out =
1110 (libinput->events_out + 1) % libinput->events_len;
1111 libinput->events_count--;
1116 LIBINPUT_EXPORT enum libinput_event_type
1117 libinput_next_event_type(struct libinput *libinput)
1119 struct libinput_event *event;
1121 if (libinput->events_count == 0)
1122 return LIBINPUT_EVENT_NONE;
1124 event = libinput->events[libinput->events_out];
1128 LIBINPUT_EXPORT void *
1129 libinput_get_user_data(struct libinput *libinput)
1131 return libinput->user_data;
1135 libinput_resume(struct libinput *libinput)
1137 return libinput->interface_backend->resume(libinput);
1140 LIBINPUT_EXPORT void
1141 libinput_suspend(struct libinput *libinput)
1143 libinput->interface_backend->suspend(libinput);
1146 LIBINPUT_EXPORT void
1147 libinput_device_set_user_data(struct libinput_device *device, void *user_data)
1149 device->user_data = user_data;
1152 LIBINPUT_EXPORT void *
1153 libinput_device_get_user_data(struct libinput_device *device)
1155 return device->user_data;
1158 LIBINPUT_EXPORT const char *
1159 libinput_device_get_sysname(struct libinput_device *device)
1161 return evdev_device_get_sysname((struct evdev_device *) device);
1164 LIBINPUT_EXPORT const char *
1165 libinput_device_get_name(struct libinput_device *device)
1167 return evdev_device_get_name((struct evdev_device *) device);
1170 LIBINPUT_EXPORT unsigned int
1171 libinput_device_get_id_product(struct libinput_device *device)
1173 return evdev_device_get_id_product((struct evdev_device *) device);
1176 LIBINPUT_EXPORT unsigned int
1177 libinput_device_get_id_vendor(struct libinput_device *device)
1179 return evdev_device_get_id_vendor((struct evdev_device *) device);
1182 LIBINPUT_EXPORT const char *
1183 libinput_device_get_output_name(struct libinput_device *device)
1185 return evdev_device_get_output((struct evdev_device *) device);
1188 LIBINPUT_EXPORT struct libinput_seat *
1189 libinput_device_get_seat(struct libinput_device *device)
1191 return device->seat;
1194 LIBINPUT_EXPORT void
1195 libinput_device_led_update(struct libinput_device *device,
1196 enum libinput_led leds)
1198 evdev_device_led_update((struct evdev_device *) device, leds);
1202 libinput_device_get_keys(struct libinput_device *device,
1203 char *keys, size_t size)
1205 return evdev_device_get_keys((struct evdev_device *) device,
1210 LIBINPUT_EXPORT void
1211 libinput_device_calibrate(struct libinput_device *device,
1212 float calibration[6])
1214 evdev_device_calibrate((struct evdev_device *) device, calibration);
1218 libinput_device_has_capability(struct libinput_device *device,
1219 enum libinput_device_capability capability)
1221 return evdev_device_has_capability((struct evdev_device *) device,
1226 libinput_device_get_size(struct libinput_device *device,
1230 return evdev_device_get_size((struct evdev_device *)device,
1235 LIBINPUT_EXPORT struct libinput_event *
1236 libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
1238 return &event->base;
1241 LIBINPUT_EXPORT struct libinput_event *
1242 libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
1244 return &event->base;
1247 LIBINPUT_EXPORT struct libinput_event *
1248 libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
1250 return &event->base;
1253 LIBINPUT_EXPORT struct libinput_event *
1254 libinput_event_touch_get_base_event(struct libinput_event_touch *event)
1256 return &event->base;