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.
30 #include "linux/input.h"
33 #include <mtdev-plumbing.h>
41 #include "libinput-private.h"
43 #define DEFAULT_AXIS_STEP_DISTANCE 10
44 #define DEFAULT_MIDDLE_BUTTON_SCROLL_TIMEOUT 200
45 /* The HW DPI rate we normalize to before calculating pointer acceleration */
46 #define DEFAULT_MOUSE_DPI 400
51 EVDEV_KEY_TYPE_BUTTON,
55 hw_set_key_down(struct evdev_device *device, int code, int pressed)
57 long_set_bit_state(device->hw_key_mask, code, pressed);
61 hw_is_key_down(struct evdev_device *device, int code)
63 return long_bit_is_set(device->hw_key_mask, code);
67 get_key_down_count(struct evdev_device *device, int code)
69 return device->key_count[code];
73 update_key_down_count(struct evdev_device *device, int code, int pressed)
76 assert(code >= 0 && code < KEY_CNT);
79 key_count = ++device->key_count[code];
81 assert(device->key_count[code] > 0);
82 key_count = --device->key_count[code];
86 log_bug_libinput(device->base.seat->libinput,
87 "Key count for %s reached abnormal values\n",
88 libevdev_event_code_get_name(EV_KEY, code));
95 evdev_keyboard_notify_key(struct evdev_device *device,
98 enum libinput_key_state state)
102 down_count = update_key_down_count(device, key, state);
104 if ((state == LIBINPUT_KEY_STATE_PRESSED && down_count == 1) ||
105 (state == LIBINPUT_KEY_STATE_RELEASED && down_count == 0))
106 keyboard_notify_key(&device->base, time, key, state);
110 evdev_pointer_notify_button(struct evdev_device *device,
113 enum libinput_button_state state)
117 down_count = update_key_down_count(device, button, state);
119 if ((state == LIBINPUT_BUTTON_STATE_PRESSED && down_count == 1) ||
120 (state == LIBINPUT_BUTTON_STATE_RELEASED && down_count == 0)) {
121 pointer_notify_button(&device->base, time, button, state);
123 if (state == LIBINPUT_BUTTON_STATE_RELEASED &&
124 device->buttons.change_to_left_handed)
125 device->buttons.change_to_left_handed(device);
131 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds)
133 static const struct {
134 enum libinput_led weston;
137 { LIBINPUT_LED_NUM_LOCK, LED_NUML },
138 { LIBINPUT_LED_CAPS_LOCK, LED_CAPSL },
139 { LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL },
141 struct input_event ev[ARRAY_LENGTH(map) + 1];
144 if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
147 memset(ev, 0, sizeof(ev));
148 for (i = 0; i < ARRAY_LENGTH(map); i++) {
150 ev[i].code = map[i].evdev;
151 ev[i].value = !!(leds & map[i].weston);
154 ev[i].code = SYN_REPORT;
156 i = write(device->fd, ev, sizeof ev);
157 (void)i; /* no, we really don't care about the return value */
161 transform_absolute(struct evdev_device *device, int32_t *x, int32_t *y)
163 if (!device->abs.apply_calibration)
166 matrix_mult_vec(&device->abs.calibration, x, y);
170 scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
172 return (val - absinfo->minimum) * to_range /
173 (absinfo->maximum - absinfo->minimum + 1);
177 evdev_device_transform_x(struct evdev_device *device,
181 return scale_axis(device->abs.absinfo_x, x, width);
185 evdev_device_transform_y(struct evdev_device *device,
189 return scale_axis(device->abs.absinfo_y, y, height);
193 evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
195 struct libinput *libinput = device->base.seat->libinput;
196 struct motion_params motion;
201 struct libinput_device *base = &device->base;
202 struct libinput_seat *seat = base->seat;
204 slot = device->mt.slot;
206 switch (device->pending_event) {
209 case EVDEV_RELATIVE_MOTION:
210 motion.dx = device->rel.dx / ((double)device->dpi / DEFAULT_MOUSE_DPI);
211 motion.dy = device->rel.dy / ((double)device->dpi / DEFAULT_MOUSE_DPI);
215 /* Use unaccelerated deltas for pointing stick scroll */
216 if (device->scroll.has_middle_button_scroll &&
217 hw_is_key_down(device, BTN_MIDDLE)) {
218 if (device->scroll.middle_button_scroll_active)
219 evdev_post_scroll(device, time,
220 motion.dx, motion.dy);
224 /* Apply pointer acceleration. */
225 filter_dispatch(device->pointer.filter, &motion, device, time);
227 if (motion.dx == 0.0 && motion.dy == 0.0)
230 pointer_notify_motion(base, time, motion.dx, motion.dy);
232 case EVDEV_ABSOLUTE_MT_DOWN:
233 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
236 if (device->mt.slots[slot].seat_slot != -1) {
237 log_bug_kernel(libinput,
238 "%s: Driver sent multiple touch down for the "
239 "same slot", device->devnode);
243 seat_slot = ffs(~seat->slot_map) - 1;
244 device->mt.slots[slot].seat_slot = seat_slot;
249 seat->slot_map |= 1 << seat_slot;
250 x = device->mt.slots[slot].x;
251 y = device->mt.slots[slot].y;
252 transform_absolute(device, &x, &y);
254 touch_notify_touch_down(base, time, slot, seat_slot, x, y);
256 case EVDEV_ABSOLUTE_MT_MOTION:
257 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
260 seat_slot = device->mt.slots[slot].seat_slot;
261 x = device->mt.slots[slot].x;
262 y = device->mt.slots[slot].y;
267 transform_absolute(device, &x, &y);
268 touch_notify_touch_motion(base, time, slot, seat_slot, x, y);
270 case EVDEV_ABSOLUTE_MT_UP:
271 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
274 seat_slot = device->mt.slots[slot].seat_slot;
275 device->mt.slots[slot].seat_slot = -1;
280 seat->slot_map &= ~(1 << seat_slot);
282 touch_notify_touch_up(base, time, slot, seat_slot);
284 case EVDEV_ABSOLUTE_TOUCH_DOWN:
285 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
288 if (device->abs.seat_slot != -1) {
289 log_bug_kernel(libinput,
290 "%s: Driver sent multiple touch down for the "
291 "same slot", device->devnode);
295 seat_slot = ffs(~seat->slot_map) - 1;
296 device->abs.seat_slot = seat_slot;
301 seat->slot_map |= 1 << seat_slot;
305 transform_absolute(device, &cx, &cy);
307 touch_notify_touch_down(base, time, -1, seat_slot, cx, cy);
309 case EVDEV_ABSOLUTE_MOTION:
312 transform_absolute(device, &cx, &cy);
316 if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
317 seat_slot = device->abs.seat_slot;
322 touch_notify_touch_motion(base, time, -1, seat_slot, x, y);
323 } else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
324 pointer_notify_motion_absolute(base, time, x, y);
327 case EVDEV_ABSOLUTE_TOUCH_UP:
328 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
331 seat_slot = device->abs.seat_slot;
332 device->abs.seat_slot = -1;
337 seat->slot_map &= ~(1 << seat_slot);
339 touch_notify_touch_up(base, time, -1, seat_slot);
342 assert(0 && "Unknown pending event type");
346 device->pending_event = EVDEV_NONE;
349 static enum evdev_key_type
350 get_key_type(uint16_t code)
352 if (code == BTN_TOUCH)
353 return EVDEV_KEY_TYPE_NONE;
355 if (code >= KEY_ESC && code <= KEY_MICMUTE)
356 return EVDEV_KEY_TYPE_KEY;
357 if (code >= BTN_MISC && code <= BTN_GEAR_UP)
358 return EVDEV_KEY_TYPE_BUTTON;
359 if (code >= KEY_OK && code <= KEY_LIGHTS_TOGGLE)
360 return EVDEV_KEY_TYPE_KEY;
361 if (code >= BTN_DPAD_UP && code <= BTN_TRIGGER_HAPPY40)
362 return EVDEV_KEY_TYPE_BUTTON;
363 return EVDEV_KEY_TYPE_NONE;
367 evdev_middle_button_scroll_timeout(uint64_t time, void *data)
369 struct evdev_device *device = data;
371 device->scroll.middle_button_scroll_active = true;
375 evdev_middle_button_scroll_button(struct evdev_device *device,
376 uint64_t time, int is_press)
379 libinput_timer_set(&device->scroll.timer,
380 time + DEFAULT_MIDDLE_BUTTON_SCROLL_TIMEOUT);
382 libinput_timer_cancel(&device->scroll.timer);
383 if (device->scroll.middle_button_scroll_active) {
384 evdev_stop_scroll(device, time);
385 device->scroll.middle_button_scroll_active = false;
387 /* If the button is released quickly enough emit the
388 * button press/release events. */
389 evdev_pointer_notify_button(device, time, BTN_MIDDLE,
390 LIBINPUT_BUTTON_STATE_PRESSED);
391 evdev_pointer_notify_button(device, time, BTN_MIDDLE,
392 LIBINPUT_BUTTON_STATE_RELEASED);
398 evdev_process_touch_button(struct evdev_device *device,
399 uint64_t time, int value)
401 if (device->pending_event != EVDEV_NONE &&
402 device->pending_event != EVDEV_ABSOLUTE_MOTION)
403 evdev_flush_pending_event(device, time);
405 device->pending_event = (value ?
406 EVDEV_ABSOLUTE_TOUCH_DOWN :
407 EVDEV_ABSOLUTE_TOUCH_UP);
411 evdev_process_key(struct evdev_device *device,
412 struct input_event *e, uint64_t time)
414 enum evdev_key_type type;
416 /* ignore kernel key repeat */
420 if (e->code == BTN_TOUCH) {
422 evdev_process_touch_button(device, time, e->value);
426 evdev_flush_pending_event(device, time);
428 type = get_key_type(e->code);
430 /* Ignore key release events from the kernel for keys that libinput
431 * never got a pressed event for. */
434 case EVDEV_KEY_TYPE_NONE:
436 case EVDEV_KEY_TYPE_KEY:
437 case EVDEV_KEY_TYPE_BUTTON:
438 if (!hw_is_key_down(device, e->code))
443 hw_set_key_down(device, e->code, e->value);
446 case EVDEV_KEY_TYPE_NONE:
448 case EVDEV_KEY_TYPE_KEY:
449 evdev_keyboard_notify_key(
453 e->value ? LIBINPUT_KEY_STATE_PRESSED :
454 LIBINPUT_KEY_STATE_RELEASED);
456 case EVDEV_KEY_TYPE_BUTTON:
457 if (device->scroll.has_middle_button_scroll &&
458 e->code == BTN_MIDDLE) {
459 evdev_middle_button_scroll_button(device, time,
463 evdev_pointer_notify_button(
466 evdev_to_left_handed(device, e->code),
467 e->value ? LIBINPUT_BUTTON_STATE_PRESSED :
468 LIBINPUT_BUTTON_STATE_RELEASED);
474 evdev_process_touch(struct evdev_device *device,
475 struct input_event *e,
480 evdev_flush_pending_event(device, time);
481 device->mt.slot = e->value;
483 case ABS_MT_TRACKING_ID:
484 if (device->pending_event != EVDEV_NONE &&
485 device->pending_event != EVDEV_ABSOLUTE_MT_MOTION)
486 evdev_flush_pending_event(device, time);
488 device->pending_event = EVDEV_ABSOLUTE_MT_DOWN;
490 device->pending_event = EVDEV_ABSOLUTE_MT_UP;
492 case ABS_MT_POSITION_X:
493 device->mt.slots[device->mt.slot].x = e->value;
494 if (device->pending_event == EVDEV_NONE)
495 device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
497 case ABS_MT_POSITION_Y:
498 device->mt.slots[device->mt.slot].y = e->value;
499 if (device->pending_event == EVDEV_NONE)
500 device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
506 evdev_process_absolute_motion(struct evdev_device *device,
507 struct input_event *e)
511 device->abs.x = e->value;
512 if (device->pending_event == EVDEV_NONE)
513 device->pending_event = EVDEV_ABSOLUTE_MOTION;
516 device->abs.y = e->value;
517 if (device->pending_event == EVDEV_NONE)
518 device->pending_event = EVDEV_ABSOLUTE_MOTION;
524 evdev_process_relative(struct evdev_device *device,
525 struct input_event *e, uint64_t time)
527 struct libinput_device *base = &device->base;
531 if (device->pending_event != EVDEV_RELATIVE_MOTION)
532 evdev_flush_pending_event(device, time);
533 device->rel.dx += e->value;
534 device->pending_event = EVDEV_RELATIVE_MOTION;
537 if (device->pending_event != EVDEV_RELATIVE_MOTION)
538 evdev_flush_pending_event(device, time);
539 device->rel.dy += e->value;
540 device->pending_event = EVDEV_RELATIVE_MOTION;
543 evdev_flush_pending_event(device, time);
547 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
548 -1 * e->value * DEFAULT_AXIS_STEP_DISTANCE);
551 evdev_flush_pending_event(device, time);
555 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
556 e->value * DEFAULT_AXIS_STEP_DISTANCE);
562 evdev_process_absolute(struct evdev_device *device,
563 struct input_event *e,
567 evdev_process_touch(device, e, time);
569 evdev_process_absolute_motion(device, e);
574 evdev_need_touch_frame(struct evdev_device *device)
576 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
579 switch (device->pending_event) {
581 case EVDEV_RELATIVE_MOTION:
583 case EVDEV_ABSOLUTE_MT_DOWN:
584 case EVDEV_ABSOLUTE_MT_MOTION:
585 case EVDEV_ABSOLUTE_MT_UP:
586 case EVDEV_ABSOLUTE_TOUCH_DOWN:
587 case EVDEV_ABSOLUTE_TOUCH_UP:
588 case EVDEV_ABSOLUTE_MOTION:
596 evdev_tag_external_mouse(struct evdev_device *device,
597 struct udev_device *udev_device)
601 bustype = libevdev_get_id_bustype(device->evdev);
602 if (bustype == BUS_USB || bustype == BUS_BLUETOOTH) {
603 if (device->seat_caps & EVDEV_DEVICE_POINTER)
604 device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
609 evdev_tag_trackpoint(struct evdev_device *device,
610 struct udev_device *udev_device)
612 if (libevdev_has_property(device->evdev, INPUT_PROP_POINTING_STICK))
613 device->tags |= EVDEV_TAG_TRACKPOINT;
617 fallback_process(struct evdev_dispatch *dispatch,
618 struct evdev_device *device,
619 struct input_event *event,
622 bool need_frame = false;
624 switch (event->type) {
626 evdev_process_relative(device, event, time);
629 evdev_process_absolute(device, event, time);
632 evdev_process_key(device, event, time);
635 need_frame = evdev_need_touch_frame(device);
636 evdev_flush_pending_event(device, time);
638 touch_notify_frame(&device->base, time);
644 fallback_destroy(struct evdev_dispatch *dispatch)
650 fallback_tag_device(struct evdev_device *device,
651 struct udev_device *udev_device)
653 evdev_tag_external_mouse(device, udev_device);
654 evdev_tag_trackpoint(device, udev_device);
658 evdev_calibration_has_matrix(struct libinput_device *libinput_device)
660 struct evdev_device *device = (struct evdev_device*)libinput_device;
662 return device->abs.absinfo_x && device->abs.absinfo_y;
665 static enum libinput_config_status
666 evdev_calibration_set_matrix(struct libinput_device *libinput_device,
667 const float matrix[6])
669 struct evdev_device *device = (struct evdev_device*)libinput_device;
671 evdev_device_calibrate(device, matrix);
673 return LIBINPUT_CONFIG_STATUS_SUCCESS;
677 evdev_calibration_get_matrix(struct libinput_device *libinput_device,
680 struct evdev_device *device = (struct evdev_device*)libinput_device;
682 matrix_to_farray6(&device->abs.usermatrix, matrix);
684 return !matrix_is_identity(&device->abs.usermatrix);
688 evdev_calibration_get_default_matrix(struct libinput_device *libinput_device,
691 struct evdev_device *device = (struct evdev_device*)libinput_device;
693 matrix_to_farray6(&device->abs.default_calibration, matrix);
695 return !matrix_is_identity(&device->abs.default_calibration);
698 struct evdev_dispatch_interface fallback_interface = {
701 NULL, /* device_added */
702 NULL, /* device_removed */
703 NULL, /* device_suspended */
704 NULL, /* device_resumed */
709 evdev_sendevents_get_modes(struct libinput_device *device)
711 return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
714 static enum libinput_config_status
715 evdev_sendevents_set_mode(struct libinput_device *device,
716 enum libinput_config_send_events_mode mode)
718 struct evdev_device *evdev = (struct evdev_device*)device;
719 struct evdev_dispatch *dispatch = evdev->dispatch;
721 if (mode == dispatch->sendevents.current_mode)
722 return LIBINPUT_CONFIG_STATUS_SUCCESS;
725 case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
726 evdev_device_resume(evdev);
728 case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
729 evdev_device_suspend(evdev);
731 default: /* no support for combined modes yet */
732 return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
735 dispatch->sendevents.current_mode = mode;
737 return LIBINPUT_CONFIG_STATUS_SUCCESS;
740 static enum libinput_config_send_events_mode
741 evdev_sendevents_get_mode(struct libinput_device *device)
743 struct evdev_device *evdev = (struct evdev_device*)device;
744 struct evdev_dispatch *dispatch = evdev->dispatch;
746 return dispatch->sendevents.current_mode;
749 static enum libinput_config_send_events_mode
750 evdev_sendevents_get_default_mode(struct libinput_device *device)
752 return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
756 evdev_left_handed_has(struct libinput_device *device)
758 /* This is only hooked up when we have left-handed configuration, so we
759 * can hardcode 1 here */
764 evdev_change_to_left_handed(struct evdev_device *device)
768 if (device->buttons.want_left_handed == device->buttons.left_handed)
771 for (button = BTN_LEFT; button < BTN_JOYSTICK; button++) {
772 if (libevdev_has_event_code(device->evdev, EV_KEY, button) &&
773 hw_is_key_down(device, button))
777 device->buttons.left_handed = device->buttons.want_left_handed;
780 static enum libinput_config_status
781 evdev_left_handed_set(struct libinput_device *device, int left_handed)
783 struct evdev_device *evdev_device = (struct evdev_device *)device;
785 evdev_device->buttons.want_left_handed = left_handed ? true : false;
787 evdev_device->buttons.change_to_left_handed(evdev_device);
789 return LIBINPUT_CONFIG_STATUS_SUCCESS;
793 evdev_left_handed_get(struct libinput_device *device)
795 struct evdev_device *evdev_device = (struct evdev_device *)device;
797 /* return the wanted configuration, even if it hasn't taken
799 return evdev_device->buttons.want_left_handed;
803 evdev_left_handed_get_default(struct libinput_device *device)
809 evdev_init_left_handed(struct evdev_device *device,
810 void (*change_to_left_handed)(struct evdev_device *))
812 device->buttons.config_left_handed.has = evdev_left_handed_has;
813 device->buttons.config_left_handed.set = evdev_left_handed_set;
814 device->buttons.config_left_handed.get = evdev_left_handed_get;
815 device->buttons.config_left_handed.get_default = evdev_left_handed_get_default;
816 device->base.config.left_handed = &device->buttons.config_left_handed;
817 device->buttons.left_handed = false;
818 device->buttons.want_left_handed = false;
819 device->buttons.change_to_left_handed = change_to_left_handed;
824 static struct evdev_dispatch *
825 fallback_dispatch_create(struct libinput_device *device)
827 struct evdev_dispatch *dispatch = zalloc(sizeof *dispatch);
828 struct evdev_device *evdev_device = (struct evdev_device *)device;
830 if (dispatch == NULL)
833 dispatch->interface = &fallback_interface;
835 if (evdev_device->buttons.want_left_handed &&
836 evdev_init_left_handed(evdev_device,
837 evdev_change_to_left_handed) == -1) {
842 device->config.calibration = &dispatch->calibration;
844 dispatch->calibration.has_matrix = evdev_calibration_has_matrix;
845 dispatch->calibration.set_matrix = evdev_calibration_set_matrix;
846 dispatch->calibration.get_matrix = evdev_calibration_get_matrix;
847 dispatch->calibration.get_default_matrix = evdev_calibration_get_default_matrix;
849 device->config.sendevents = &dispatch->sendevents.config;
851 dispatch->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
852 dispatch->sendevents.config.get_modes = evdev_sendevents_get_modes;
853 dispatch->sendevents.config.set_mode = evdev_sendevents_set_mode;
854 dispatch->sendevents.config.get_mode = evdev_sendevents_get_mode;
855 dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode;
861 evdev_process_event(struct evdev_device *device, struct input_event *e)
863 struct evdev_dispatch *dispatch = device->dispatch;
864 uint64_t time = e->time.tv_sec * 1000ULL + e->time.tv_usec / 1000;
866 dispatch->interface->process(dispatch, device, e, time);
870 evdev_device_dispatch_one(struct evdev_device *device,
871 struct input_event *ev)
873 if (!device->mtdev) {
874 evdev_process_event(device, ev);
876 mtdev_put_event(device->mtdev, ev);
877 if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) {
878 while (!mtdev_empty(device->mtdev)) {
879 struct input_event e;
880 mtdev_get_event(device->mtdev, &e);
881 evdev_process_event(device, &e);
888 evdev_sync_device(struct evdev_device *device)
890 struct input_event ev;
894 rc = libevdev_next_event(device->evdev,
895 LIBEVDEV_READ_FLAG_SYNC, &ev);
898 evdev_device_dispatch_one(device, &ev);
899 } while (rc == LIBEVDEV_READ_STATUS_SYNC);
901 return rc == -EAGAIN ? 0 : rc;
905 evdev_device_dispatch(void *data)
907 struct evdev_device *device = data;
908 struct libinput *libinput = device->base.seat->libinput;
909 struct input_event ev;
912 /* If the compositor is repainting, this function is called only once
913 * per frame and we have to process all the events available on the
914 * fd, otherwise there will be input lag. */
916 rc = libevdev_next_event(device->evdev,
917 LIBEVDEV_READ_FLAG_NORMAL, &ev);
918 if (rc == LIBEVDEV_READ_STATUS_SYNC) {
919 switch (ratelimit_test(&device->syn_drop_limit)) {
921 log_info(libinput, "SYN_DROPPED event from "
922 "\"%s\" - some input events have "
923 "been lost.\n", device->devname);
925 case RATELIMIT_THRESHOLD:
926 log_info(libinput, "SYN_DROPPED flood "
930 case RATELIMIT_EXCEEDED:
934 /* send one more sync event so we handle all
935 currently pending events before we sync up
936 to the current state */
937 ev.code = SYN_REPORT;
938 evdev_device_dispatch_one(device, &ev);
940 rc = evdev_sync_device(device);
942 rc = LIBEVDEV_READ_STATUS_SUCCESS;
943 } else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
944 evdev_device_dispatch_one(device, &ev);
946 } while (rc == LIBEVDEV_READ_STATUS_SUCCESS);
948 if (rc != -EAGAIN && rc != -EINTR) {
949 libinput_remove_source(libinput, device->source);
950 device->source = NULL;
955 evdev_accel_config_available(struct libinput_device *device)
957 /* this function is only called if we set up ptraccel, so we can
958 reply with a resounding "Yes" */
962 static enum libinput_config_status
963 evdev_accel_config_set_speed(struct libinput_device *device, double speed)
965 struct evdev_device *dev = (struct evdev_device *)device;
967 if (!filter_set_speed(dev->pointer.filter, speed))
968 return LIBINPUT_CONFIG_STATUS_INVALID;
970 return LIBINPUT_CONFIG_STATUS_SUCCESS;
974 evdev_accel_config_get_speed(struct libinput_device *device)
976 struct evdev_device *dev = (struct evdev_device *)device;
978 return filter_get_speed(dev->pointer.filter);
982 evdev_accel_config_get_default_speed(struct libinput_device *device)
988 evdev_device_init_pointer_acceleration(struct evdev_device *device)
990 device->pointer.filter =
991 create_pointer_accelerator_filter(
992 pointer_accel_profile_linear);
993 if (!device->pointer.filter)
996 device->pointer.config.available = evdev_accel_config_available;
997 device->pointer.config.set_speed = evdev_accel_config_set_speed;
998 device->pointer.config.get_speed = evdev_accel_config_get_speed;
999 device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed;
1000 device->base.config.accel = &device->pointer.config;
1007 evdev_need_mtdev(struct evdev_device *device)
1009 struct libevdev *evdev = device->evdev;
1011 return (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
1012 libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y) &&
1013 !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT));
1017 evdev_tag_device(struct evdev_device *device)
1020 struct udev_device *udev_device = NULL;
1026 udev_device = udev_device_new_from_syspath(udev, device->syspath);
1028 if (device->dispatch->interface->tag_device)
1029 device->dispatch->interface->tag_device(device, udev_device);
1030 udev_device_unref(udev_device);
1036 evdev_fix_abs_resolution(struct libevdev *evdev,
1038 const struct input_absinfo *absinfo)
1040 struct input_absinfo fixed;
1042 if (absinfo->resolution == 0) {
1044 fixed.resolution = 1;
1045 /* libevdev_set_abs_info() changes the absinfo we already
1046 have a pointer to, no need to fetch it again */
1047 libevdev_set_abs_info(evdev, code, &fixed);
1055 evdev_configure_device(struct evdev_device *device)
1057 struct libinput *libinput = device->base.seat->libinput;
1058 struct libevdev *evdev = device->evdev;
1059 const struct input_absinfo *absinfo;
1060 int has_abs, has_rel, has_mt;
1061 int has_button, has_keyboard, has_touch;
1062 struct mt_slot *slots;
1075 if (libevdev_has_event_type(evdev, EV_ABS)) {
1077 if ((absinfo = libevdev_get_abs_info(evdev, ABS_X))) {
1078 if (evdev_fix_abs_resolution(evdev,
1081 device->abs.fake_resolution = 1;
1082 device->abs.absinfo_x = absinfo;
1085 if ((absinfo = libevdev_get_abs_info(evdev, ABS_Y))) {
1086 if (evdev_fix_abs_resolution(evdev,
1089 device->abs.fake_resolution = 1;
1090 device->abs.absinfo_y = absinfo;
1094 /* Fake MT devices have the ABS_MT_SLOT bit set because of
1095 the limited ABS_* range - they aren't MT devices, they
1096 just have too many ABS_ axes */
1097 if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT) &&
1098 libevdev_get_num_slots(evdev) == -1) {
1101 } else if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
1102 libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) {
1103 absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
1104 if (evdev_fix_abs_resolution(evdev,
1107 device->abs.fake_resolution = 1;
1108 device->abs.absinfo_x = absinfo;
1110 absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
1111 if (evdev_fix_abs_resolution(evdev,
1114 device->abs.fake_resolution = 1;
1115 device->abs.absinfo_y = absinfo;
1120 /* We only handle the slotted Protocol B in libinput.
1121 Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
1122 require mtdev for conversion. */
1123 if (evdev_need_mtdev(device)) {
1124 device->mtdev = mtdev_new_open(device->fd);
1128 num_slots = device->mtdev->caps.slot.maximum;
1129 if (device->mtdev->caps.slot.minimum < 0 ||
1132 active_slot = device->mtdev->caps.slot.value;
1134 num_slots = libevdev_get_num_slots(device->evdev);
1135 active_slot = libevdev_get_current_slot(evdev);
1138 slots = calloc(num_slots, sizeof(struct mt_slot));
1142 for (slot = 0; slot < num_slots; ++slot) {
1143 slots[slot].seat_slot = -1;
1147 device->mt.slots = slots;
1148 device->mt.slots_len = num_slots;
1149 device->mt.slot = active_slot;
1153 if (libevdev_has_property(evdev, INPUT_PROP_POINTING_STICK)) {
1154 libinput_timer_init(&device->scroll.timer,
1155 device->base.seat->libinput,
1156 evdev_middle_button_scroll_timeout,
1158 device->scroll.has_middle_button_scroll = true;
1161 if (libevdev_has_event_code(evdev, EV_REL, REL_X) ||
1162 libevdev_has_event_code(evdev, EV_REL, REL_Y))
1165 if (libevdev_has_event_type(evdev, EV_KEY)) {
1166 if (!libevdev_has_property(evdev, INPUT_PROP_DIRECT) &&
1167 libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER) &&
1168 !libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
1169 (has_abs || has_mt)) {
1170 device->dispatch = evdev_mt_touchpad_create(device);
1172 "input device '%s', %s is a touchpad\n",
1173 device->devname, device->devnode);
1174 return device->dispatch == NULL ? -1 : 0;
1177 for (i = 0; i < KEY_MAX; i++) {
1178 if (libevdev_has_event_code(evdev, EV_KEY, i)) {
1179 switch (get_key_type(i)) {
1180 case EVDEV_KEY_TYPE_NONE:
1182 case EVDEV_KEY_TYPE_KEY:
1185 case EVDEV_KEY_TYPE_BUTTON:
1192 if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH))
1195 if (libevdev_has_event_type(evdev, EV_LED))
1198 if ((has_abs || has_rel) && has_button) {
1199 if (evdev_device_init_pointer_acceleration(device) == -1)
1202 device->seat_caps |= EVDEV_DEVICE_POINTER;
1205 "input device '%s', %s is a pointer caps =%s%s%s\n",
1206 device->devname, device->devnode,
1207 has_abs ? " absolute-motion" : "",
1208 has_rel ? " relative-motion": "",
1209 has_button ? " button" : "");
1211 /* want left-handed config option */
1212 device->buttons.want_left_handed = true;
1215 device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
1217 "input device '%s', %s is a keyboard\n",
1218 device->devname, device->devnode);
1220 if (has_touch && !has_button) {
1221 device->seat_caps |= EVDEV_DEVICE_TOUCH;
1223 "input device '%s', %s is a touch device\n",
1224 device->devname, device->devnode);
1231 evdev_notify_added_device(struct evdev_device *device)
1233 struct libinput_device *dev;
1235 list_for_each(dev, &device->base.seat->devices_list, link) {
1236 struct evdev_device *d = (struct evdev_device*)dev;
1237 if (dev == &device->base)
1240 /* Notify existing device d about addition of device device */
1241 if (d->dispatch->interface->device_added)
1242 d->dispatch->interface->device_added(d, device);
1244 /* Notify new device device about existing device d */
1245 if (device->dispatch->interface->device_added)
1246 device->dispatch->interface->device_added(device, d);
1248 /* Notify new device device if existing device d is suspended */
1249 if (d->suspended && device->dispatch->interface->device_suspended)
1250 device->dispatch->interface->device_suspended(device, d);
1253 notify_added_device(&device->base);
1256 struct evdev_device *
1257 evdev_device_create(struct libinput_seat *seat,
1258 const char *devnode,
1259 const char *sysname,
1260 const char *syspath)
1262 struct libinput *libinput = seat->libinput;
1263 struct evdev_device *device;
1266 int unhandled_device = 0;
1268 /* Use non-blocking mode so that we can loop on read on
1269 * evdev_device_data() until all events on the fd are
1270 * read. mtdev_get() also expects this. */
1271 fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
1274 "opening input device '%s' failed (%s).\n",
1275 devnode, strerror(-fd));
1279 device = zalloc(sizeof *device);
1283 libinput_device_init(&device->base, seat);
1284 libinput_seat_ref(seat);
1286 rc = libevdev_new_from_fd(fd, &device->evdev);
1290 libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
1292 device->seat_caps = 0;
1294 device->mtdev = NULL;
1295 device->devnode = strdup(devnode);
1296 device->sysname = strdup(sysname);
1297 device->syspath = strdup(syspath);
1300 device->abs.seat_slot = -1;
1301 device->dispatch = NULL;
1303 device->pending_event = EVDEV_NONE;
1304 device->devname = libevdev_get_name(device->evdev);
1305 device->scroll.threshold = 5.0; /* Default may be overridden */
1306 device->scroll.direction = 0;
1307 device->dpi = DEFAULT_MOUSE_DPI;
1308 /* at most 5 SYN_DROPPED log-messages per 30s */
1309 ratelimit_init(&device->syn_drop_limit, 30ULL * 1000, 5);
1311 matrix_init_identity(&device->abs.calibration);
1312 matrix_init_identity(&device->abs.usermatrix);
1313 matrix_init_identity(&device->abs.default_calibration);
1315 if (evdev_configure_device(device) == -1)
1318 if (device->seat_caps == 0) {
1319 unhandled_device = 1;
1323 /* If the dispatch was not set up use the fallback. */
1324 if (device->dispatch == NULL)
1325 device->dispatch = fallback_dispatch_create(&device->base);
1326 if (device->dispatch == NULL)
1330 libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
1331 if (!device->source)
1334 list_insert(seat->devices_list.prev, &device->base.link);
1336 evdev_tag_device(device);
1337 evdev_notify_added_device(device);
1343 close_restricted(libinput, fd);
1344 evdev_device_destroy(device);
1346 return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL;
1350 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size)
1352 memset(keys, 0, size);
1357 evdev_device_get_output(struct evdev_device *device)
1359 return device->output_name;
1363 evdev_device_get_sysname(struct evdev_device *device)
1365 return device->sysname;
1369 evdev_device_get_name(struct evdev_device *device)
1371 return device->devname;
1375 evdev_device_get_id_product(struct evdev_device *device)
1377 return libevdev_get_id_product(device->evdev);
1381 evdev_device_get_id_vendor(struct evdev_device *device)
1383 return libevdev_get_id_vendor(device->evdev);
1387 evdev_device_set_default_calibration(struct evdev_device *device,
1388 const float calibration[6])
1390 matrix_from_farray6(&device->abs.default_calibration, calibration);
1391 evdev_device_calibrate(device, calibration);
1395 evdev_device_calibrate(struct evdev_device *device,
1396 const float calibration[6])
1398 struct matrix scale,
1403 matrix_from_farray6(&transform, calibration);
1404 device->abs.apply_calibration = !matrix_is_identity(&transform);
1406 if (!device->abs.apply_calibration) {
1407 matrix_init_identity(&device->abs.calibration);
1411 sx = device->abs.absinfo_x->maximum - device->abs.absinfo_x->minimum + 1;
1412 sy = device->abs.absinfo_y->maximum - device->abs.absinfo_y->minimum + 1;
1414 /* The transformation matrix is in the form:
1418 * Where a, e are the scale components, a, b, d, e are the rotation
1419 * component (combined with scale) and c and f are the translation
1420 * component. The translation component in the input matrix must be
1421 * normalized to multiples of the device width and height,
1422 * respectively. e.g. c == 1 shifts one device-width to the right.
1424 * We pre-calculate a single matrix to apply to event coordinates:
1425 * M = Un-Normalize * Calibration * Normalize
1427 * Normalize: scales the device coordinates to [0,1]
1428 * Calibration: user-supplied matrix
1429 * Un-Normalize: scales back up to device coordinates
1430 * Matrix maths requires the normalize/un-normalize in reverse
1434 /* back up the user matrix so we can return it on request */
1435 matrix_from_farray6(&device->abs.usermatrix, calibration);
1438 matrix_init_translate(&translate,
1439 device->abs.absinfo_x->minimum,
1440 device->abs.absinfo_y->minimum);
1441 matrix_init_scale(&scale, sx, sy);
1442 matrix_mult(&scale, &translate, &scale);
1445 matrix_mult(&transform, &scale, &transform);
1448 matrix_init_translate(&translate,
1449 -device->abs.absinfo_x->minimum/sx,
1450 -device->abs.absinfo_y->minimum/sy);
1451 matrix_init_scale(&scale, 1.0/sx, 1.0/sy);
1452 matrix_mult(&scale, &translate, &scale);
1454 /* store final matrix in device */
1455 matrix_mult(&device->abs.calibration, &transform, &scale);
1459 evdev_device_has_capability(struct evdev_device *device,
1460 enum libinput_device_capability capability)
1462 switch (capability) {
1463 case LIBINPUT_DEVICE_CAP_POINTER:
1464 return !!(device->seat_caps & EVDEV_DEVICE_POINTER);
1465 case LIBINPUT_DEVICE_CAP_KEYBOARD:
1466 return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD);
1467 case LIBINPUT_DEVICE_CAP_TOUCH:
1468 return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
1475 evdev_device_get_size(struct evdev_device *device,
1479 const struct input_absinfo *x, *y;
1481 x = libevdev_get_abs_info(device->evdev, ABS_X);
1482 y = libevdev_get_abs_info(device->evdev, ABS_Y);
1484 if (!x || !y || device->abs.fake_resolution ||
1485 !x->resolution || !y->resolution)
1488 *width = evdev_convert_to_mm(x, x->maximum);
1489 *height = evdev_convert_to_mm(y, y->maximum);
1495 evdev_is_scrolling(const struct evdev_device *device,
1496 enum libinput_pointer_axis axis)
1498 assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
1499 axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
1501 return (device->scroll.direction & (1 << axis)) != 0;
1505 evdev_start_scrolling(struct evdev_device *device,
1506 enum libinput_pointer_axis axis)
1508 assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
1509 axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
1511 device->scroll.direction |= (1 << axis);
1515 evdev_post_scroll(struct evdev_device *device,
1520 double trigger_horiz, trigger_vert;
1522 if (!evdev_is_scrolling(device,
1523 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
1524 device->scroll.buildup_vertical += dy;
1525 if (!evdev_is_scrolling(device,
1526 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
1527 device->scroll.buildup_horizontal += dx;
1529 trigger_vert = device->scroll.buildup_vertical;
1530 trigger_horiz = device->scroll.buildup_horizontal;
1532 /* If we're not scrolling yet, use a distance trigger: moving
1533 past a certain distance starts scrolling */
1534 if (!evdev_is_scrolling(device,
1535 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) &&
1536 !evdev_is_scrolling(device,
1537 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
1538 if (fabs(trigger_vert) >= device->scroll.threshold)
1539 evdev_start_scrolling(device,
1540 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
1541 if (fabs(trigger_horiz) >= device->scroll.threshold)
1542 evdev_start_scrolling(device,
1543 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
1544 /* We're already scrolling in one direction. Require some
1545 trigger speed to start scrolling in the other direction */
1546 } else if (!evdev_is_scrolling(device,
1547 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
1548 if (fabs(dy) >= device->scroll.threshold)
1549 evdev_start_scrolling(device,
1550 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
1551 } else if (!evdev_is_scrolling(device,
1552 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
1553 if (fabs(dx) >= device->scroll.threshold)
1554 evdev_start_scrolling(device,
1555 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
1558 /* We use the trigger to enable, but the delta from this event for
1559 * the actual scroll movement. Otherwise we get a jump once
1560 * scrolling engages */
1562 evdev_is_scrolling(device,
1563 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
1564 pointer_notify_axis(&device->base,
1566 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
1571 evdev_is_scrolling(device,
1572 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
1573 pointer_notify_axis(&device->base,
1575 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
1581 evdev_stop_scroll(struct evdev_device *device, uint64_t time)
1583 /* terminate scrolling with a zero scroll event */
1584 if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
1585 pointer_notify_axis(&device->base,
1587 LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
1589 if (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
1590 pointer_notify_axis(&device->base,
1592 LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
1595 device->scroll.buildup_horizontal = 0;
1596 device->scroll.buildup_vertical = 0;
1597 device->scroll.direction = 0;
1601 release_pressed_keys(struct evdev_device *device)
1603 struct libinput *libinput = device->base.seat->libinput;
1607 if ((time = libinput_now(libinput)) == 0)
1610 for (code = 0; code < KEY_CNT; code++) {
1611 int count = get_key_down_count(device, code);
1614 log_bug_libinput(libinput,
1615 "Key %d is down %d times.\n",
1620 while (get_key_down_count(device, code) > 0) {
1621 switch (get_key_type(code)) {
1622 case EVDEV_KEY_TYPE_NONE:
1624 case EVDEV_KEY_TYPE_KEY:
1625 evdev_keyboard_notify_key(
1629 LIBINPUT_KEY_STATE_RELEASED);
1631 case EVDEV_KEY_TYPE_BUTTON:
1632 evdev_pointer_notify_button(
1635 evdev_to_left_handed(device, code),
1636 LIBINPUT_BUTTON_STATE_RELEASED);
1644 evdev_notify_suspended_device(struct evdev_device *device)
1646 struct libinput_device *it;
1648 if (device->suspended)
1651 list_for_each(it, &device->base.seat->devices_list, link) {
1652 struct evdev_device *d = (struct evdev_device*)it;
1653 if (it == &device->base)
1656 if (d->dispatch->interface->device_suspended)
1657 d->dispatch->interface->device_suspended(d, device);
1660 device->suspended = 1;
1664 evdev_notify_resumed_device(struct evdev_device *device)
1666 struct libinput_device *it;
1668 if (!device->suspended)
1671 list_for_each(it, &device->base.seat->devices_list, link) {
1672 struct evdev_device *d = (struct evdev_device*)it;
1673 if (it == &device->base)
1676 if (d->dispatch->interface->device_resumed)
1677 d->dispatch->interface->device_resumed(d, device);
1680 device->suspended = 0;
1684 evdev_device_suspend(struct evdev_device *device)
1686 evdev_notify_suspended_device(device);
1688 if (device->source) {
1689 libinput_remove_source(device->base.seat->libinput,
1691 device->source = NULL;
1694 release_pressed_keys(device);
1696 if (device->mtdev) {
1697 mtdev_close_delete(device->mtdev);
1698 device->mtdev = NULL;
1701 if (device->fd != -1) {
1702 close_restricted(device->base.seat->libinput, device->fd);
1710 evdev_device_compare_syspath(struct evdev_device *device, int fd)
1712 struct udev *udev = NULL;
1713 struct udev_device *udev_device = NULL;
1714 const char *syspath;
1722 if (fstat(fd, &st) < 0)
1725 udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
1729 syspath = udev_device_get_syspath(udev_device);
1730 rc = strcmp(syspath, device->syspath);
1733 udev_device_unref(udev_device);
1740 evdev_device_resume(struct evdev_device *device)
1742 struct libinput *libinput = device->base.seat->libinput;
1745 if (device->fd != -1)
1748 if (device->syspath == NULL)
1751 fd = open_restricted(libinput, device->devnode, O_RDWR | O_NONBLOCK);
1756 if (evdev_device_compare_syspath(device, fd)) {
1757 close_restricted(libinput, fd);
1763 if (evdev_need_mtdev(device)) {
1764 device->mtdev = mtdev_new_open(device->fd);
1770 libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
1771 if (!device->source) {
1772 mtdev_close_delete(device->mtdev);
1776 memset(device->hw_key_mask, 0, sizeof(device->hw_key_mask));
1778 evdev_notify_resumed_device(device);
1784 evdev_device_remove(struct evdev_device *device)
1786 struct libinput_device *dev;
1788 list_for_each(dev, &device->base.seat->devices_list, link) {
1789 struct evdev_device *d = (struct evdev_device*)dev;;
1790 if (dev == &device->base)
1793 if (d->dispatch->interface->device_removed)
1794 d->dispatch->interface->device_removed(d, device);
1797 evdev_device_suspend(device);
1799 /* A device may be removed while suspended. Free the syspath to
1800 * skip re-opening a different device with the same node */
1801 free(device->syspath);
1802 device->syspath = NULL;
1804 list_remove(&device->base.link);
1806 notify_removed_device(&device->base);
1807 libinput_device_unref(&device->base);
1811 evdev_device_destroy(struct evdev_device *device)
1813 struct evdev_dispatch *dispatch;
1815 dispatch = device->dispatch;
1817 dispatch->interface->destroy(dispatch);
1819 filter_destroy(device->pointer.filter);
1820 libinput_seat_unref(device->base.seat);
1821 libevdev_free(device->evdev);
1822 free(device->mt.slots);
1823 free(device->devnode);
1824 free(device->sysname);
1825 free(device->syspath);