zalloc all events to make sure we have defined defaults
[platform/upstream/libinput.git] / src / libinput.c
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 #include "config.h"
24
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/epoll.h>
30 #include <unistd.h>
31 #include <assert.h>
32
33 #include "libinput.h"
34 #include "libinput-private.h"
35 #include "evdev.h"
36
37 enum libinput_event_class {
38         LIBINPUT_EVENT_CLASS_NONE,
39         LIBINPUT_EVENT_CLASS_BASE,
40         LIBINPUT_EVENT_CLASS_SEAT,
41         LIBINPUT_EVENT_CLASS_DEVICE,
42 };
43
44 struct libinput_source {
45         libinput_source_dispatch_t dispatch;
46         void *user_data;
47         int fd;
48         struct list link;
49 };
50
51 struct libinput_event {
52         enum libinput_event_type type;
53         struct libinput_device *device;
54 };
55
56 struct libinput_event_device_notify {
57         struct libinput_event base;
58         struct libinput_device *device;
59 };
60
61 struct libinput_event_keyboard {
62         struct libinput_event base;
63         uint32_t time;
64         uint32_t key;
65         enum libinput_keyboard_key_state state;
66 };
67
68 struct libinput_event_pointer {
69         struct libinput_event base;
70         uint32_t time;
71         li_fixed_t x;
72         li_fixed_t y;
73         uint32_t button;
74         enum libinput_pointer_button_state state;
75         enum libinput_pointer_axis axis;
76         li_fixed_t value;
77 };
78
79 struct libinput_event_touch {
80         struct libinput_event base;
81         uint32_t time;
82         uint32_t slot;
83         li_fixed_t x;
84         li_fixed_t y;
85         enum libinput_touch_type touch_type;
86 };
87
88 static void
89 libinput_post_event(struct libinput *libinput,
90                     struct libinput_event *event);
91
92 LIBINPUT_EXPORT enum libinput_event_type
93 libinput_event_get_type(struct libinput_event *event)
94 {
95         return event->type;
96 }
97
98 LIBINPUT_EXPORT struct libinput*
99 libinput_event_get_context(struct libinput_event *event)
100 {
101         return event->device->seat->libinput;
102 }
103
104 LIBINPUT_EXPORT struct libinput_device*
105 libinput_event_get_device(struct libinput_event *event)
106 {
107         return event->device;
108 }
109
110 LIBINPUT_EXPORT uint32_t
111 libinput_event_keyboard_get_time(
112         struct libinput_event_keyboard *event)
113 {
114         return event->time;
115 }
116
117 LIBINPUT_EXPORT uint32_t
118 libinput_event_keyboard_get_key(
119         struct libinput_event_keyboard *event)
120 {
121         return event->key;
122 }
123
124 LIBINPUT_EXPORT enum libinput_keyboard_key_state
125 libinput_event_keyboard_get_key_state(
126         struct libinput_event_keyboard *event)
127 {
128         return event->state;
129 }
130
131 LIBINPUT_EXPORT uint32_t
132 libinput_event_pointer_get_time(
133         struct libinput_event_pointer *event)
134 {
135         return event->time;
136 }
137
138 LIBINPUT_EXPORT li_fixed_t
139 libinput_event_pointer_get_dx(
140         struct libinput_event_pointer *event)
141 {
142         return event->x;
143 }
144
145 LIBINPUT_EXPORT li_fixed_t
146 libinput_event_pointer_get_dy(
147         struct libinput_event_pointer *event)
148 {
149         return event->y;
150 }
151
152 LIBINPUT_EXPORT li_fixed_t
153 libinput_event_pointer_get_absolute_x(
154         struct libinput_event_pointer *event)
155 {
156         return event->x;
157 }
158
159 LIBINPUT_EXPORT li_fixed_t
160 libinput_event_pointer_get_absolute_y(
161         struct libinput_event_pointer *event)
162 {
163         return event->y;
164 }
165
166 LIBINPUT_EXPORT uint32_t
167 libinput_event_pointer_get_button(
168         struct libinput_event_pointer *event)
169 {
170         return event->button;
171 }
172
173 LIBINPUT_EXPORT enum libinput_pointer_button_state
174 libinput_event_pointer_get_button_state(
175         struct libinput_event_pointer *event)
176 {
177         return event->state;
178 }
179
180 LIBINPUT_EXPORT enum libinput_pointer_axis
181 libinput_event_pointer_get_axis(
182         struct libinput_event_pointer *event)
183 {
184         return event->axis;
185 }
186
187 LIBINPUT_EXPORT li_fixed_t
188 libinput_event_pointer_get_axis_value(
189         struct libinput_event_pointer *event)
190 {
191         return event->value;
192 }
193
194 LIBINPUT_EXPORT uint32_t
195 libinput_event_touch_get_time(
196         struct libinput_event_touch *event)
197 {
198         return event->time;
199 }
200
201 LIBINPUT_EXPORT uint32_t
202 libinput_event_touch_get_slot(
203         struct libinput_event_touch *event)
204 {
205         return event->slot;
206 }
207
208 LIBINPUT_EXPORT li_fixed_t
209 libinput_event_touch_get_x(
210         struct libinput_event_touch *event)
211 {
212         return event->x;
213 }
214
215 LIBINPUT_EXPORT li_fixed_t
216 libinput_event_touch_get_y(
217         struct libinput_event_touch *event)
218 {
219         return event->y;
220 }
221
222 LIBINPUT_EXPORT enum libinput_touch_type
223 libinput_event_touch_get_touch_type(
224         struct libinput_event_touch *event)
225 {
226         return event->touch_type;
227 }
228
229 struct libinput_source *
230 libinput_add_fd(struct libinput *libinput,
231                 int fd,
232                 libinput_source_dispatch_t dispatch,
233                 void *user_data)
234 {
235         struct libinput_source *source;
236         struct epoll_event ep;
237
238         source = malloc(sizeof *source);
239         if (!source)
240                 return NULL;
241
242         source->dispatch = dispatch;
243         source->user_data = user_data;
244         source->fd = fd;
245
246         memset(&ep, 0, sizeof ep);
247         ep.events = EPOLLIN;
248         ep.data.ptr = source;
249
250         if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
251                 close(source->fd);
252                 free(source);
253                 return NULL;
254         }
255
256         return source;
257 }
258
259 void
260 libinput_remove_source(struct libinput *libinput,
261                        struct libinput_source *source)
262 {
263         epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL);
264         close(source->fd);
265         source->fd = -1;
266         list_insert(&libinput->source_destroy_list, &source->link);
267 }
268
269 int
270 libinput_init(struct libinput *libinput,
271               const struct libinput_interface *interface,
272               const struct libinput_interface_backend *interface_backend,
273               void *user_data)
274 {
275         libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
276         if (libinput->epoll_fd < 0)
277                 return -1;
278
279         libinput->events_len = 4;
280         libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
281         if (!libinput->events) {
282                 close(libinput->epoll_fd);
283                 return -1;
284         }
285
286         libinput->interface = interface;
287         libinput->interface_backend = interface_backend;
288         libinput->user_data = user_data;
289         list_init(&libinput->source_destroy_list);
290         list_init(&libinput->seat_list);
291
292         return 0;
293 }
294
295 static void
296 libinput_device_destroy(struct libinput_device *device);
297
298 static void
299 libinput_seat_destroy(struct libinput_seat *seat);
300
301 static void
302 libinput_drop_destroyed_sources(struct libinput *libinput)
303 {
304         struct libinput_source *source, *next;
305
306         list_for_each_safe(source, next, &libinput->source_destroy_list, link)
307                 free(source);
308         list_init(&libinput->source_destroy_list);
309 }
310
311 LIBINPUT_EXPORT void
312 libinput_destroy(struct libinput *libinput)
313 {
314         struct libinput_event *event;
315         struct libinput_device *device, *next_device;
316         struct libinput_seat *seat, *next_seat;
317
318         if (libinput == NULL)
319                 return;
320
321         libinput_suspend(libinput);
322
323         libinput->interface_backend->destroy(libinput);
324
325         while ((event = libinput_get_event(libinput)))
326                libinput_event_destroy(event);
327
328         libinput_drop_destroyed_sources(libinput);
329
330         free(libinput->events);
331
332         list_for_each_safe(seat, next_seat, &libinput->seat_list, link) {
333                 list_for_each_safe(device, next_device,
334                                    &seat->devices_list,
335                                    link)
336                         libinput_device_destroy(device);
337
338                 libinput_seat_destroy(seat);
339         }
340
341         close(libinput->epoll_fd);
342         free(libinput);
343 }
344
345 static enum libinput_event_class
346 libinput_event_get_class(struct libinput_event *event)
347 {
348         switch (event->type) {
349         case LIBINPUT_EVENT_NONE:
350                 return LIBINPUT_EVENT_CLASS_NONE;
351
352         case LIBINPUT_EVENT_DEVICE_ADDED:
353         case LIBINPUT_EVENT_DEVICE_REMOVED:
354                 return LIBINPUT_EVENT_CLASS_BASE;
355
356         case LIBINPUT_EVENT_KEYBOARD_KEY:
357         case LIBINPUT_EVENT_POINTER_MOTION:
358         case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
359         case LIBINPUT_EVENT_POINTER_BUTTON:
360         case LIBINPUT_EVENT_POINTER_AXIS:
361         case LIBINPUT_EVENT_TOUCH_TOUCH:
362                 return LIBINPUT_EVENT_CLASS_DEVICE;
363         }
364
365         /* We should never end up here. */
366         abort();
367 }
368
369 LIBINPUT_EXPORT void
370 libinput_event_destroy(struct libinput_event *event)
371 {
372         if (event == NULL)
373                 return;
374
375         switch (libinput_event_get_class(event)) {
376         case LIBINPUT_EVENT_CLASS_NONE:
377         case LIBINPUT_EVENT_CLASS_BASE:
378                 break;
379         case LIBINPUT_EVENT_CLASS_SEAT:
380                 libinput_seat_unref(event->device->seat);
381                 break;
382         case LIBINPUT_EVENT_CLASS_DEVICE:
383                 libinput_device_unref(event->device);
384                 break;
385         }
386
387         free(event);
388 }
389
390 int
391 open_restricted(struct libinput *libinput,
392                 const char *path, int flags)
393 {
394         return libinput->interface->open_restricted(path,
395                                                     flags,
396                                                     libinput->user_data);
397 }
398
399 void
400 close_restricted(struct libinput *libinput, int fd)
401 {
402         return libinput->interface->close_restricted(fd, libinput->user_data);
403 }
404
405 void
406 libinput_seat_init(struct libinput_seat *seat,
407                    struct libinput *libinput,
408                    const char *physical_name,
409                    const char *logical_name,
410                    libinput_seat_destroy_func destroy)
411 {
412         seat->refcount = 1;
413         seat->libinput = libinput;
414         seat->physical_name = strdup(physical_name);
415         seat->logical_name = strdup(logical_name);
416         seat->destroy = destroy;
417         list_init(&seat->devices_list);
418 }
419
420 LIBINPUT_EXPORT void
421 libinput_seat_ref(struct libinput_seat *seat)
422 {
423         seat->refcount++;
424 }
425
426 static void
427 libinput_seat_destroy(struct libinput_seat *seat)
428 {
429         list_remove(&seat->link);
430         free(seat->logical_name);
431         free(seat->physical_name);
432         seat->destroy(seat);
433 }
434
435 LIBINPUT_EXPORT void
436 libinput_seat_unref(struct libinput_seat *seat)
437 {
438         assert(seat->refcount > 0);
439         seat->refcount--;
440         if (seat->refcount == 0)
441                 libinput_seat_destroy(seat);
442 }
443
444 LIBINPUT_EXPORT void
445 libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
446 {
447         seat->user_data = user_data;
448 }
449
450 LIBINPUT_EXPORT void *
451 libinput_seat_get_user_data(struct libinput_seat *seat)
452 {
453         return seat->user_data;
454 }
455
456 LIBINPUT_EXPORT const char *
457 libinput_seat_get_physical_name(struct libinput_seat *seat)
458 {
459         return seat->physical_name;
460 }
461
462 LIBINPUT_EXPORT const char *
463 libinput_seat_get_logical_name(struct libinput_seat *seat)
464 {
465         return seat->logical_name;
466 }
467
468 void
469 libinput_device_init(struct libinput_device *device,
470                      struct libinput_seat *seat)
471 {
472         device->seat = seat;
473         device->refcount = 1;
474 }
475
476 LIBINPUT_EXPORT void
477 libinput_device_ref(struct libinput_device *device)
478 {
479         device->refcount++;
480 }
481
482 static void
483 libinput_device_destroy(struct libinput_device *device)
484 {
485         evdev_device_destroy((struct evdev_device *) device);
486 }
487
488 LIBINPUT_EXPORT void
489 libinput_device_unref(struct libinput_device *device)
490 {
491         assert(device->refcount > 0);
492         device->refcount--;
493         if (device->refcount == 0)
494                 libinput_device_destroy(device);
495 }
496
497 LIBINPUT_EXPORT int
498 libinput_get_fd(struct libinput *libinput)
499 {
500         return libinput->epoll_fd;
501 }
502
503 LIBINPUT_EXPORT int
504 libinput_dispatch(struct libinput *libinput)
505 {
506         struct libinput_source *source;
507         struct epoll_event ep[32];
508         int i, count;
509
510         count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0);
511         if (count < 0)
512                 return -errno;
513
514         for (i = 0; i < count; ++i) {
515                 source = ep[i].data.ptr;
516                 if (source->fd == -1)
517                         continue;
518
519                 source->dispatch(source->user_data);
520         }
521
522         libinput_drop_destroyed_sources(libinput);
523
524         return 0;
525 }
526
527 static void
528 init_event_base(struct libinput_event *event,
529                 struct libinput_device *device,
530                 enum libinput_event_type type)
531 {
532         event->type = type;
533         event->device = device;
534 }
535
536 static void
537 post_base_event(struct libinput_device *device,
538                 enum libinput_event_type type,
539                 struct libinput_event *event)
540 {
541         struct libinput *libinput = device->seat->libinput;
542         init_event_base(event, device, type);
543         libinput_post_event(libinput, event);
544 }
545
546 static void
547 post_device_event(struct libinput_device *device,
548                   enum libinput_event_type type,
549                   struct libinput_event *event)
550 {
551         init_event_base(event, device, type);
552         libinput_post_event(device->seat->libinput, event);
553 }
554
555 void
556 notify_added_device(struct libinput_device *device)
557 {
558         struct libinput_event_device_notify *added_device_event;
559
560         added_device_event = zalloc(sizeof *added_device_event);
561         if (!added_device_event)
562                 return;
563
564         *added_device_event = (struct libinput_event_device_notify) {
565                 .device = device,
566         };
567
568         post_base_event(device,
569                         LIBINPUT_EVENT_DEVICE_ADDED,
570                         &added_device_event->base);
571 }
572
573 void
574 notify_removed_device(struct libinput_device *device)
575 {
576         struct libinput_event_device_notify *removed_device_event;
577
578         removed_device_event = zalloc(sizeof *removed_device_event);
579         if (!removed_device_event)
580                 return;
581
582         *removed_device_event = (struct libinput_event_device_notify) {
583                 .device = device,
584         };
585
586         post_base_event(device,
587                         LIBINPUT_EVENT_DEVICE_REMOVED,
588                         &removed_device_event->base);
589 }
590
591 void
592 keyboard_notify_key(struct libinput_device *device,
593                     uint32_t time,
594                     uint32_t key,
595                     enum libinput_keyboard_key_state state)
596 {
597         struct libinput_event_keyboard *key_event;
598
599         key_event = zalloc(sizeof *key_event);
600         if (!key_event)
601                 return;
602
603         *key_event = (struct libinput_event_keyboard) {
604                 .time = time,
605                 .key = key,
606                 .state = state,
607         };
608
609         post_device_event(device,
610                           LIBINPUT_EVENT_KEYBOARD_KEY,
611                           &key_event->base);
612 }
613
614 void
615 pointer_notify_motion(struct libinput_device *device,
616                       uint32_t time,
617                       li_fixed_t dx,
618                       li_fixed_t dy)
619 {
620         struct libinput_event_pointer *motion_event;
621
622         motion_event = zalloc(sizeof *motion_event);
623         if (!motion_event)
624                 return;
625
626         *motion_event = (struct libinput_event_pointer) {
627                 .time = time,
628                 .x = dx,
629                 .y = dy,
630         };
631
632         post_device_event(device,
633                           LIBINPUT_EVENT_POINTER_MOTION,
634                           &motion_event->base);
635 }
636
637 void
638 pointer_notify_motion_absolute(struct libinput_device *device,
639                                uint32_t time,
640                                li_fixed_t x,
641                                li_fixed_t y)
642 {
643         struct libinput_event_pointer *motion_absolute_event;
644
645         motion_absolute_event = zalloc(sizeof *motion_absolute_event);
646         if (!motion_absolute_event)
647                 return;
648
649         *motion_absolute_event = (struct libinput_event_pointer) {
650                 .time = time,
651                 .x = x,
652                 .y = y,
653         };
654
655         post_device_event(device,
656                           LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
657                           &motion_absolute_event->base);
658 }
659
660 void
661 pointer_notify_button(struct libinput_device *device,
662                       uint32_t time,
663                       int32_t button,
664                       enum libinput_pointer_button_state state)
665 {
666         struct libinput_event_pointer *button_event;
667
668         button_event = zalloc(sizeof *button_event);
669         if (!button_event)
670                 return;
671
672         *button_event = (struct libinput_event_pointer) {
673                 .time = time,
674                 .button = button,
675                 .state = state,
676         };
677
678         post_device_event(device,
679                           LIBINPUT_EVENT_POINTER_BUTTON,
680                           &button_event->base);
681 }
682
683 void
684 pointer_notify_axis(struct libinput_device *device,
685                     uint32_t time,
686                     enum libinput_pointer_axis axis,
687                     li_fixed_t value)
688 {
689         struct libinput_event_pointer *axis_event;
690
691         axis_event = zalloc(sizeof *axis_event);
692         if (!axis_event)
693                 return;
694
695         *axis_event = (struct libinput_event_pointer) {
696                 .time = time,
697                 .axis = axis,
698                 .value = value,
699         };
700
701         post_device_event(device,
702                           LIBINPUT_EVENT_POINTER_AXIS,
703                           &axis_event->base);
704 }
705
706 void
707 touch_notify_touch(struct libinput_device *device,
708                    uint32_t time,
709                    int32_t slot,
710                    li_fixed_t x,
711                    li_fixed_t y,
712                    enum libinput_touch_type touch_type)
713 {
714         struct libinput_event_touch *touch_event;
715
716         touch_event = zalloc(sizeof *touch_event);
717         if (!touch_event)
718                 return;
719
720         *touch_event = (struct libinput_event_touch) {
721                 .time = time,
722                 .slot = slot,
723                 .x = x,
724                 .y = y,
725                 .touch_type = touch_type,
726         };
727
728         post_device_event(device,
729                           LIBINPUT_EVENT_TOUCH_TOUCH,
730                           &touch_event->base);
731 }
732
733 static void
734 libinput_post_event(struct libinput *libinput,
735                     struct libinput_event *event)
736 {
737         struct libinput_event **events = libinput->events;
738         size_t events_len = libinput->events_len;
739         size_t events_count = libinput->events_count;
740         size_t move_len;
741         size_t new_out;
742
743         events_count++;
744         if (events_count > events_len) {
745                 events_len *= 2;
746                 events = realloc(events, events_len * sizeof *events);
747                 if (!events) {
748                         fprintf(stderr, "Failed to reallocate event ring "
749                                 "buffer");
750                         return;
751                 }
752
753                 if (libinput->events_count > 0 && libinput->events_in == 0) {
754                         libinput->events_in = libinput->events_len;
755                 } else if (libinput->events_count > 0 &&
756                            libinput->events_out >= libinput->events_in) {
757                         move_len = libinput->events_len - libinput->events_out;
758                         new_out = events_len - move_len;
759                         memmove(events + new_out,
760                                 events + libinput->events_out,
761                                 move_len * sizeof *events);
762                         libinput->events_out = new_out;
763                 }
764
765                 libinput->events = events;
766                 libinput->events_len = events_len;
767         }
768
769         switch (libinput_event_get_class(event)) {
770         case LIBINPUT_EVENT_CLASS_NONE:
771         case LIBINPUT_EVENT_CLASS_BASE:
772                 break;
773         case LIBINPUT_EVENT_CLASS_SEAT:
774                 libinput_seat_ref(event->device->seat);
775                 break;
776         case LIBINPUT_EVENT_CLASS_DEVICE:
777                 libinput_device_ref(event->device);
778                 break;
779         }
780
781         libinput->events_count = events_count;
782         events[libinput->events_in] = event;
783         libinput->events_in = (libinput->events_in + 1) % libinput->events_len;
784 }
785
786 LIBINPUT_EXPORT struct libinput_event *
787 libinput_get_event(struct libinput *libinput)
788 {
789         struct libinput_event *event;
790
791         if (libinput->events_count == 0)
792                 return NULL;
793
794         event = libinput->events[libinput->events_out];
795         libinput->events_out =
796                 (libinput->events_out + 1) % libinput->events_len;
797         libinput->events_count--;
798
799         return event;
800 }
801
802 LIBINPUT_EXPORT enum libinput_event_type
803 libinput_next_event_type(struct libinput *libinput)
804 {
805         struct libinput_event *event;
806
807         if (libinput->events_count == 0)
808                 return LIBINPUT_EVENT_NONE;
809
810         event = libinput->events[libinput->events_out];
811         return event->type;
812 }
813
814 LIBINPUT_EXPORT void *
815 libinput_get_user_data(struct libinput *libinput)
816 {
817         return libinput->user_data;
818 }
819
820 LIBINPUT_EXPORT int
821 libinput_resume(struct libinput *libinput)
822 {
823         return libinput->interface_backend->resume(libinput);
824 }
825
826 LIBINPUT_EXPORT void
827 libinput_suspend(struct libinput *libinput)
828 {
829         libinput->interface_backend->suspend(libinput);
830 }
831
832 LIBINPUT_EXPORT void
833 libinput_device_set_user_data(struct libinput_device *device, void *user_data)
834 {
835         device->user_data = user_data;
836 }
837
838 LIBINPUT_EXPORT void *
839 libinput_device_get_user_data(struct libinput_device *device)
840 {
841         return device->user_data;
842 }
843
844 LIBINPUT_EXPORT const char *
845 libinput_device_get_sysname(struct libinput_device *device)
846 {
847         return evdev_device_get_sysname((struct evdev_device *) device);
848 }
849
850 LIBINPUT_EXPORT const char *
851 libinput_device_get_output_name(struct libinput_device *device)
852 {
853         return evdev_device_get_output((struct evdev_device *) device);
854 }
855
856 LIBINPUT_EXPORT struct libinput_seat *
857 libinput_device_get_seat(struct libinput_device *device)
858 {
859         return device->seat;
860 }
861
862 LIBINPUT_EXPORT void
863 libinput_device_led_update(struct libinput_device *device,
864                            enum libinput_led leds)
865 {
866         evdev_device_led_update((struct evdev_device *) device, leds);
867 }
868
869 LIBINPUT_EXPORT int
870 libinput_device_get_keys(struct libinput_device *device,
871                          char *keys, size_t size)
872 {
873         return evdev_device_get_keys((struct evdev_device *) device,
874                                      keys,
875                                      size);
876 }
877
878 LIBINPUT_EXPORT void
879 libinput_device_calibrate(struct libinput_device *device,
880                           float calibration[6])
881 {
882         evdev_device_calibrate((struct evdev_device *) device, calibration);
883 }
884
885 LIBINPUT_EXPORT int
886 libinput_device_has_capability(struct libinput_device *device,
887                                enum libinput_device_capability capability)
888 {
889         return evdev_device_has_capability((struct evdev_device *) device,
890                                            capability);
891 }