2 * Copyright © 2013 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32 #include "libevdev-int.h"
33 #include "libevdev-util.h"
34 #include "event-names.h"
38 static int sync_mt_state(struct libevdev *dev, int create_events);
41 init_event_queue(struct libevdev *dev)
43 /* FIXME: count the number of axes, keys, etc. to get a better idea at how many events per
44 EV_SYN we could possibly get. Then multiply that by the actual buffer size we care about */
46 const int QUEUE_SIZE = 256;
48 return queue_alloc(dev, QUEUE_SIZE);
52 _libevdev_log(struct libevdev *dev, const char *format, ...)
56 va_start(args, format);
57 dev->log(format, args);
62 libevdev_noop_log_func(const char *format, va_list args)
71 dev = calloc(1, sizeof(*dev));
76 dev->current_slot = -1;
77 dev->log = libevdev_noop_log_func;
78 dev->grabbed = LIBEVDEV_UNGRAB;
79 dev->sync_state = SYNC_NONE;
85 libevdev_new_from_fd(int fd, struct libevdev **dev)
94 rc = libevdev_set_fd(d, fd);
103 libevdev_free(struct libevdev *dev)
116 libevdev_set_log_handler(struct libevdev *dev, libevdev_log_func_t logfunc)
121 dev->log = logfunc ? logfunc : libevdev_noop_log_func;
125 libevdev_change_fd(struct libevdev *dev, int fd)
134 libevdev_set_fd(struct libevdev* dev, int fd)
143 rc = ioctl(fd, EVIOCGBIT(0, sizeof(dev->bits)), dev->bits);
147 memset(buf, 0, sizeof(buf));
148 rc = ioctl(fd, EVIOCGNAME(sizeof(buf) - 1), buf);
153 dev->name = strdup(buf);
161 memset(buf, 0, sizeof(buf));
162 rc = ioctl(fd, EVIOCGPHYS(sizeof(buf) - 1), buf);
164 /* uinput has no phys */
168 dev->phys = strdup(buf);
177 memset(buf, 0, sizeof(buf));
178 rc = ioctl(fd, EVIOCGUNIQ(sizeof(buf) - 1), buf);
183 dev->uniq = strdup(buf);
190 rc = ioctl(fd, EVIOCGID, &dev->ids);
194 rc = ioctl(fd, EVIOCGVERSION, &dev->driver_version);
198 rc = ioctl(fd, EVIOCGPROP(sizeof(dev->props)), dev->props);
202 rc = ioctl(fd, EVIOCGBIT(EV_REL, sizeof(dev->rel_bits)), dev->rel_bits);
206 rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(dev->abs_bits)), dev->abs_bits);
210 rc = ioctl(fd, EVIOCGBIT(EV_LED, sizeof(dev->led_bits)), dev->led_bits);
214 rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(dev->key_bits)), dev->key_bits);
218 rc = ioctl(fd, EVIOCGBIT(EV_SW, sizeof(dev->sw_bits)), dev->sw_bits);
222 rc = ioctl(fd, EVIOCGBIT(EV_MSC, sizeof(dev->msc_bits)), dev->msc_bits);
226 rc = ioctl(fd, EVIOCGBIT(EV_FF, sizeof(dev->ff_bits)), dev->ff_bits);
230 rc = ioctl(fd, EVIOCGBIT(EV_SND, sizeof(dev->snd_bits)), dev->snd_bits);
234 rc = ioctl(fd, EVIOCGKEY(sizeof(dev->key_values)), dev->key_values);
238 rc = ioctl(fd, EVIOCGLED(sizeof(dev->led_values)), dev->led_values);
242 /* rep is a special case, always set it to 1 for both values if EV_REP is set */
243 if (bit_is_set(dev->bits, EV_REP)) {
244 for (i = 0; i < REP_CNT; i++)
245 set_bit(dev->rep_bits, i);
246 rc = ioctl(fd, EVIOCGREP, dev->rep_values);
251 for (i = ABS_X; i <= ABS_MAX; i++) {
252 if (bit_is_set(dev->abs_bits, i)) {
253 struct input_absinfo abs_info;
254 rc = ioctl(fd, EVIOCGABS(i), &abs_info);
258 dev->abs_info[i] = abs_info;
259 if (i == ABS_MT_SLOT) {
260 dev->num_slots = abs_info.maximum + 1;
261 dev->current_slot = abs_info.value;
268 sync_mt_state(dev, 0);
270 rc = init_event_queue(dev);
276 /* not copying key state because we won't know when we'll start to
277 * use this fd and key's are likely to change state by then.
278 * Same with the valuators, really, but they may not change.
282 return rc ? -errno : 0;
286 libevdev_get_fd(const struct libevdev* dev)
292 init_event(struct libevdev *dev, struct input_event *ev, int type, int code, int value)
294 ev->time = dev->last_event_time;
301 sync_key_state(struct libevdev *dev)
305 unsigned long keystate[NLONGS(KEY_CNT)];
307 rc = ioctl(dev->fd, EVIOCGKEY(sizeof(keystate)), keystate);
311 for (i = 0; i < KEY_MAX; i++) {
313 old = bit_is_set(dev->key_values, i);
314 new = bit_is_set(keystate, i);
316 struct input_event *ev = queue_push(dev);
317 init_event(dev, ev, EV_KEY, i, new ? 1 : 0);
319 set_bit_state(dev->key_values, i, new);
324 return rc ? -errno : 0;
328 sync_led_state(struct libevdev *dev)
332 unsigned long ledstate[NLONGS(LED_CNT)];
334 rc = ioctl(dev->fd, EVIOCGLED(sizeof(ledstate)), ledstate);
338 for (i = 0; i < LED_MAX; i++) {
340 old = bit_is_set(dev->led_values, i);
341 new = bit_is_set(ledstate, i);
343 struct input_event *ev = queue_push(dev);
344 init_event(dev, ev, EV_LED, i, new ? 1 : 0);
346 set_bit_state(dev->led_values, i, new);
351 return rc ? -errno : 0;
354 sync_abs_state(struct libevdev *dev)
359 for (i = ABS_X; i <= ABS_MAX; i++) {
360 struct input_absinfo abs_info;
362 if (i >= ABS_MT_MIN && i <= ABS_MT_MAX)
365 if (!bit_is_set(dev->abs_bits, i))
368 rc = ioctl(dev->fd, EVIOCGABS(i), &abs_info);
372 if (dev->abs_info[i].value != abs_info.value) {
373 struct input_event *ev = queue_push(dev);
375 init_event(dev, ev, EV_ABS, i, abs_info.value);
376 dev->abs_info[i].value = abs_info.value;
382 return rc ? -errno : 0;
386 sync_mt_state(struct libevdev *dev, int create_events)
393 } mt_state[ABS_MT_CNT];
395 for (i = ABS_MT_MIN; i < ABS_MT_MAX; i++) {
397 if (i == ABS_MT_SLOT)
400 if (!libevdev_has_event_code(dev, EV_ABS, i))
403 idx = i - ABS_MT_MIN;
404 mt_state[idx].code = i;
405 rc = ioctl(dev->fd, EVIOCGMTSLOTS(sizeof(struct mt_state)), &mt_state[idx]);
410 for (i = 0; i < dev->num_slots; i++) {
412 struct input_event *ev;
415 ev = queue_push(dev);
416 init_event(dev, ev, EV_ABS, ABS_MT_SLOT, i);
419 for (j = ABS_MT_MIN; j < ABS_MT_MAX; j++) {
420 int jdx = j - ABS_MT_MIN;
422 if (j == ABS_MT_SLOT)
425 if (!libevdev_has_event_code(dev, EV_ABS, j))
428 if (dev->mt_slot_vals[i][jdx] == mt_state[jdx].val[i])
432 ev = queue_push(dev);
433 init_event(dev, ev, EV_ABS, j, mt_state[jdx].val[i]);
435 dev->mt_slot_vals[i][jdx] = mt_state[jdx].val[i];
441 return rc ? -errno : 0;
445 sync_state(struct libevdev *dev)
449 struct input_event *ev;
451 /* FIXME: if we have events in the queue after the SYN_DROPPED (which was
452 queue[0]) we need to shift this backwards. Except that chances are that the
453 queue may be either full or too full to prepend all the events needed for
456 so we search for the last sync event in the queue and drop everything before
457 including that event and rely on the kernel to tell us the right value for that
458 bitfield during the sync process.
461 for (i = queue_num_elements(dev) - 1; i >= 0; i--) {
462 struct input_event e;
463 queue_peek(dev, i, &e);
464 if (e.type == EV_SYN)
469 queue_shift_multiple(dev, i + 1, NULL);
471 if (libevdev_has_event_type(dev, EV_KEY))
472 rc = sync_key_state(dev);
473 if (libevdev_has_event_type(dev, EV_LED))
474 rc = sync_led_state(dev);
475 if (rc == 0 && libevdev_has_event_type(dev, EV_ABS))
476 rc = sync_abs_state(dev);
477 if (rc == 0 && libevdev_has_event_code(dev, EV_ABS, ABS_MT_SLOT))
478 rc = sync_mt_state(dev, 1);
480 dev->queue_nsync = queue_num_elements(dev);
482 if (dev->queue_nsync > 0) {
483 ev = queue_push(dev);
484 init_event(dev, ev, EV_SYN, SYN_REPORT, 0);
492 update_key_state(struct libevdev *dev, const struct input_event *e)
494 if (!libevdev_has_event_type(dev, EV_KEY))
497 if (e->code > KEY_MAX)
500 set_bit_state(dev->key_values, e->code, e->value != 0);
506 update_mt_state(struct libevdev *dev, const struct input_event *e)
508 if (e->code == ABS_MT_SLOT) {
510 dev->current_slot = e->value;
511 /* sync abs_info with the current slot values */
512 for (i = ABS_MT_SLOT + 1; i <= ABS_MT_MAX; i++) {
513 if (libevdev_has_event_code(dev, EV_ABS, i))
514 dev->abs_info[i].value = dev->mt_slot_vals[dev->current_slot][i - ABS_MT_MIN];
518 } else if (dev->current_slot == -1)
521 dev->mt_slot_vals[dev->current_slot][e->code - ABS_MT_MIN] = e->value;
527 update_abs_state(struct libevdev *dev, const struct input_event *e)
529 if (!libevdev_has_event_type(dev, EV_ABS))
532 if (e->code > ABS_MAX)
535 if (e->code >= ABS_MT_MIN && e->code <= ABS_MT_MAX)
536 update_mt_state(dev, e);
538 dev->abs_info[e->code].value = e->value;
544 update_led_state(struct libevdev *dev, const struct input_event *e)
546 if (!libevdev_has_event_type(dev, EV_LED))
549 if (e->code > LED_MAX)
552 set_bit_state(dev->led_values, e->code, e->value != 0);
558 update_state(struct libevdev *dev, const struct input_event *e)
567 rc = update_key_state(dev, e);
570 rc = update_abs_state(dev, e);
573 rc = update_led_state(dev, e);
577 dev->last_event_time = e->time;
583 read_more_events(struct libevdev *dev)
587 struct input_event *next;
589 free_elem = queue_num_free_elements(dev);
593 next = queue_next_element(dev);
594 len = read(dev->fd, next, free_elem * sizeof(struct input_event));
597 } else if (len > 0 && len % sizeof(struct input_event) != 0)
600 int nev = len/sizeof(struct input_event);
601 queue_set_num_elements(dev, queue_num_elements(dev) + nev);
607 int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_event *ev)
614 if (!(flags & (LIBEVDEV_READ_NORMAL|LIBEVDEV_READ_SYNC|LIBEVDEV_FORCE_SYNC)))
617 if (flags & LIBEVDEV_READ_SYNC) {
618 if (dev->sync_state == SYNC_NEEDED) {
619 rc = sync_state(dev);
622 dev->sync_state = SYNC_IN_PROGRESS;
625 if (dev->queue_nsync == 0) {
626 dev->sync_state = SYNC_NONE;
630 } else if (dev->sync_state != SYNC_NONE) {
631 struct input_event e;
633 /* call update_state for all events here, otherwise the library has the wrong view
635 while (queue_shift(dev, &e) == 0) {
637 update_state(dev, &e);
640 dev->sync_state = SYNC_NONE;
643 /* FIXME: if the first event after SYNC_IN_PROGRESS is a SYN_DROPPED, log this */
645 /* Always read in some more events. Best case this smoothes over a potential SYN_DROPPED,
646 worst case we don't read fast enough and end up with SYN_DROPPED anyway.
648 Except if the fd is in blocking mode and we still have events from the last read, don't
652 if (!(flags & LIBEVDEV_READ_BLOCKING) ||
653 queue_num_elements(dev) == 0) {
654 rc = read_more_events(dev);
655 if (rc < 0 && rc != -EAGAIN)
659 if (flags & LIBEVDEV_FORCE_SYNC) {
660 dev->sync_state = SYNC_NEEDED;
666 if (queue_shift(dev, ev) != 0)
669 update_state(dev, ev);
671 /* if we disabled a code, get the next event instead */
672 } while(!libevdev_has_event_code(dev, ev->type, ev->code));
675 if (ev->type == EV_SYN && ev->code == SYN_DROPPED) {
676 dev->sync_state = SYNC_NEEDED;
680 if (flags & LIBEVDEV_READ_SYNC && dev->queue_nsync > 0) {
683 if (dev->queue_nsync == 0)
684 dev->sync_state = SYNC_NONE;
691 int libevdev_has_event_pending(struct libevdev *dev)
693 struct pollfd fds = { dev->fd, POLLIN, 0 };
699 if (queue_num_elements(dev) != 0)
702 rc = poll(&fds, 1, 0);
703 return (rc >= 0) ? rc : -errno;
707 libevdev_get_name(const struct libevdev *dev)
709 return dev->name ? dev->name : "";
713 libevdev_get_phys(const struct libevdev *dev)
719 libevdev_get_uniq(const struct libevdev *dev)
724 #define STRING_SETTER(field) \
725 void libevdev_set_##field(struct libevdev *dev, const char *field) \
730 dev->field = strdup(field); \
738 #define PRODUCT_GETTER(name, field) \
739 int libevdev_get_##name(const struct libevdev *dev) \
741 return dev->ids.field; \
744 PRODUCT_GETTER(product_id, product); /* DEPRECATED */
745 PRODUCT_GETTER(vendor_id, vendor); /* DEPRECATED */
746 PRODUCT_GETTER(bustype, bustype); /* DEPRECATED */
747 PRODUCT_GETTER(version, version); /* DEPRECATED */
749 PRODUCT_GETTER(id_product, product);
750 PRODUCT_GETTER(id_vendor, vendor);
751 PRODUCT_GETTER(id_bustype, bustype);
752 PRODUCT_GETTER(id_version, version);
754 #define PRODUCT_SETTER(field) \
755 void libevdev_set_id_##field(struct libevdev *dev, int field) \
757 dev->ids.field = field;\
760 PRODUCT_SETTER(product);
761 PRODUCT_SETTER(vendor);
762 PRODUCT_SETTER(bustype);
763 PRODUCT_SETTER(version);
765 int libevdev_get_driver_version(const struct libevdev *dev)
767 return dev->driver_version;
771 libevdev_has_property(const struct libevdev *dev, unsigned int prop)
773 return (prop <= INPUT_PROP_MAX) && bit_is_set(dev->props, prop);
777 libevdev_enable_property(struct libevdev *dev, unsigned int prop)
779 if (prop > INPUT_PROP_MAX)
782 set_bit(dev->props, prop);
787 libevdev_has_event_type(const struct libevdev *dev, unsigned int type)
789 return (type <= EV_MAX) && bit_is_set(dev->bits, type);
793 libevdev_has_event_code(const struct libevdev *dev, unsigned int type, unsigned int code)
795 const unsigned long *mask;
798 if (!libevdev_has_event_type(dev, type))
804 max = type_to_mask_const(dev, type, &mask);
806 if (max == -1 || code > max)
809 return bit_is_set(mask, code);
813 libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code)
817 if (!libevdev_has_event_type(dev, type) || !libevdev_has_event_code(dev, type, code))
821 case EV_ABS: value = dev->abs_info[code].value; break;
822 case EV_KEY: value = bit_is_set(dev->key_values, code); break;
823 case EV_LED: value = bit_is_set(dev->led_values, code); break;
832 int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value)
835 struct input_event e;
837 if (!libevdev_has_event_type(dev, type) || !libevdev_has_event_code(dev, type, code))
845 case EV_ABS: rc = update_abs_state(dev, &e); break;
846 case EV_KEY: rc = update_key_state(dev, &e); break;
847 case EV_LED: rc = update_led_state(dev, &e); break;
857 libevdev_fetch_event_value(const struct libevdev *dev, unsigned int type, unsigned int code, int *value)
859 if (libevdev_has_event_type(dev, type) &&
860 libevdev_has_event_code(dev, type, code)) {
861 *value = libevdev_get_event_value(dev, type, code);
868 libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code)
870 if (!libevdev_has_event_type(dev, EV_ABS) || !libevdev_has_event_code(dev, EV_ABS, code))
873 if (slot >= dev->num_slots || slot >= MAX_SLOTS)
876 if (code > ABS_MT_MAX || code < ABS_MT_MIN)
879 return dev->mt_slot_vals[slot][code - ABS_MT_MIN];
883 libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value)
885 if (!libevdev_has_event_type(dev, EV_ABS) || !libevdev_has_event_code(dev, EV_ABS, code))
888 if (slot >= dev->num_slots || slot >= MAX_SLOTS)
891 if (code > ABS_MT_MAX || code < ABS_MT_MIN)
894 if (code == ABS_MT_SLOT) {
895 if (value < 0 || value >= libevdev_get_num_slots(dev))
897 dev->current_slot = value;
900 dev->mt_slot_vals[slot][code - ABS_MT_MIN] = value;
907 libevdev_fetch_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code, int *value)
909 if (libevdev_has_event_type(dev, EV_ABS) &&
910 libevdev_has_event_code(dev, EV_ABS, code) &&
911 slot < dev->num_slots && slot < MAX_SLOTS) {
912 *value = libevdev_get_slot_value(dev, slot, code);
919 libevdev_get_num_slots(const struct libevdev *dev)
921 return dev->num_slots;
925 libevdev_get_current_slot(const struct libevdev *dev)
927 return dev->current_slot;
930 const struct input_absinfo*
931 libevdev_get_abs_info(const struct libevdev *dev, unsigned int code)
933 if (!libevdev_has_event_type(dev, EV_ABS) ||
934 !libevdev_has_event_code(dev, EV_ABS, code))
937 return &dev->abs_info[code];
940 #define ABS_GETTER(name, field) \
941 int libevdev_get_abs_##name(const struct libevdev *dev, unsigned int code) \
943 const struct input_absinfo *absinfo = libevdev_get_abs_info(dev, code); \
944 return absinfo ? absinfo->field : 0; \
947 ABS_GETTER(max, maximum); /* DEPRECATED */
948 ABS_GETTER(min, minimum); /* DEPRECATED */
949 ABS_GETTER(maximum, maximum);
950 ABS_GETTER(minimum, minimum);
951 ABS_GETTER(fuzz, fuzz)
952 ABS_GETTER(flat, flat)
953 ABS_GETTER(resolution, resolution)
955 #define ABS_SETTER(field) \
956 void libevdev_set_abs_##field(struct libevdev *dev, unsigned int code, int val) \
958 if (!libevdev_has_event_code(dev, EV_ABS, code)) \
960 dev->abs_info[code].field = val; \
967 ABS_SETTER(resolution)
969 void libevdev_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
971 if (!libevdev_has_event_code(dev, EV_ABS, code))
974 dev->abs_info[code] = *abs;
978 libevdev_enable_event_type(struct libevdev *dev, unsigned int type)
983 if (libevdev_has_event_type(dev, type))
986 set_bit(dev->bits, type);
988 if (type == EV_REP) {
989 int delay = 0, period = 0;
990 libevdev_enable_event_code(dev, EV_REP, REP_DELAY, &delay);
991 libevdev_enable_event_code(dev, EV_REP, REP_PERIOD, &period);
997 libevdev_disable_event_type(struct libevdev *dev, unsigned int type)
999 if (type > EV_MAX || type == EV_SYN)
1002 clear_bit(dev->bits, type);
1008 libevdev_enable_event_code(struct libevdev *dev, unsigned int type,
1009 unsigned int code, const void *data)
1012 unsigned long *mask;
1014 if (libevdev_enable_event_type(dev, type))
1031 max = type_to_mask(dev, type, &mask);
1036 set_bit(mask, code);
1038 if (type == EV_ABS) {
1039 const struct input_absinfo *abs = data;
1040 dev->abs_info[code] = *abs;
1041 } else if (type == EV_REP) {
1042 const int *value = data;
1043 dev->rep_values[code] = *value;
1050 libevdev_disable_event_code(struct libevdev *dev, unsigned int type, unsigned int code)
1053 unsigned long *mask;
1058 max = type_to_mask(dev, type, &mask);
1063 clear_bit(mask, code);
1070 libevdev_kernel_set_abs_value(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
1072 return libevdev_kernel_set_abs_info(dev, code, abs);
1076 libevdev_kernel_set_abs_info(struct libevdev *dev, unsigned int code, const struct input_absinfo *abs)
1083 rc = ioctl(dev->fd, EVIOCSABS(code), abs);
1087 rc = libevdev_enable_event_code(dev, EV_ABS, code, abs);
1093 libevdev_grab(struct libevdev *dev, enum libevdev_grab_mode grab)
1097 if (grab != LIBEVDEV_GRAB && grab != LIBEVDEV_UNGRAB)
1100 if (grab == dev->grabbed)
1103 if (grab == LIBEVDEV_GRAB)
1104 rc = ioctl(dev->fd, EVIOCGRAB, (void *)1);
1105 else if (grab == LIBEVDEV_UNGRAB)
1106 rc = ioctl(dev->fd, EVIOCGRAB, (void *)0);
1109 dev->grabbed = grab;
1111 return rc < 0 ? -errno : 0;
1115 libevdev_is_event_type(const struct input_event *ev, unsigned int type)
1117 return type < EV_MAX && ev->type == type;
1121 libevdev_is_event_code(const struct input_event *ev, unsigned int type, unsigned int code)
1123 return type < EV_MAX &&
1125 (type == EV_SYN || code <= libevdev_get_event_type_max(type)) &&
1130 libevdev_get_event_type_name(unsigned int type)
1135 return ev_map[type];
1139 libevdev_get_event_code_name(unsigned int type, unsigned int code)
1144 if (code > ev_max[type])
1147 return event_type_map[type][code];
1152 libevdev_get_input_prop_name(unsigned int prop)
1154 return libevdev_get_property_name(prop);
1158 libevdev_get_property_name(unsigned int prop)
1160 if (prop > INPUT_PROP_MAX)
1163 return input_prop_map[prop];
1167 libevdev_get_event_type_max(unsigned int type)
1172 return ev_max[type];
1176 libevdev_get_repeat(struct libevdev *dev, int *delay, int *period)
1178 if (!libevdev_has_event_type(dev, EV_REP))
1182 *delay = dev->rep_values[REP_DELAY];
1184 *period = dev->rep_values[REP_PERIOD];
1190 libevdev_kernel_set_led_value(struct libevdev *dev, unsigned int code, enum libevdev_led_value value)
1192 return libevdev_kernel_set_led_values(dev, code, value, -1);
1196 libevdev_kernel_set_led_values(struct libevdev *dev, ...)
1198 struct input_event ev[LED_MAX + 1];
1199 enum libevdev_led_value val;
1205 memset(ev, 0, sizeof(ev));
1207 va_start(args, dev);
1208 code = va_arg(args, unsigned int);
1209 while (code != -1) {
1210 if (code > LED_MAX) {
1214 val = va_arg(args, enum libevdev_led_value);
1215 if (val != LIBEVDEV_LED_ON && val != LIBEVDEV_LED_OFF) {
1220 if (libevdev_has_event_code(dev, EV_LED, code)) {
1221 struct input_event *e = ev;
1223 while (e->type > 0 && e->code != code)
1230 e->value = (val == LIBEVDEV_LED_ON);
1232 code = va_arg(args, unsigned int);
1236 if (rc == 0 && nleds > 0) {
1237 ev[nleds].type = EV_SYN;
1238 ev[nleds++].code = SYN_REPORT;
1240 rc = write(libevdev_get_fd(dev), ev, nleds * sizeof(ev[0]));
1242 nleds--; /* last is EV_SYN */
1244 update_led_state(dev, &ev[nleds]);
1246 rc = (rc != -1) ? 0 : -errno;