2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2013 Jonas Ådahl
4 * Copyright © 2013-2017 Red Hat, Inc.
5 * Copyright © 2017 James Ye <jye836@gmail.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
29 #include <mtdev-plumbing.h>
31 #include "evdev-fallback.h"
32 #include "util-input-event.h"
35 fallback_keyboard_notify_key(struct fallback_dispatch *dispatch,
36 struct evdev_device *device,
39 enum libinput_key_state state)
43 down_count = evdev_update_key_down_count(device, key, state);
45 if ((state == LIBINPUT_KEY_STATE_PRESSED && down_count == 1) ||
46 (state == LIBINPUT_KEY_STATE_RELEASED && down_count == 0))
47 keyboard_notify_key(&device->base, time, key, state);
51 fallback_lid_notify_toggle(struct fallback_dispatch *dispatch,
52 struct evdev_device *device,
55 if (dispatch->lid.is_closed ^ dispatch->lid.is_closed_client_state) {
56 switch_notify_toggle(&device->base,
59 dispatch->lid.is_closed);
60 dispatch->lid.is_closed_client_state = dispatch->lid.is_closed;
65 fallback_notify_physical_button(struct fallback_dispatch *dispatch,
66 struct evdev_device *device,
69 enum libinput_button_state state)
71 evdev_pointer_notify_physical_button(device, time, button, state);
74 static enum libinput_switch_state
75 fallback_interface_get_switch_state(struct evdev_dispatch *evdev_dispatch,
76 enum libinput_switch sw)
78 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
81 case LIBINPUT_SWITCH_TABLET_MODE:
84 /* Internal function only, so we can abort here */
88 return dispatch->tablet_mode.sw.state ?
89 LIBINPUT_SWITCH_STATE_ON :
90 LIBINPUT_SWITCH_STATE_OFF;
94 post_button_scroll(struct evdev_device *device,
95 struct device_float_coords raw,
98 if (device->scroll.method != LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)
101 switch(device->scroll.button_scroll_state) {
102 case BUTTONSCROLL_IDLE:
104 case BUTTONSCROLL_BUTTON_DOWN:
105 /* if the button is down but scroll is not active, we're within the
106 timeout where we swallow motion events but don't post
108 evdev_log_debug(device, "btnscroll: discarding\n");
110 case BUTTONSCROLL_READY:
111 device->scroll.button_scroll_state = BUTTONSCROLL_SCROLLING;
113 case BUTTONSCROLL_SCROLLING:
115 const struct normalized_coords normalized =
116 filter_dispatch_constant(device->pointer.filter,
120 evdev_post_scroll(device, time,
121 LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS,
127 assert(!"invalid scroll button state");
131 fallback_filter_defuzz_touch(struct fallback_dispatch *dispatch,
132 struct evdev_device *device,
133 struct mt_slot *slot)
135 struct device_coords point;
137 if (!dispatch->mt.want_hysteresis)
140 point = evdev_hysteresis(&slot->point,
141 &slot->hysteresis_center,
142 &dispatch->mt.hysteresis_margin);
145 if (point.x == slot->hysteresis_center.x &&
146 point.y == slot->hysteresis_center.y)
149 slot->hysteresis_center = point;
155 fallback_rotate_relative(struct fallback_dispatch *dispatch,
156 struct evdev_device *device)
158 struct device_coords rel = dispatch->rel;
160 if (!device->base.config.rotation)
163 /* loss of precision for non-90 degrees, but we only support 90 deg
164 * right now anyway */
165 matrix_mult_vec(&dispatch->rotation.matrix, &rel.x, &rel.y);
171 fallback_flush_extra_aux_data(struct fallback_dispatch *dispatch,
172 struct evdev_device *device,
173 uint64_t time, int32_t type,
174 int32_t slot, int32_t seat_slot)
176 struct libinput_device *base = &device->base;
177 struct mt_aux_data *aux_data;
179 list_for_each(aux_data, &dispatch->mt.aux_data_list[slot], link) {
180 if (aux_data->changed) {
181 touch_notify_aux_data(base, time, slot, seat_slot, aux_data->code, aux_data->value);
182 aux_data->changed = false;
188 fallback_flush_relative_motion(struct fallback_dispatch *dispatch,
189 struct evdev_device *device,
192 struct libinput_device *base = &device->base;
193 struct normalized_coords accel;
194 struct device_float_coords raw;
196 if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
199 fallback_rotate_relative(dispatch, device);
201 raw.x = dispatch->rel.x;
202 raw.y = dispatch->rel.y;
206 /* Use unaccelerated deltas for pointing stick scroll */
207 if (post_button_scroll(device, raw, time))
210 if (device->pointer.filter) {
211 /* Apply pointer acceleration. */
212 accel = filter_dispatch(device->pointer.filter,
217 evdev_log_bug_libinput(device,
218 "accel filter missing\n");
219 accel.x = accel.y = 0;
222 if (normalized_is_zero(accel))
225 pointer_notify_motion(base, time, &accel, &raw);
229 fallback_flush_absolute_motion(struct fallback_dispatch *dispatch,
230 struct evdev_device *device,
233 struct libinput_device *base = &device->base;
234 struct device_coords point;
236 if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
239 point = dispatch->abs.point;
240 evdev_transform_absolute(device, &point);
242 pointer_notify_motion_absolute(base, time, &point);
246 fallback_flush_mt_down(struct fallback_dispatch *dispatch,
247 struct evdev_device *device,
251 struct libinput_device *base = &device->base;
252 struct libinput_seat *seat = base->seat;
253 struct device_coords point;
254 struct mt_slot *slot;
257 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
260 slot = &dispatch->mt.slots[slot_idx];
261 if (slot->seat_slot != -1) {
262 evdev_log_bug_kernel(device,
263 "driver sent multiple touch down for the same slot");
267 seat_slot = ffs(~seat->slot_map) - 1;
268 slot->seat_slot = seat_slot;
273 seat->slot_map |= bit(seat_slot);
275 slot->hysteresis_center = point;
276 evdev_transform_absolute(device, &point);
278 fallback_flush_extra_aux_data(dispatch, device, time,
279 dispatch->pending_event, slot_idx, seat_slot);
280 touch_notify_touch_down(base, time, slot_idx, seat_slot,
281 &point, &slot->area, slot->pressure);
287 fallback_flush_mt_motion(struct fallback_dispatch *dispatch,
288 struct evdev_device *device,
292 struct libinput_device *base = &device->base;
293 struct device_coords point;
294 struct mt_slot *slot;
297 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
300 slot = &dispatch->mt.slots[slot_idx];
301 seat_slot = slot->seat_slot;
307 if (fallback_filter_defuzz_touch(dispatch, device, slot))
310 evdev_transform_absolute(device, &point);
312 fallback_flush_extra_aux_data(dispatch, device, time,
313 dispatch->pending_event, slot_idx, seat_slot);
314 touch_notify_touch_motion(base, time, slot_idx, seat_slot,
315 &point, &slot->area, slot->pressure);
321 fallback_flush_mt_up(struct fallback_dispatch *dispatch,
322 struct evdev_device *device,
326 struct libinput_device *base = &device->base;
327 struct libinput_seat *seat = base->seat;
328 struct mt_slot *slot;
331 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
334 slot = &dispatch->mt.slots[slot_idx];
335 seat_slot = slot->seat_slot;
336 slot->seat_slot = -1;
341 seat->slot_map &= ~bit(seat_slot);
343 fallback_flush_extra_aux_data(dispatch, device, time,
344 dispatch->pending_event, slot_idx, seat_slot);
345 touch_notify_touch_up(base, time, slot_idx, seat_slot);
351 fallback_flush_mt_cancel(struct fallback_dispatch *dispatch,
352 struct evdev_device *device,
356 struct libinput_device *base = &device->base;
357 struct libinput_seat *seat = base->seat;
358 struct mt_slot *slot;
361 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
364 slot = &dispatch->mt.slots[slot_idx];
365 seat_slot = slot->seat_slot;
366 slot->seat_slot = -1;
371 seat->slot_map &= ~bit(seat_slot);
373 touch_notify_touch_cancel(base, time, slot_idx, seat_slot);
379 fallback_flush_st_down(struct fallback_dispatch *dispatch,
380 struct evdev_device *device,
383 struct libinput_device *base = &device->base;
384 struct libinput_seat *seat = base->seat;
385 struct device_coords point;
387 struct ellipse default_touch = {
388 .major = DEFAULT_TOUCH_MAJOR,
389 .minor = DEFAULT_TOUCH_MINOR,
390 .orientation = DEFAULT_TOUCH_ORIENTATION
393 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
396 if (dispatch->abs.seat_slot != -1) {
397 evdev_log_bug_kernel(device,
398 "driver sent multiple touch down for the same slot");
402 seat_slot = ffs(~seat->slot_map) - 1;
403 dispatch->abs.seat_slot = seat_slot;
408 seat->slot_map |= bit(seat_slot);
410 point = dispatch->abs.point;
411 evdev_transform_absolute(device, &point);
413 touch_notify_touch_down(base, time, -1, seat_slot, &point, &default_touch, DEFAULT_TOUCH_PRESSURE);
419 fallback_flush_st_motion(struct fallback_dispatch *dispatch,
420 struct evdev_device *device,
423 struct libinput_device *base = &device->base;
424 struct device_coords point;
426 struct ellipse default_touch = {
427 .major = DEFAULT_TOUCH_MAJOR,
428 .minor = DEFAULT_TOUCH_MINOR,
429 .orientation = DEFAULT_TOUCH_ORIENTATION
432 point = dispatch->abs.point;
433 evdev_transform_absolute(device, &point);
435 seat_slot = dispatch->abs.seat_slot;
440 touch_notify_touch_motion(base, time, -1, seat_slot, &point, &default_touch, DEFAULT_TOUCH_PRESSURE);
446 fallback_flush_st_up(struct fallback_dispatch *dispatch,
447 struct evdev_device *device,
450 struct libinput_device *base = &device->base;
451 struct libinput_seat *seat = base->seat;
454 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
457 seat_slot = dispatch->abs.seat_slot;
458 dispatch->abs.seat_slot = -1;
463 seat->slot_map &= ~bit(seat_slot);
465 touch_notify_touch_up(base, time, -1, seat_slot);
471 fallback_flush_st_cancel(struct fallback_dispatch *dispatch,
472 struct evdev_device *device,
475 struct libinput_device *base = &device->base;
476 struct libinput_seat *seat = base->seat;
479 if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
482 seat_slot = dispatch->abs.seat_slot;
483 dispatch->abs.seat_slot = -1;
488 seat->slot_map &= ~bit(seat_slot);
490 touch_notify_touch_cancel(base, time, -1, seat_slot);
496 fallback_process_touch_extra_aux_data(struct fallback_dispatch *dispatch,
497 struct evdev_device *device,
498 struct input_event *e)
500 struct mt_aux_data *aux_data;
501 struct list *current_axis_list;
503 if (!dispatch->mt.aux_data_list) return false;
504 if (dispatch->mt.slot < 0 || dispatch->mt.slot >= (int)dispatch->mt.slots_len)
507 current_axis_list = &dispatch->mt.aux_data_list[dispatch->mt.slot];
509 if (list_empty(current_axis_list)) return false;
511 list_for_each(aux_data, current_axis_list, link) {
512 if (aux_data->code == e->code) {
513 if (aux_data->value != e->value) {
514 aux_data->changed = true;
515 aux_data->value = e->value;
523 fallback_process_touch_button(struct fallback_dispatch *dispatch,
524 struct evdev_device *device,
525 uint64_t time, int value)
527 dispatch->pending_event |= (value) ?
528 EVDEV_ABSOLUTE_TOUCH_DOWN :
529 EVDEV_ABSOLUTE_TOUCH_UP;
533 fallback_process_key(struct fallback_dispatch *dispatch,
534 struct evdev_device *device,
535 struct input_event *e, uint64_t time)
539 /* ignore kernel key repeat */
543 if (e->code == BTN_TOUCH) {
545 fallback_process_touch_button(dispatch,
552 type = get_key_type(e->code);
554 /* Ignore key release events from the kernel for keys that libinput
555 * never got a pressed event for or key presses for keys that we
556 * think are still down */
561 case KEY_TYPE_BUTTON:
562 if ((e->value && hw_is_key_down(dispatch, e->code)) ||
563 (e->value == 0 && !hw_is_key_down(dispatch, e->code))) {
567 dispatch->pending_event |= EVDEV_KEY;
571 hw_set_key_down(dispatch, e->code, e->value);
577 fallback_keyboard_notify_key(
582 e->value ? LIBINPUT_KEY_STATE_PRESSED :
583 LIBINPUT_KEY_STATE_RELEASED);
585 case KEY_TYPE_BUTTON:
591 fallback_process_touch(struct fallback_dispatch *dispatch,
592 struct evdev_device *device,
593 struct input_event *e,
596 struct mt_slot *slot = &dispatch->mt.slots[dispatch->mt.slot];
598 if (e->code == ABS_MT_SLOT) {
599 if ((size_t)e->value >= dispatch->mt.slots_len) {
600 evdev_log_bug_libinput(device,
601 "exceeded slot count (%d of max %zd)\n",
603 dispatch->mt.slots_len);
604 e->value = dispatch->mt.slots_len - 1;
606 dispatch->mt.slot = e->value;
611 case ABS_MT_TRACKING_ID:
613 dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
614 slot->state = SLOT_STATE_BEGIN;
615 if (dispatch->mt.has_palm) {
617 v = libevdev_get_slot_value(device->evdev,
622 /* new touch, no cancel needed */
623 slot->palm_state = PALM_WAS_PALM;
626 slot->palm_state = PALM_NONE;
630 slot->palm_state = PALM_NONE;
633 dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
634 slot->state = SLOT_STATE_END;
638 case ABS_MT_POSITION_X:
639 evdev_device_check_abs_axis_range(device, e->code, e->value);
640 dispatch->mt.slots[dispatch->mt.slot].point.x = e->value;
641 dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
644 case ABS_MT_POSITION_Y:
645 evdev_device_check_abs_axis_range(device, e->code, e->value);
646 dispatch->mt.slots[dispatch->mt.slot].point.y = e->value;
647 dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
650 case ABS_MT_TOOL_TYPE:
651 /* The transitions matter - we (may) need to send a touch
652 * cancel event if we just switched to a palm touch. And the
653 * kernel may switch back to finger but we keep the touch as
654 * palm - but then we need to reset correctly on a new touch
659 if (slot->palm_state == PALM_NONE)
660 slot->palm_state = PALM_NEW;
663 if (slot->palm_state == PALM_IS_PALM)
664 slot->palm_state = PALM_WAS_PALM;
667 dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
670 case ABS_MT_TOUCH_MAJOR:
671 dispatch->mt.slots[dispatch->mt.slot].area.major = e->value;
672 if (dispatch->pending_event == EVDEV_NONE)
673 dispatch->pending_event = EVDEV_ABSOLUTE_MT;
675 case ABS_MT_TOUCH_MINOR:
676 dispatch->mt.slots[dispatch->mt.slot].area.minor = e->value;
677 if (dispatch->pending_event == EVDEV_NONE)
678 dispatch->pending_event = EVDEV_ABSOLUTE_MT;
680 case ABS_MT_ORIENTATION:
681 dispatch->mt.slots[dispatch->mt.slot].area.orientation = e->value;
682 if (dispatch->pending_event == EVDEV_NONE)
683 dispatch->pending_event = EVDEV_ABSOLUTE_MT;
686 fallback_process_touch_extra_aux_data(dispatch, device, e);
692 fallback_process_absolute_motion(struct fallback_dispatch *dispatch,
693 struct evdev_device *device,
694 struct input_event *e)
698 evdev_device_check_abs_axis_range(device, e->code, e->value);
699 dispatch->abs.point.x = e->value;
700 dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION;
703 evdev_device_check_abs_axis_range(device, e->code, e->value);
704 dispatch->abs.point.y = e->value;
705 dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION;
711 fallback_lid_keyboard_event(uint64_t time,
712 struct libinput_event *event,
715 struct fallback_dispatch *dispatch = fallback_dispatch(data);
717 if (!dispatch->lid.is_closed)
720 if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY)
723 if (dispatch->lid.reliability == RELIABILITY_WRITE_OPEN) {
724 int fd = libevdev_get_fd(dispatch->device->evdev);
726 struct input_event ev[2];
728 ev[0] = input_event_init(0, EV_SW, SW_LID, 0);
729 ev[1] = input_event_init(0, EV_SYN, SYN_REPORT, 0);
731 rc = write(fd, ev, sizeof(ev));
734 evdev_log_error(dispatch->device,
735 "failed to write SW_LID state (%s)",
738 /* In case write() fails, we sync the lid state manually
742 /* Posting the event here means we preempt the keyboard events that
743 * caused us to wake up, so the lid event is always passed on before
746 dispatch->lid.is_closed = false;
747 fallback_lid_notify_toggle(dispatch, dispatch->device, time);
751 fallback_lid_toggle_keyboard_listener(struct fallback_dispatch *dispatch,
752 struct evdev_paired_keyboard *kbd,
757 libinput_device_remove_event_listener(&kbd->listener);
760 libinput_device_add_event_listener(
763 fallback_lid_keyboard_event,
766 libinput_device_init_event_listener(&kbd->listener);
771 fallback_lid_toggle_keyboard_listeners(struct fallback_dispatch *dispatch,
774 struct evdev_paired_keyboard *kbd;
776 list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) {
780 fallback_lid_toggle_keyboard_listener(dispatch,
787 fallback_process_switch(struct fallback_dispatch *dispatch,
788 struct evdev_device *device,
789 struct input_event *e,
792 enum libinput_switch_state state;
795 /* TODO: this should to move to handle_state */
799 is_closed = !!e->value;
801 fallback_lid_toggle_keyboard_listeners(dispatch, is_closed);
803 if (dispatch->lid.is_closed == is_closed)
806 dispatch->lid.is_closed = is_closed;
807 fallback_lid_notify_toggle(dispatch, device, time);
810 if (dispatch->tablet_mode.sw.state == e->value)
813 dispatch->tablet_mode.sw.state = e->value;
815 state = LIBINPUT_SWITCH_STATE_ON;
817 state = LIBINPUT_SWITCH_STATE_OFF;
818 switch_notify_toggle(&device->base,
820 LIBINPUT_SWITCH_TABLET_MODE,
827 fallback_reject_relative(struct evdev_device *device,
828 const struct input_event *e,
831 if ((e->code == REL_X || e->code == REL_Y) &&
832 (device->seat_caps & EVDEV_DEVICE_POINTER) == 0) {
833 evdev_log_bug_libinput_ratelimit(device,
834 &device->nonpointer_rel_limit,
835 "REL_X/Y from a non-pointer device\n");
843 fallback_process_relative(struct fallback_dispatch *dispatch,
844 struct evdev_device *device,
845 struct input_event *e, uint64_t time)
847 if (fallback_reject_relative(device, e, time))
852 dispatch->rel.x += e->value;
853 dispatch->pending_event |= EVDEV_RELATIVE_MOTION;
856 dispatch->rel.y += e->value;
857 dispatch->pending_event |= EVDEV_RELATIVE_MOTION;
861 fallback_wheel_process_relative(dispatch, device, e, time);
865 fallback_process_absolute(struct fallback_dispatch *dispatch,
866 struct evdev_device *device,
867 struct input_event *e,
871 fallback_process_touch(dispatch, device, e, time);
873 fallback_process_absolute_motion(dispatch, device, e);
878 fallback_any_button_down(struct fallback_dispatch *dispatch,
879 struct evdev_device *device)
883 for (button = BTN_LEFT; button < BTN_JOYSTICK; button++) {
884 if (libevdev_has_event_code(device->evdev, EV_KEY, button) &&
885 hw_is_key_down(dispatch, button))
892 fallback_arbitrate_touch(struct fallback_dispatch *dispatch,
893 struct mt_slot *slot)
895 bool discard = false;
897 if (dispatch->arbitration.state == ARBITRATION_IGNORE_RECT &&
898 point_in_rect(&slot->point, &dispatch->arbitration.rect)) {
899 slot->palm_state = PALM_IS_PALM;
907 fallback_flush_mt_events(struct fallback_dispatch *dispatch,
908 struct evdev_device *device,
913 for (size_t i = 0; i < dispatch->mt.slots_len; i++) {
914 struct mt_slot *slot = &dispatch->mt.slots[i];
921 /* Any palm state other than PALM_NEW means we've either
922 * already cancelled the touch or the touch was never
923 * a finger anyway and we didn't send the begin.
925 if (slot->palm_state == PALM_NEW) {
926 if (slot->state != SLOT_STATE_BEGIN)
927 sent = fallback_flush_mt_cancel(dispatch,
931 slot->palm_state = PALM_IS_PALM;
932 } else if (slot->palm_state == PALM_NONE) {
933 switch (slot->state) {
934 case SLOT_STATE_BEGIN:
935 if (!fallback_arbitrate_touch(dispatch,
937 sent = fallback_flush_mt_down(dispatch,
943 case SLOT_STATE_UPDATE:
944 sent = fallback_flush_mt_motion(dispatch,
950 sent = fallback_flush_mt_up(dispatch,
955 case SLOT_STATE_NONE:
960 /* State machine continues independent of the palm state */
961 switch (slot->state) {
962 case SLOT_STATE_BEGIN:
963 slot->state = SLOT_STATE_UPDATE;
965 case SLOT_STATE_UPDATE:
968 slot->state = SLOT_STATE_NONE;
970 case SLOT_STATE_NONE:
971 /* touch arbitration may swallow the begin,
972 * so we may get updates for a touch still
982 fallback_handle_state(struct fallback_dispatch *dispatch,
983 struct evdev_device *device,
986 bool need_touch_frame = false;
988 /* Relative motion */
989 if (dispatch->pending_event & EVDEV_RELATIVE_MOTION)
990 fallback_flush_relative_motion(dispatch, device, time);
992 /* Single touch or absolute pointer devices */
993 if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_DOWN) {
994 if (fallback_flush_st_down(dispatch, device, time))
995 need_touch_frame = true;
996 } else if (dispatch->pending_event & EVDEV_ABSOLUTE_MOTION) {
997 if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
998 if (fallback_flush_st_motion(dispatch,
1001 need_touch_frame = true;
1002 } else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
1003 fallback_flush_absolute_motion(dispatch,
1009 if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_UP) {
1010 if (fallback_flush_st_up(dispatch, device, time))
1011 need_touch_frame = true;
1014 /* Multitouch devices */
1015 if (dispatch->pending_event & EVDEV_ABSOLUTE_MT)
1016 need_touch_frame = fallback_flush_mt_events(dispatch,
1020 if (need_touch_frame)
1021 touch_notify_frame(&device->base, time);
1023 fallback_wheel_handle_state(dispatch, device, time);
1025 /* Buttons and keys */
1026 if (dispatch->pending_event & EVDEV_KEY) {
1027 bool want_debounce = false;
1028 for (unsigned int code = 0; code <= KEY_MAX; code++) {
1029 if (!hw_key_has_changed(dispatch, code))
1032 if (get_key_type(code) == KEY_TYPE_BUTTON) {
1033 want_debounce = true;
1039 fallback_debounce_handle_state(dispatch, time);
1041 hw_key_update_last_state(dispatch);
1044 dispatch->pending_event = EVDEV_NONE;
1048 fallback_interface_process(struct evdev_dispatch *evdev_dispatch,
1049 struct evdev_device *device,
1050 struct input_event *event,
1053 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1055 if (dispatch->arbitration.in_arbitration)
1058 switch (event->type) {
1060 fallback_process_relative(dispatch, device, event, time);
1063 fallback_process_absolute(dispatch, device, event, time);
1066 fallback_process_key(dispatch, device, event, time);
1069 fallback_process_switch(dispatch, device, event, time);
1072 fallback_handle_state(dispatch, device, time);
1078 cancel_touches(struct fallback_dispatch *dispatch,
1079 struct evdev_device *device,
1080 const struct device_coord_rect *rect,
1084 bool need_frame = false;
1086 if (!rect || point_in_rect(&dispatch->abs.point, rect))
1087 need_frame = fallback_flush_st_cancel(dispatch,
1091 for (idx = 0; idx < dispatch->mt.slots_len; idx++) {
1092 struct mt_slot *slot = &dispatch->mt.slots[idx];
1094 if (slot->seat_slot == -1)
1097 if ((!rect || point_in_rect(&slot->point, rect)) &&
1098 fallback_flush_mt_cancel(dispatch, device, idx, time))
1103 touch_notify_frame(&device->base, time);
1107 release_pressed_keys(struct fallback_dispatch *dispatch,
1108 struct evdev_device *device,
1113 for (code = 0; code < KEY_CNT; code++) {
1114 int count = get_key_down_count(device, code);
1120 evdev_log_bug_libinput(device,
1121 "key %d is down %d times.\n",
1126 switch (get_key_type(code)) {
1130 fallback_keyboard_notify_key(
1135 LIBINPUT_KEY_STATE_RELEASED);
1137 case KEY_TYPE_BUTTON:
1138 evdev_pointer_notify_button(
1141 evdev_to_left_handed(device, code),
1142 LIBINPUT_BUTTON_STATE_RELEASED);
1146 count = get_key_down_count(device, code);
1148 evdev_log_bug_libinput(device,
1149 "releasing key %d failed.\n",
1157 fallback_return_to_neutral_state(struct fallback_dispatch *dispatch,
1158 struct evdev_device *device)
1160 struct libinput *libinput = evdev_libinput_context(device);
1163 if ((time = libinput_now(libinput)) == 0)
1166 cancel_touches(dispatch, device, NULL, time);
1167 release_pressed_keys(dispatch, device, time);
1168 memset(dispatch->hw_key_mask, 0, sizeof(dispatch->hw_key_mask));
1169 memset(dispatch->hw_key_mask, 0, sizeof(dispatch->last_hw_key_mask));
1173 fallback_interface_suspend(struct evdev_dispatch *evdev_dispatch,
1174 struct evdev_device *device)
1176 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1178 fallback_return_to_neutral_state(dispatch, device);
1182 fallback_interface_remove(struct evdev_dispatch *evdev_dispatch)
1184 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1185 struct evdev_paired_keyboard *kbd;
1187 libinput_timer_cancel(&dispatch->wheel.scroll_timer);
1188 libinput_timer_cancel(&dispatch->debounce.timer);
1189 libinput_timer_cancel(&dispatch->debounce.timer_short);
1190 libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
1192 libinput_device_remove_event_listener(&dispatch->tablet_mode.other.listener);
1194 list_for_each_safe(kbd,
1195 &dispatch->lid.paired_keyboard_list,
1197 evdev_paired_keyboard_destroy(kbd);
1202 fallback_interface_sync_initial_state(struct evdev_device *device,
1203 struct evdev_dispatch *evdev_dispatch)
1205 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1206 uint64_t time = libinput_now(evdev_libinput_context(device));
1208 if (device->tags & EVDEV_TAG_LID_SWITCH) {
1209 struct libevdev *evdev = device->evdev;
1211 dispatch->lid.is_closed = libevdev_get_event_value(evdev,
1214 dispatch->lid.is_closed_client_state = false;
1216 /* For the initial state sync, we depend on whether the lid switch
1217 * is reliable. If we know it's reliable, we sync as expected.
1218 * If we're not sure, we ignore the initial state and only sync on
1219 * the first future lid close event. Laptops with a broken switch
1220 * that always have the switch in 'on' state thus don't mess up our
1223 if (dispatch->lid.is_closed &&
1224 dispatch->lid.reliability == RELIABILITY_RELIABLE) {
1225 fallback_lid_notify_toggle(dispatch, device, time);
1229 if (dispatch->tablet_mode.sw.state) {
1230 switch_notify_toggle(&device->base,
1232 LIBINPUT_SWITCH_TABLET_MODE,
1233 LIBINPUT_SWITCH_STATE_ON);
1238 fallback_interface_update_rect(struct evdev_dispatch *evdev_dispatch,
1239 struct evdev_device *device,
1240 const struct phys_rect *phys_rect,
1243 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1244 struct device_coord_rect rect;
1248 /* Existing touches do not change, we just update the rect and only
1249 * new touches in these areas will be ignored. If you want to paint
1250 * over your finger, be my guest. */
1251 rect = evdev_phys_rect_to_units(device, phys_rect);
1252 dispatch->arbitration.rect = rect;
1256 fallback_interface_toggle_touch(struct evdev_dispatch *evdev_dispatch,
1257 struct evdev_device *device,
1258 enum evdev_arbitration_state which,
1259 const struct phys_rect *phys_rect,
1262 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1263 struct device_coord_rect rect = {0};
1265 if (which == dispatch->arbitration.state)
1269 case ARBITRATION_NOT_ACTIVE:
1270 /* if in-kernel arbitration is in use and there is a touch
1271 * and a pen in proximity, lifting the pen out of proximity
1272 * causes a touch begin for the touch. On a hand-lift the
1273 * proximity out precedes the touch up by a few ms, so we
1274 * get what looks like a tap. Fix this by delaying
1275 * arbitration by just a little bit so that any touch in
1276 * event is caught as palm touch. */
1277 libinput_timer_set(&dispatch->arbitration.arbitration_timer,
1280 case ARBITRATION_IGNORE_RECT:
1282 rect = evdev_phys_rect_to_units(device, phys_rect);
1283 cancel_touches(dispatch, device, &rect, time);
1284 dispatch->arbitration.rect = rect;
1286 case ARBITRATION_IGNORE_ALL:
1287 libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
1288 fallback_return_to_neutral_state(dispatch, device);
1289 dispatch->arbitration.in_arbitration = true;
1293 dispatch->arbitration.state = which;
1297 fallback_interface_destroy(struct evdev_dispatch *evdev_dispatch)
1299 struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
1301 libinput_timer_destroy(&dispatch->wheel.scroll_timer);
1302 libinput_timer_destroy(&dispatch->arbitration.arbitration_timer);
1303 libinput_timer_destroy(&dispatch->debounce.timer);
1304 libinput_timer_destroy(&dispatch->debounce.timer_short);
1306 free(dispatch->mt.slots);
1311 fallback_lid_pair_keyboard(struct evdev_device *lid_switch,
1312 struct evdev_device *keyboard)
1314 struct fallback_dispatch *dispatch =
1315 fallback_dispatch(lid_switch->dispatch);
1316 struct evdev_paired_keyboard *kbd;
1319 if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0 ||
1320 (lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0)
1323 if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0)
1326 list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) {
1329 evdev_log_info(lid_switch,
1330 "lid: too many internal keyboards\n");
1335 kbd = zalloc(sizeof(*kbd));
1336 kbd->device = keyboard;
1337 libinput_device_init_event_listener(&kbd->listener);
1338 list_insert(&dispatch->lid.paired_keyboard_list, &kbd->link);
1339 evdev_log_debug(lid_switch,
1340 "lid: keyboard paired with %s<->%s\n",
1341 lid_switch->devname,
1344 /* We need to init the event listener now only if the
1345 * reported state is closed. */
1346 if (dispatch->lid.is_closed)
1347 fallback_lid_toggle_keyboard_listener(dispatch,
1349 dispatch->lid.is_closed);
1353 fallback_resume(struct fallback_dispatch *dispatch,
1354 struct evdev_device *device)
1356 if (dispatch->base.sendevents.current_mode ==
1357 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED)
1360 evdev_device_resume(device);
1364 fallback_suspend(struct fallback_dispatch *dispatch,
1365 struct evdev_device *device)
1367 evdev_device_suspend(device);
1371 fallback_tablet_mode_switch_event(uint64_t time,
1372 struct libinput_event *event,
1375 struct fallback_dispatch *dispatch = data;
1376 struct evdev_device *device = dispatch->device;
1377 struct libinput_event_switch *swev;
1379 if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE)
1382 swev = libinput_event_get_switch_event(event);
1383 if (libinput_event_switch_get_switch(swev) !=
1384 LIBINPUT_SWITCH_TABLET_MODE)
1387 switch (libinput_event_switch_get_switch_state(swev)) {
1388 case LIBINPUT_SWITCH_STATE_OFF:
1389 fallback_resume(dispatch, device);
1390 evdev_log_debug(device, "tablet-mode: resuming device\n");
1392 case LIBINPUT_SWITCH_STATE_ON:
1393 fallback_suspend(dispatch, device);
1394 evdev_log_debug(device, "tablet-mode: suspending device\n");
1400 fallback_pair_tablet_mode(struct evdev_device *keyboard,
1401 struct evdev_device *tablet_mode_switch)
1403 struct fallback_dispatch *dispatch =
1404 fallback_dispatch(keyboard->dispatch);
1406 if ((keyboard->tags & EVDEV_TAG_EXTERNAL_KEYBOARD))
1409 if ((keyboard->tags & EVDEV_TAG_TRACKPOINT)) {
1410 if (keyboard->tags & EVDEV_TAG_EXTERNAL_MOUSE)
1412 /* This filters out all internal keyboard-like devices (Video
1414 } else if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0) {
1418 if (evdev_device_has_model_quirk(keyboard,
1419 QUIRK_MODEL_TABLET_MODE_NO_SUSPEND))
1422 if ((tablet_mode_switch->tags & EVDEV_TAG_TABLET_MODE_SWITCH) == 0)
1425 if (dispatch->tablet_mode.other.sw_device)
1428 evdev_log_debug(keyboard,
1429 "tablet-mode: paired %s<->%s\n",
1431 tablet_mode_switch->devname);
1433 libinput_device_add_event_listener(&tablet_mode_switch->base,
1434 &dispatch->tablet_mode.other.listener,
1435 fallback_tablet_mode_switch_event,
1437 dispatch->tablet_mode.other.sw_device = tablet_mode_switch;
1439 if (evdev_device_switch_get_state(tablet_mode_switch,
1440 LIBINPUT_SWITCH_TABLET_MODE)
1441 == LIBINPUT_SWITCH_STATE_ON) {
1442 evdev_log_debug(keyboard, "tablet-mode: suspending device\n");
1443 fallback_suspend(dispatch, keyboard);
1448 fallback_interface_device_added(struct evdev_device *device,
1449 struct evdev_device *added_device)
1451 fallback_lid_pair_keyboard(device, added_device);
1452 fallback_pair_tablet_mode(device, added_device);
1456 fallback_interface_device_removed(struct evdev_device *device,
1457 struct evdev_device *removed_device)
1459 struct fallback_dispatch *dispatch =
1460 fallback_dispatch(device->dispatch);
1461 struct evdev_paired_keyboard *kbd;
1463 list_for_each_safe(kbd,
1464 &dispatch->lid.paired_keyboard_list,
1469 if (kbd->device != removed_device)
1472 evdev_paired_keyboard_destroy(kbd);
1475 if (removed_device == dispatch->tablet_mode.other.sw_device) {
1476 libinput_device_remove_event_listener(
1477 &dispatch->tablet_mode.other.listener);
1478 libinput_device_init_event_listener(
1479 &dispatch->tablet_mode.other.listener);
1480 dispatch->tablet_mode.other.sw_device = NULL;
1484 struct evdev_dispatch_interface fallback_interface = {
1485 .process = fallback_interface_process,
1486 .suspend = fallback_interface_suspend,
1487 .remove = fallback_interface_remove,
1488 .destroy = fallback_interface_destroy,
1489 .device_added = fallback_interface_device_added,
1490 .device_removed = fallback_interface_device_removed,
1491 .device_suspended = fallback_interface_device_removed, /* treat as remove */
1492 .device_resumed = fallback_interface_device_added, /* treat as add */
1493 .post_added = fallback_interface_sync_initial_state,
1494 .touch_arbitration_toggle = fallback_interface_toggle_touch,
1495 .touch_arbitration_update_rect = fallback_interface_update_rect,
1496 .get_switch_state = fallback_interface_get_switch_state,
1500 fallback_device_interface_set_aux_data(struct evdev_dispatch *evdev_dispatch, uint32_t code)
1503 struct fallback_dispatch *dispatch;
1504 struct mt_aux_data *aux_data;
1506 dispatch = fallback_dispatch(evdev_dispatch);
1508 if (!list_empty(&dispatch->mt.aux_data_list[0])) {
1509 list_for_each(aux_data, &dispatch->mt.aux_data_list[0], link) {
1510 if (code == aux_data->code) return;
1514 for (i = 0; i < (int)dispatch->mt.slots_len; i++) {
1515 aux_data = calloc(1, sizeof(struct mt_aux_data));
1516 if (!aux_data) goto failed;
1517 aux_data->code = code;
1518 list_insert(&dispatch->mt.aux_data_list[i], &aux_data->link);
1523 for (i = i-1; i >= 0; i--) {
1524 list_for_each_safe(aux_data, &dispatch->mt.aux_data_list[i], link) {
1525 list_remove(&aux_data->link);
1532 fallback_device_interface_free_aux_data(struct evdev_dispatch *evdev_dispatch)
1535 struct fallback_dispatch *dispatch;
1536 struct mt_aux_data *aux_data;
1538 dispatch = fallback_dispatch(evdev_dispatch);
1540 for (i = 0; i < (int)dispatch->mt.slots_len; i++) {
1541 list_for_each_safe(aux_data, &dispatch->mt.aux_data_list[i], link) {
1542 list_remove(&aux_data->link);
1545 list_remove(&dispatch->mt.aux_data_list[i]);
1547 free(dispatch->mt.aux_data_list);
1550 struct evdev_dispatch_device_interface fallback_device_interface = {
1551 .set_aux_data = fallback_device_interface_set_aux_data
1555 fallback_change_to_left_handed(struct evdev_device *device)
1557 struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
1559 if (device->left_handed.want_enabled == device->left_handed.enabled)
1562 if (fallback_any_button_down(dispatch, device))
1565 device->left_handed.enabled = device->left_handed.want_enabled;
1569 fallback_change_scroll_method(struct evdev_device *device)
1571 struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
1573 if (device->scroll.want_method == device->scroll.method &&
1574 device->scroll.want_button == device->scroll.button &&
1575 device->scroll.want_lock_enabled == device->scroll.lock_enabled)
1578 if (fallback_any_button_down(dispatch, device))
1581 device->scroll.method = device->scroll.want_method;
1582 device->scroll.button = device->scroll.want_button;
1583 device->scroll.lock_enabled = device->scroll.want_lock_enabled;
1584 evdev_set_button_scroll_lock_enabled(device, device->scroll.lock_enabled);
1588 fallback_rotation_config_is_available(struct libinput_device *device)
1590 /* This function only gets called when we support rotation */
1594 static enum libinput_config_status
1595 fallback_rotation_config_set_angle(struct libinput_device *libinput_device,
1596 unsigned int degrees_cw)
1598 struct evdev_device *device = evdev_device(libinput_device);
1599 struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
1601 dispatch->rotation.angle = degrees_cw;
1602 matrix_init_rotate(&dispatch->rotation.matrix, degrees_cw);
1604 return LIBINPUT_CONFIG_STATUS_SUCCESS;
1608 fallback_rotation_config_get_angle(struct libinput_device *libinput_device)
1610 struct evdev_device *device = evdev_device(libinput_device);
1611 struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
1613 return dispatch->rotation.angle;
1617 fallback_rotation_config_get_default_angle(struct libinput_device *device)
1623 fallback_init_rotation(struct fallback_dispatch *dispatch,
1624 struct evdev_device *device)
1626 if ((device->model_flags & EVDEV_MODEL_TRACKBALL) == 0)
1629 dispatch->rotation.config.is_available = fallback_rotation_config_is_available;
1630 dispatch->rotation.config.set_angle = fallback_rotation_config_set_angle;
1631 dispatch->rotation.config.get_angle = fallback_rotation_config_get_angle;
1632 dispatch->rotation.config.get_default_angle = fallback_rotation_config_get_default_angle;
1633 dispatch->rotation.is_enabled = false;
1634 matrix_init_identity(&dispatch->rotation.matrix);
1635 device->base.config.rotation = &dispatch->rotation.config;
1639 fallback_dispatch_init_slots(struct fallback_dispatch *dispatch,
1640 struct evdev_device *device)
1642 struct libevdev *evdev = device->evdev;
1643 struct mt_slot *slots;
1648 if (evdev_is_fake_mt_device(device) ||
1649 !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
1650 !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
1653 /* We only handle the slotted Protocol B in libinput.
1654 Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
1655 require mtdev for conversion. */
1656 if (evdev_need_mtdev(device)) {
1657 device->mtdev = mtdev_new_open(device->fd);
1661 /* pick 10 slots as default for type A
1664 active_slot = device->mtdev->caps.slot.value;
1666 num_slots = libevdev_get_num_slots(device->evdev);
1667 active_slot = libevdev_get_current_slot(evdev);
1670 slots = zalloc(num_slots * sizeof(struct mt_slot));
1672 for (slot = 0; slot < num_slots; ++slot) {
1673 slots[slot].seat_slot = -1;
1675 if (evdev_need_mtdev(device))
1678 slots[slot].point.x = libevdev_get_slot_value(evdev,
1681 slots[slot].point.y = libevdev_get_slot_value(evdev,
1684 slots[slot].area.major = libevdev_get_slot_value(evdev,
1686 ABS_MT_TOUCH_MAJOR);
1687 slots[slot].area.minor = libevdev_get_slot_value(evdev,
1689 ABS_MT_TOUCH_MINOR);
1690 slots[slot].area.orientation = libevdev_get_slot_value(evdev,
1692 ABS_MT_ORIENTATION);
1693 slots[slot].pressure = libevdev_get_slot_value(evdev,
1697 dispatch->mt.slots = slots;
1698 dispatch->mt.slots_len = num_slots;
1699 dispatch->mt.slot = active_slot;
1700 dispatch->mt.has_palm = libevdev_has_event_code(evdev,
1704 dispatch->mt.aux_data_list = calloc(num_slots, sizeof(struct list));
1705 if (dispatch->mt.aux_data_list) {
1707 for (i = 0; i < num_slots; i++) {
1708 list_init(&dispatch->mt.aux_data_list[i]);
1714 if (device->abs.absinfo_x->fuzz || device->abs.absinfo_y->fuzz) {
1715 dispatch->mt.want_hysteresis = true;
1716 dispatch->mt.hysteresis_margin.x = device->abs.absinfo_x->fuzz/2;
1717 dispatch->mt.hysteresis_margin.y = device->abs.absinfo_y->fuzz/2;
1724 fallback_dispatch_init_rel(struct fallback_dispatch *dispatch,
1725 struct evdev_device *device)
1727 dispatch->rel.x = 0;
1728 dispatch->rel.y = 0;
1732 fallback_dispatch_init_abs(struct fallback_dispatch *dispatch,
1733 struct evdev_device *device)
1735 if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X))
1738 dispatch->abs.point.x = device->abs.absinfo_x->value;
1739 dispatch->abs.point.y = device->abs.absinfo_y->value;
1740 dispatch->abs.seat_slot = -1;
1742 evdev_device_init_abs_range_warnings(device);
1746 fallback_dispatch_init_switch(struct fallback_dispatch *dispatch,
1747 struct evdev_device *device)
1751 list_init(&dispatch->lid.paired_keyboard_list);
1753 if (device->tags & EVDEV_TAG_LID_SWITCH) {
1754 dispatch->lid.reliability = evdev_read_switch_reliability_prop(device);
1755 dispatch->lid.is_closed = false;
1758 if (device->tags & EVDEV_TAG_TABLET_MODE_SWITCH) {
1759 val = libevdev_get_event_value(device->evdev,
1762 dispatch->tablet_mode.sw.state = val;
1765 libinput_device_init_event_listener(&dispatch->tablet_mode.other.listener);
1769 fallback_arbitration_timeout(uint64_t now, void *data)
1771 struct fallback_dispatch *dispatch = data;
1773 if (dispatch->arbitration.in_arbitration)
1774 dispatch->arbitration.in_arbitration = false;
1778 fallback_init_arbitration(struct fallback_dispatch *dispatch,
1779 struct evdev_device *device)
1781 char timer_name[64];
1783 snprintf(timer_name,
1786 evdev_device_get_sysname(device));
1787 libinput_timer_init(&dispatch->arbitration.arbitration_timer,
1788 evdev_libinput_context(device),
1790 fallback_arbitration_timeout,
1792 dispatch->arbitration.in_arbitration = false;
1795 struct evdev_dispatch *
1796 fallback_dispatch_create(struct libinput_device *libinput_device)
1798 struct evdev_device *device = evdev_device(libinput_device);
1799 struct fallback_dispatch *dispatch;
1801 dispatch = zalloc(sizeof *dispatch);
1802 dispatch->device = evdev_device(libinput_device);
1803 dispatch->base.dispatch_type = DISPATCH_FALLBACK;
1804 dispatch->base.interface = &fallback_interface;
1805 dispatch->pending_event = EVDEV_NONE;
1806 list_init(&dispatch->lid.paired_keyboard_list);
1808 fallback_dispatch_init_rel(dispatch, device);
1809 fallback_dispatch_init_abs(dispatch, device);
1810 if (fallback_dispatch_init_slots(dispatch, device) == -1) {
1815 fallback_dispatch_init_switch(dispatch, device);
1817 if (device->left_handed.want_enabled)
1818 evdev_init_left_handed(device,
1819 fallback_change_to_left_handed);
1821 if (device->scroll.want_button)
1822 evdev_init_button_scroll(device,
1823 fallback_change_scroll_method);
1825 if (device->scroll.natural_scrolling_enabled)
1826 evdev_init_natural_scroll(device);
1828 evdev_init_calibration(device, &dispatch->calibration);
1829 evdev_init_sendevents(device, &dispatch->base);
1830 fallback_init_rotation(dispatch, device);
1832 /* BTN_MIDDLE is set on mice even when it's not present. So
1833 * we can only use the absence of BTN_MIDDLE to mean something, i.e.
1834 * we enable it by default on anything that only has L&R.
1835 * If we have L&R and no middle, we don't expose it as config
1837 if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) &&
1838 libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) {
1839 bool has_middle = libevdev_has_event_code(device->evdev,
1842 bool want_config = has_middle;
1843 bool enable_by_default = !has_middle;
1845 evdev_init_middlebutton(device,
1850 fallback_init_wheel(dispatch, device);
1851 fallback_init_debounce(dispatch);
1852 fallback_init_arbitration(dispatch, device);
1854 dispatch->base.device_interface = &fallback_device_interface;
1856 return &dispatch->base;