2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2013 Jonas Ådahl
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include "linux/input.h"
32 #include <mtdev-plumbing.h>
40 #include "libinput-private.h"
42 #define DEFAULT_AXIS_STEP_DISTANCE 10
47 EVDEV_KEY_TYPE_BUTTON,
51 set_key_down(struct evdev_device *device, int code, int pressed)
53 long_set_bit_state(device->key_mask, code, pressed);
57 is_key_down(struct evdev_device *device, int code)
59 return long_bit_is_set(device->key_mask, code);
63 get_key_down_count(struct evdev_device *device, int code)
65 return device->key_count[code];
69 update_key_down_count(struct evdev_device *device, int code, int pressed)
72 assert(code >= 0 && code < KEY_CNT);
75 key_count = ++device->key_count[code];
77 assert(device->key_count[code] > 0);
78 key_count = --device->key_count[code];
82 log_bug_libinput(device->base.seat->libinput,
83 "Key count for %s reached abnormal values\n",
84 libevdev_event_code_get_name(EV_KEY, code));
91 evdev_keyboard_notify_key(struct evdev_device *device,
94 enum libinput_key_state state)
98 down_count = update_key_down_count(device, key, state);
100 if ((state == LIBINPUT_KEY_STATE_PRESSED && down_count == 1) ||
101 (state == LIBINPUT_KEY_STATE_RELEASED && down_count == 0))
102 keyboard_notify_key(&device->base, time, key, state);
106 evdev_pointer_notify_button(struct evdev_device *device,
109 enum libinput_button_state state)
113 down_count = update_key_down_count(device, button, state);
115 if ((state == LIBINPUT_BUTTON_STATE_PRESSED && down_count == 1) ||
116 (state == LIBINPUT_BUTTON_STATE_RELEASED && down_count == 0))
117 pointer_notify_button(&device->base, time, button, state);
121 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds)
123 static const struct {
124 enum libinput_led weston;
127 { LIBINPUT_LED_NUM_LOCK, LED_NUML },
128 { LIBINPUT_LED_CAPS_LOCK, LED_CAPSL },
129 { LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL },
131 struct input_event ev[ARRAY_LENGTH(map) + 1];
134 if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
137 memset(ev, 0, sizeof(ev));
138 for (i = 0; i < ARRAY_LENGTH(map); i++) {
140 ev[i].code = map[i].evdev;
141 ev[i].value = !!(leds & map[i].weston);
144 ev[i].code = SYN_REPORT;
146 i = write(device->fd, ev, sizeof ev);
147 (void)i; /* no, we really don't care about the return value */
151 transform_absolute(struct evdev_device *device, int32_t *x, int32_t *y)
153 if (!device->abs.apply_calibration) {
158 *x = device->abs.x * device->abs.calibration[0] +
159 device->abs.y * device->abs.calibration[1] +
160 device->abs.calibration[2];
162 *y = device->abs.x * device->abs.calibration[3] +
163 device->abs.y * device->abs.calibration[4] +
164 device->abs.calibration[5];
169 scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
171 return (val - absinfo->minimum) * to_range /
172 (absinfo->maximum - absinfo->minimum + 1);
176 evdev_device_transform_x(struct evdev_device *device,
180 return scale_axis(device->abs.absinfo_x, x, width);
184 evdev_device_transform_y(struct evdev_device *device,
188 return scale_axis(device->abs.absinfo_y, y, height);
192 evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
194 struct libinput *libinput = device->base.seat->libinput;
195 struct motion_params motion;
200 struct libinput_device *base = &device->base;
201 struct libinput_seat *seat = base->seat;
203 slot = device->mt.slot;
205 switch (device->pending_event) {
208 case EVDEV_RELATIVE_MOTION:
209 motion.dx = device->rel.dx;
210 motion.dy = device->rel.dy;
214 /* Apply pointer acceleration. */
215 filter_dispatch(device->pointer.filter, &motion, device, time);
217 if (motion.dx == 0.0 && motion.dy == 0.0)
220 pointer_notify_motion(base, time, motion.dx, motion.dy);
222 case EVDEV_ABSOLUTE_MT_DOWN:
223 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
226 if (device->mt.slots[slot].seat_slot != -1) {
227 log_bug_kernel(libinput,
228 "%s: Driver sent multiple touch down for the "
229 "same slot", device->devnode);
233 seat_slot = ffs(~seat->slot_map) - 1;
234 device->mt.slots[slot].seat_slot = seat_slot;
239 seat->slot_map |= 1 << seat_slot;
240 x = device->mt.slots[slot].x;
241 y = device->mt.slots[slot].y;
243 touch_notify_touch_down(base, time, slot, seat_slot, x, y);
245 case EVDEV_ABSOLUTE_MT_MOTION:
246 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
249 seat_slot = device->mt.slots[slot].seat_slot;
250 x = device->mt.slots[slot].x;
251 y = device->mt.slots[slot].y;
256 touch_notify_touch_motion(base, time, slot, seat_slot, x, y);
258 case EVDEV_ABSOLUTE_MT_UP:
259 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
262 seat_slot = device->mt.slots[slot].seat_slot;
263 device->mt.slots[slot].seat_slot = -1;
268 seat->slot_map &= ~(1 << seat_slot);
270 touch_notify_touch_up(base, time, slot, seat_slot);
272 case EVDEV_ABSOLUTE_TOUCH_DOWN:
273 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
276 if (device->abs.seat_slot != -1) {
277 log_bug_kernel(libinput,
278 "%s: Driver sent multiple touch down for the "
279 "same slot", device->devnode);
283 seat_slot = ffs(~seat->slot_map) - 1;
284 device->abs.seat_slot = seat_slot;
289 seat->slot_map |= 1 << seat_slot;
291 transform_absolute(device, &cx, &cy);
293 touch_notify_touch_down(base, time, -1, seat_slot, cx, cy);
295 case EVDEV_ABSOLUTE_MOTION:
296 transform_absolute(device, &cx, &cy);
300 if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
301 seat_slot = device->abs.seat_slot;
306 touch_notify_touch_motion(base, time, -1, seat_slot, x, y);
307 } else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
308 pointer_notify_motion_absolute(base, time, x, y);
311 case EVDEV_ABSOLUTE_TOUCH_UP:
312 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
315 seat_slot = device->abs.seat_slot;
316 device->abs.seat_slot = -1;
321 seat->slot_map &= ~(1 << seat_slot);
323 touch_notify_touch_up(base, time, -1, seat_slot);
326 assert(0 && "Unknown pending event type");
330 device->pending_event = EVDEV_NONE;
333 static enum evdev_key_type
334 get_key_type(uint16_t code)
336 if (code == BTN_TOUCH)
337 return EVDEV_KEY_TYPE_NONE;
339 if (code >= KEY_ESC && code <= KEY_MICMUTE)
340 return EVDEV_KEY_TYPE_KEY;
341 if (code >= BTN_MISC && code <= BTN_GEAR_UP)
342 return EVDEV_KEY_TYPE_BUTTON;
343 if (code >= KEY_OK && code <= KEY_LIGHTS_TOGGLE)
344 return EVDEV_KEY_TYPE_KEY;
345 if (code >= BTN_DPAD_UP && code <= BTN_TRIGGER_HAPPY40)
346 return EVDEV_KEY_TYPE_BUTTON;
347 return EVDEV_KEY_TYPE_NONE;
351 evdev_process_touch_button(struct evdev_device *device,
352 uint64_t time, int value)
354 if (device->pending_event != EVDEV_NONE &&
355 device->pending_event != EVDEV_ABSOLUTE_MOTION)
356 evdev_flush_pending_event(device, time);
358 device->pending_event = (value ?
359 EVDEV_ABSOLUTE_TOUCH_DOWN :
360 EVDEV_ABSOLUTE_TOUCH_UP);
364 evdev_process_key(struct evdev_device *device,
365 struct input_event *e, uint64_t time)
367 enum evdev_key_type type;
369 /* ignore kernel key repeat */
373 if (e->code == BTN_TOUCH) {
375 evdev_process_touch_button(device, time, e->value);
379 evdev_flush_pending_event(device, time);
381 type = get_key_type(e->code);
383 /* Ignore key release events from the kernel for keys that libinput
384 * never got a pressed event for. */
387 case EVDEV_KEY_TYPE_NONE:
389 case EVDEV_KEY_TYPE_KEY:
390 case EVDEV_KEY_TYPE_BUTTON:
391 if (!is_key_down(device, e->code))
396 set_key_down(device, e->code, e->value);
399 case EVDEV_KEY_TYPE_NONE:
401 case EVDEV_KEY_TYPE_KEY:
402 evdev_keyboard_notify_key(
406 e->value ? LIBINPUT_KEY_STATE_PRESSED :
407 LIBINPUT_KEY_STATE_RELEASED);
409 case EVDEV_KEY_TYPE_BUTTON:
410 evdev_pointer_notify_button(
414 e->value ? LIBINPUT_BUTTON_STATE_PRESSED :
415 LIBINPUT_BUTTON_STATE_RELEASED);
421 evdev_process_touch(struct evdev_device *device,
422 struct input_event *e,
427 evdev_flush_pending_event(device, time);
428 device->mt.slot = e->value;
430 case ABS_MT_TRACKING_ID:
431 if (device->pending_event != EVDEV_NONE &&
432 device->pending_event != EVDEV_ABSOLUTE_MT_MOTION)
433 evdev_flush_pending_event(device, time);
435 device->pending_event = EVDEV_ABSOLUTE_MT_DOWN;
437 device->pending_event = EVDEV_ABSOLUTE_MT_UP;
439 case ABS_MT_POSITION_X:
440 device->mt.slots[device->mt.slot].x = e->value;
441 if (device->pending_event == EVDEV_NONE)
442 device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
444 case ABS_MT_POSITION_Y:
445 device->mt.slots[device->mt.slot].y = e->value;
446 if (device->pending_event == EVDEV_NONE)
447 device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
453 evdev_process_absolute_motion(struct evdev_device *device,
454 struct input_event *e)
458 device->abs.x = e->value;
459 if (device->pending_event == EVDEV_NONE)
460 device->pending_event = EVDEV_ABSOLUTE_MOTION;
463 device->abs.y = e->value;
464 if (device->pending_event == EVDEV_NONE)
465 device->pending_event = EVDEV_ABSOLUTE_MOTION;
471 evdev_process_relative(struct evdev_device *device,
472 struct input_event *e, uint64_t time)
474 struct libinput_device *base = &device->base;
478 if (device->pending_event != EVDEV_RELATIVE_MOTION)
479 evdev_flush_pending_event(device, time);
480 device->rel.dx += e->value;
481 device->pending_event = EVDEV_RELATIVE_MOTION;
484 if (device->pending_event != EVDEV_RELATIVE_MOTION)
485 evdev_flush_pending_event(device, time);
486 device->rel.dy += e->value;
487 device->pending_event = EVDEV_RELATIVE_MOTION;
490 evdev_flush_pending_event(device, time);
494 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
495 -1 * e->value * DEFAULT_AXIS_STEP_DISTANCE);
498 evdev_flush_pending_event(device, time);
507 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
508 e->value * DEFAULT_AXIS_STEP_DISTANCE);
518 evdev_process_absolute(struct evdev_device *device,
519 struct input_event *e,
523 evdev_process_touch(device, e, time);
525 evdev_process_absolute_motion(device, e);
530 evdev_need_touch_frame(struct evdev_device *device)
532 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
535 switch (device->pending_event) {
537 case EVDEV_RELATIVE_MOTION:
539 case EVDEV_ABSOLUTE_MT_DOWN:
540 case EVDEV_ABSOLUTE_MT_MOTION:
541 case EVDEV_ABSOLUTE_MT_UP:
542 case EVDEV_ABSOLUTE_TOUCH_DOWN:
543 case EVDEV_ABSOLUTE_TOUCH_UP:
544 case EVDEV_ABSOLUTE_MOTION:
552 fallback_process(struct evdev_dispatch *dispatch,
553 struct evdev_device *device,
554 struct input_event *event,
559 switch (event->type) {
561 evdev_process_relative(device, event, time);
564 evdev_process_absolute(device, event, time);
567 evdev_process_key(device, event, time);
570 need_frame = evdev_need_touch_frame(device);
571 evdev_flush_pending_event(device, time);
573 touch_notify_frame(&device->base, time);
579 fallback_destroy(struct evdev_dispatch *dispatch)
584 struct evdev_dispatch_interface fallback_interface = {
589 static struct evdev_dispatch *
590 fallback_dispatch_create(void)
592 struct evdev_dispatch *dispatch = malloc(sizeof *dispatch);
593 if (dispatch == NULL)
596 dispatch->interface = &fallback_interface;
602 evdev_process_event(struct evdev_device *device, struct input_event *e)
604 struct evdev_dispatch *dispatch = device->dispatch;
605 uint64_t time = e->time.tv_sec * 1000ULL + e->time.tv_usec / 1000;
607 dispatch->interface->process(dispatch, device, e, time);
611 evdev_device_dispatch_one(struct evdev_device *device,
612 struct input_event *ev)
614 if (!device->mtdev) {
615 evdev_process_event(device, ev);
617 mtdev_put_event(device->mtdev, ev);
618 if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) {
619 while (!mtdev_empty(device->mtdev)) {
620 struct input_event e;
621 mtdev_get_event(device->mtdev, &e);
622 evdev_process_event(device, &e);
629 evdev_sync_device(struct evdev_device *device)
631 struct input_event ev;
635 rc = libevdev_next_event(device->evdev,
636 LIBEVDEV_READ_FLAG_SYNC, &ev);
639 evdev_device_dispatch_one(device, &ev);
640 } while (rc == LIBEVDEV_READ_STATUS_SYNC);
642 return rc == -EAGAIN ? 0 : rc;
646 evdev_device_dispatch(void *data)
648 struct evdev_device *device = data;
649 struct libinput *libinput = device->base.seat->libinput;
650 struct input_event ev;
653 /* If the compositor is repainting, this function is called only once
654 * per frame and we have to process all the events available on the
655 * fd, otherwise there will be input lag. */
657 rc = libevdev_next_event(device->evdev,
658 LIBEVDEV_READ_FLAG_NORMAL, &ev);
659 if (rc == LIBEVDEV_READ_STATUS_SYNC) {
660 /* send one more sync event so we handle all
661 currently pending events before we sync up
662 to the current state */
663 ev.code = SYN_REPORT;
664 evdev_device_dispatch_one(device, &ev);
666 rc = evdev_sync_device(device);
668 rc = LIBEVDEV_READ_STATUS_SUCCESS;
669 } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
670 evdev_device_dispatch_one(device, &ev);
672 } while (rc == LIBEVDEV_READ_STATUS_SUCCESS);
674 if (rc != -EAGAIN && rc != -EINTR) {
675 libinput_remove_source(libinput, device->source);
676 device->source = NULL;
681 configure_pointer_acceleration(struct evdev_device *device)
683 device->pointer.filter =
684 create_pointer_accelator_filter(
685 pointer_accel_profile_smooth_simple);
686 if (!device->pointer.filter)
693 evdev_configure_device(struct evdev_device *device)
695 struct libinput *libinput = device->base.seat->libinput;
696 struct libevdev *evdev = device->evdev;
697 const struct input_absinfo *absinfo;
698 struct input_absinfo fixed;
699 int has_abs, has_rel, has_mt;
700 int has_button, has_keyboard, has_touch;
701 struct mt_slot *slots;
714 if (libevdev_has_event_type(evdev, EV_ABS)) {
716 if ((absinfo = libevdev_get_abs_info(evdev, ABS_X))) {
717 if (absinfo->resolution == 0) {
719 fixed.resolution = 1;
720 libevdev_set_abs_info(evdev, ABS_X, &fixed);
721 device->abs.fake_resolution = 1;
723 device->abs.absinfo_x = absinfo;
726 if ((absinfo = libevdev_get_abs_info(evdev, ABS_Y))) {
727 if (absinfo->resolution == 0) {
729 fixed.resolution = 1;
730 libevdev_set_abs_info(evdev, ABS_Y, &fixed);
731 device->abs.fake_resolution = 1;
733 device->abs.absinfo_y = absinfo;
736 /* We only handle the slotted Protocol B in weston.
737 Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
738 require mtdev for conversion. */
739 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
740 libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) {
741 absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
742 if (absinfo->resolution == 0) {
744 fixed.resolution = 1;
745 libevdev_set_abs_info(evdev,
748 device->abs.fake_resolution = 1;
750 device->abs.absinfo_x = absinfo;
751 absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
752 if (absinfo->resolution == 0) {
754 fixed.resolution = 1;
755 libevdev_set_abs_info(evdev,
758 device->abs.fake_resolution = 1;
760 device->abs.absinfo_y = absinfo;
765 if (!libevdev_has_event_code(evdev,
766 EV_ABS, ABS_MT_SLOT)) {
767 device->mtdev = mtdev_new_open(device->fd);
771 num_slots = device->mtdev->caps.slot.maximum;
772 if (device->mtdev->caps.slot.minimum < 0 ||
775 active_slot = device->mtdev->caps.slot.value;
777 num_slots = libevdev_get_num_slots(device->evdev);
778 active_slot = libevdev_get_current_slot(evdev);
781 slots = calloc(num_slots, sizeof(struct mt_slot));
785 for (slot = 0; slot < num_slots; ++slot) {
786 slots[slot].seat_slot = -1;
790 device->mt.slots = slots;
791 device->mt.slots_len = num_slots;
792 device->mt.slot = active_slot;
795 if (libevdev_has_event_code(evdev, EV_REL, REL_X) ||
796 libevdev_has_event_code(evdev, EV_REL, REL_Y))
799 if (libevdev_has_event_type(evdev, EV_KEY)) {
800 if (!libevdev_has_property(evdev, INPUT_PROP_DIRECT) &&
801 libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER) &&
802 !libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
803 (has_abs || has_mt)) {
804 device->dispatch = evdev_mt_touchpad_create(device);
806 "input device '%s', %s is a touchpad\n",
807 device->devname, device->devnode);
808 return device->dispatch == NULL ? -1 : 0;
811 for (i = 0; i < KEY_MAX; i++) {
812 if (libevdev_has_event_code(evdev, EV_KEY, i)) {
813 switch (get_key_type(i)) {
814 case EVDEV_KEY_TYPE_NONE:
816 case EVDEV_KEY_TYPE_KEY:
819 case EVDEV_KEY_TYPE_BUTTON:
826 if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH))
829 if (libevdev_has_event_type(evdev, EV_LED))
832 if ((has_abs || has_rel) && has_button) {
833 if (configure_pointer_acceleration(device) == -1)
836 device->seat_caps |= EVDEV_DEVICE_POINTER;
839 "input device '%s', %s is a pointer caps =%s%s%s\n",
840 device->devname, device->devnode,
841 has_abs ? " absolute-motion" : "",
842 has_rel ? " relative-motion": "",
843 has_button ? " button" : "");
846 device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
848 "input device '%s', %s is a keyboard\n",
849 device->devname, device->devnode);
851 if (has_touch && !has_button) {
852 device->seat_caps |= EVDEV_DEVICE_TOUCH;
854 "input device '%s', %s is a touch device\n",
855 device->devname, device->devnode);
861 struct evdev_device *
862 evdev_device_create(struct libinput_seat *seat,
866 struct libinput *libinput = seat->libinput;
867 struct evdev_device *device;
870 int unhandled_device = 0;
872 /* Use non-blocking mode so that we can loop on read on
873 * evdev_device_data() until all events on the fd are
874 * read. mtdev_get() also expects this. */
875 fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
878 "opening input device '%s' failed (%s).\n",
879 devnode, strerror(-fd));
883 device = zalloc(sizeof *device);
887 libinput_device_init(&device->base, seat);
888 libinput_seat_ref(seat);
890 rc = libevdev_new_from_fd(fd, &device->evdev);
894 libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
896 device->seat_caps = 0;
898 device->mtdev = NULL;
899 device->devnode = strdup(devnode);
900 device->sysname = strdup(sysname);
903 device->abs.seat_slot = -1;
904 device->dispatch = NULL;
906 device->pending_event = EVDEV_NONE;
907 device->devname = libevdev_get_name(device->evdev);
909 if (evdev_configure_device(device) == -1)
912 if (device->seat_caps == 0) {
913 unhandled_device = 1;
917 /* If the dispatch was not set up use the fallback. */
918 if (device->dispatch == NULL)
919 device->dispatch = fallback_dispatch_create();
920 if (device->dispatch == NULL)
924 libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
928 list_insert(seat->devices_list.prev, &device->base.link);
929 notify_added_device(&device->base);
935 close_restricted(libinput, fd);
936 evdev_device_destroy(device);
938 return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL;
942 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size)
944 memset(keys, 0, size);
949 evdev_device_get_output(struct evdev_device *device)
951 return device->output_name;
955 evdev_device_get_sysname(struct evdev_device *device)
957 return device->sysname;
961 evdev_device_get_name(struct evdev_device *device)
963 return device->devname;
967 evdev_device_get_id_product(struct evdev_device *device)
969 return libevdev_get_id_product(device->evdev);
973 evdev_device_get_id_vendor(struct evdev_device *device)
975 return libevdev_get_id_vendor(device->evdev);
979 evdev_device_calibrate(struct evdev_device *device, float calibration[6])
981 device->abs.apply_calibration = 1;
982 memcpy(device->abs.calibration, calibration, sizeof device->abs.calibration);
986 evdev_device_has_capability(struct evdev_device *device,
987 enum libinput_device_capability capability)
989 switch (capability) {
990 case LIBINPUT_DEVICE_CAP_POINTER:
991 return !!(device->seat_caps & EVDEV_DEVICE_POINTER);
992 case LIBINPUT_DEVICE_CAP_KEYBOARD:
993 return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD);
994 case LIBINPUT_DEVICE_CAP_TOUCH:
995 return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
1002 evdev_device_get_size(struct evdev_device *device,
1006 const struct input_absinfo *x, *y;
1008 x = libevdev_get_abs_info(device->evdev, ABS_X);
1009 y = libevdev_get_abs_info(device->evdev, ABS_Y);
1011 if (!x || !y || device->abs.fake_resolution ||
1012 !x->resolution || !y->resolution)
1015 *width = evdev_convert_to_mm(x, x->maximum);
1016 *height = evdev_convert_to_mm(y, y->maximum);
1022 release_pressed_keys(struct evdev_device *device)
1024 struct libinput *libinput = device->base.seat->libinput;
1029 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
1030 log_bug_libinput(libinput, "clock_gettime: %s\n", strerror(errno));
1034 time = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
1036 for (code = 0; code < KEY_CNT; code++) {
1037 if (get_key_down_count(device, code) > 0) {
1038 switch (get_key_type(code)) {
1039 case EVDEV_KEY_TYPE_NONE:
1041 case EVDEV_KEY_TYPE_KEY:
1042 keyboard_notify_key(
1046 LIBINPUT_KEY_STATE_RELEASED);
1048 case EVDEV_KEY_TYPE_BUTTON:
1049 pointer_notify_button(
1053 LIBINPUT_BUTTON_STATE_RELEASED);
1061 evdev_device_remove(struct evdev_device *device)
1064 libinput_remove_source(device->base.seat->libinput,
1067 release_pressed_keys(device);
1070 mtdev_close_delete(device->mtdev);
1071 close_restricted(device->base.seat->libinput, device->fd);
1073 list_remove(&device->base.link);
1075 notify_removed_device(&device->base);
1076 libinput_device_unref(&device->base);
1080 evdev_device_destroy(struct evdev_device *device)
1082 struct evdev_dispatch *dispatch;
1084 dispatch = device->dispatch;
1086 dispatch->interface->destroy(dispatch);
1088 filter_destroy(device->pointer.filter);
1089 libinput_seat_unref(device->base.seat);
1090 libevdev_free(device->evdev);
1091 free(device->mt.slots);
1092 free(device->devnode);
1093 free(device->sysname);