Lines Matching refs:tp

62 tp_filter_motion(struct tp_dispatch *tp,
73 raw = tp_scale_to_xaxis(tp, *unaccelerated);
75 return filter_dispatch(tp->device->pointer.filter,
76 &raw, tp, time);
80 tp_filter_motion_unaccelerated(struct tp_dispatch *tp,
91 raw = tp_scale_to_xaxis(tp, *unaccelerated);
93 return filter_dispatch_constant(tp->device->pointer.filter,
94 &raw, tp, time);
98 tp_filter_scroll(struct tp_dispatch *tp,
109 raw = tp_scale_to_xaxis(tp, *unaccelerated);
111 return filter_dispatch_scroll(tp->device->pointer.filter,
112 &raw, tp, time);
116 tp_calculate_motion_speed(struct tp_dispatch *tp,
127 if (!tp->has_mt || tp->semi_mt)
150 mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
184 tp_detect_wobbling(struct tp_dispatch *tp,
192 if (tp->nfingers_down != 1 ||
193 tp->nfingers_down != tp->old_nfingers_down)
196 if (tp->hysteresis.enabled || t->history.count == 0)
199 if (!(tp->queued & TOUCHPAD_EVENT_MOTION)) {
207 dtime = time - tp->hysteresis.last_motion_time;
209 tp->hysteresis.last_motion_time = time;
222 tp->hysteresis.enabled = true;
223 evdev_log_debug(tp->device,
232 tp_motion_hysteresis(struct tp_dispatch *tp,
235 if (!tp->hysteresis.enabled)
241 &tp->hysteresis.margin);
253 tp_current_touch(struct tp_dispatch *tp)
255 return &tp->touches[min(tp->slot, tp->ntouches - 1)];
259 tp_get_touch(struct tp_dispatch *tp, unsigned int slot)
261 assert(slot < tp->ntouches);
262 return &tp->touches[slot];
266 tp_fake_finger_count(struct tp_dispatch *tp)
269 tp->fake_touches & ~(FAKE_FINGER_OVERFLOW|0x1);
274 evdev_log_bug_kernel(tp->device,
276 tp->fake_touches);
278 if (tp->fake_touches & FAKE_FINGER_OVERFLOW)
282 return ffs(tp->fake_touches >> 1);
286 tp_fake_finger_is_touching(struct tp_dispatch *tp)
288 return tp->fake_touches & 0x1;
292 tp_fake_finger_set(struct tp_dispatch *tp,
301 tp->fake_touches &= ~FAKE_FINGER_OVERFLOW;
317 tp->fake_touches |= FAKE_FINGER_OVERFLOW;
324 tp->fake_touches &= ~FAKE_FINGER_OVERFLOW;
325 tp->fake_touches |= bit(shift);
328 tp->fake_touches &= ~bit(shift);
333 tp_new_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
343 evdev_log_bug_kernel(tp->device,
346 tp->nfingers_down++;
365 tp->queued |= TOUCHPAD_EVENT_MOTION;
369 tp_begin_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
375 tp->nfingers_down++;
380 assert(tp->nfingers_down >= 1);
381 tp->hysteresis.last_motion_time = time;
393 tp_maybe_end_touch(struct tp_dispatch *tp,
402 evdev_log_bug_libinput(tp->device,
413 assert(tp->nfingers_down >= 1);
414 tp->nfingers_down--;
428 tp_recover_ended_touch(struct tp_dispatch *tp,
433 tp->nfingers_down++;
441 tp_end_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
444 evdev_log_bug_libinput(tp->device,
457 tp->queued |= TOUCHPAD_EVENT_MOTION;
464 tp_end_sequence(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
467 tp_maybe_end_touch(tp, t, time);
471 tp_stop_actions(struct tp_dispatch *tp, uint64_t time)
473 tp_edge_scroll_stop_events(tp, time);
474 tp_gesture_cancel(tp, time);
475 tp_tap_suspend(tp, time);
496 rotated(struct tp_dispatch *tp, unsigned int code, int value)
500 if (!tp->left_handed.rotate)
506 absinfo = tp->device->abs.absinfo_x;
510 absinfo = tp->device->abs.absinfo_y;
519 tp_process_absolute(struct tp_dispatch *tp,
523 struct tp_touch *t = tp_current_touch(tp);
527 evdev_device_check_abs_axis_range(tp->device,
530 t->point.x = rotated(tp, e->code, e->value);
532 tp->queued |= TOUCHPAD_EVENT_MOTION;
535 evdev_device_check_abs_axis_range(tp->device,
538 t->point.y = rotated(tp, e->code, e->value);
540 tp->queued |= TOUCHPAD_EVENT_MOTION;
543 tp->slot = e->value;
547 tp->nactive_slots += 1;
548 tp_new_touch(tp, t, time);
550 assert(tp->nactive_slots >= 1);
551 tp->nactive_slots -= 1;
552 tp_end_sequence(tp, t, time);
558 tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
563 tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
568 tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
573 tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
579 tp_process_absolute_st(struct tp_dispatch *tp,
583 struct tp_touch *t = tp_current_touch(tp);
587 evdev_device_check_abs_axis_range(tp->device,
590 t->point.x = rotated(tp, e->code, e->value);
592 tp->queued |= TOUCHPAD_EVENT_MOTION;
595 evdev_device_check_abs_axis_range(tp->device,
598 t->point.y = rotated(tp, e->code, e->value);
600 tp->queued |= TOUCHPAD_EVENT_MOTION;
605 tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
611 tp_restore_synaptics_touches(struct tp_dispatch *tp,
617 nfake_touches = tp_fake_finger_count(tp);
621 if (tp->nfingers_down >= nfake_touches ||
622 (tp->nfingers_down == tp->num_slots && nfake_touches == tp->num_slots))
634 for (i = 0; i < tp->num_slots; i++) {
635 struct tp_touch *t = tp_get_touch(tp, i);
641 tp_recover_ended_touch(tp, t);
646 tp_process_fake_touches(struct tp_dispatch *tp,
653 nfake_touches = tp_fake_finger_count(tp);
657 if (tp->device->model_flags &
659 tp_restore_synaptics_touches(tp, time);
683 if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD &&
684 nfake_touches > 1 && tp->has_mt &&
685 tp->nactive_slots > 0 &&
686 nfake_touches > tp->nactive_slots &&
687 tp->nactive_slots < tp->num_slots) {
688 evdev_log_bug_kernel(tp->device,
690 tp->num_slots,
691 tp->nactive_slots);
698 tp->num_slots = tp->nactive_slots;
701 start = tp->has_mt ? tp->num_slots : 0;
702 for (i = start; i < tp->ntouches; i++) {
703 t = tp_get_touch(tp, i);
705 tp_new_touch(tp, t, time);
707 tp_end_sequence(tp, t, time);
712 tp_process_trackpoint_button(struct tp_dispatch *tp,
726 if (!tp->buttons.trackpoint)
729 dispatch = tp->buttons.trackpoint->dispatch;
750 tp->buttons.trackpoint,
753 tp->buttons.trackpoint,
758 tp_process_key(struct tp_dispatch *tp,
770 tp_process_button(tp, e, time);
778 tp_fake_finger_set(tp, e->code, !!e->value);
783 tp_process_trackpoint_button(tp, e, time);
789 tp_process_msc(struct tp_dispatch *tp,
796 tp->quirks.msc_timestamp.now = e->value;
797 tp->queued |= TOUCHPAD_EVENT_TIMESTAMP;
801 tp_unpin_finger(const struct tp_dispatch *tp, struct tp_touch *t)
812 mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
822 tp_pin_fingers(struct tp_dispatch *tp)
826 tp_for_each_touch(tp, t) {
833 tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t)
838 !tp_thumb_ignored(tp, t) &&
839 tp_button_touch_active(tp, t) &&
840 tp_edge_scroll_touch_active(tp, t);
844 tp_touch_active_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t)
849 !tp_thumb_ignored_for_gesture(tp, t) &&
850 tp_button_touch_active(tp, t) &&
851 tp_edge_scroll_touch_active(tp, t);
855 tp_palm_was_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
857 return t->palm.first.x < tp->palm.left_edge ||
858 t->palm.first.x > tp->palm.right_edge;
862 tp_palm_was_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
864 return t->palm.first.y < tp->palm.upper_edge;
868 tp_palm_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
870 return t->point.x < tp->palm.left_edge ||
871 t->point.x > tp->palm.right_edge;
875 tp_palm_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
877 return t->point.y < tp->palm.upper_edge;
881 tp_palm_in_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
883 return tp_palm_in_side_edge(tp, t) || tp_palm_in_top_edge(tp, t);
887 tp_palm_detect_dwt_triggered(struct tp_dispatch *tp,
891 if (tp->dwt.dwt_enabled &&
892 tp->dwt.keyboard_active &&
899 if (!tp->dwt.keyboard_active &&
909 t->palm.time > tp->dwt.keyboard_last_press_time) {
911 evdev_log_debug(tp->device,
921 tp_palm_detect_trackpoint_triggered(struct tp_dispatch *tp,
925 if (!tp->palm.monitor_trackpoint)
930 tp->palm.trackpoint_active) {
937 !tp->palm.trackpoint_active) {
940 t->palm.time > tp->palm.trackpoint_last_event_time) {
942 evdev_log_debug(tp->device,
951 tp_palm_detect_tool_triggered(struct tp_dispatch *tp,
955 if (!tp->palm.use_mt_tool)
973 tp_palm_detect_move_out_of_edge(struct tp_dispatch *tp,
982 if (time < t->palm.time + PALM_TIMEOUT && !tp_palm_in_edge(tp, t)) {
983 if (tp_palm_was_in_side_edge(tp, t))
985 else if (tp_palm_was_in_top_edge(tp, t))
990 dirs = phys_get_direction(tp_phys_delta(tp, delta));
1000 tp_palm_detect_multifinger(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
1004 if (tp->nfingers_down < 2)
1015 tp_for_each_touch(tp, other) {
1019 if (tp_touch_active(tp, other) &&
1029 tp_palm_detect_touch_size_triggered(struct tp_dispatch *tp,
1033 if (!tp->palm.use_size)
1041 if (t->major > tp->palm.size_threshold ||
1042 t->minor > tp->palm.size_threshold) {
1044 evdev_log_debug(tp->device,
1055 tp_palm_detect_edge(struct tp_dispatch *tp,
1060 if (tp_palm_detect_multifinger(tp, t, time)) {
1062 evdev_log_debug(tp->device,
1070 } else if (tp_palm_detect_move_out_of_edge(tp, t, time)) {
1072 evdev_log_debug(tp->device,
1079 if (tp_palm_detect_multifinger(tp, t, time)) {
1085 if (t->state != TOUCH_BEGIN || !tp_palm_in_edge(tp, t))
1088 if (tp_touch_get_edge(tp, t) & EDGE_RIGHT)
1099 tp_palm_detect_pressure_triggered(struct tp_dispatch *tp,
1103 if (!tp->palm.use_pressure)
1110 if (t->pressure > tp->palm.pressure_threshold)
1117 tp_palm_detect_arbitration_triggered(struct tp_dispatch *tp,
1121 if (tp->arbitration.state == ARBITRATION_NOT_ACTIVE)
1130 tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
1135 if (tp_palm_detect_pressure_triggered(tp, t, time))
1138 if (tp_palm_detect_arbitration_triggered(tp, t, time))
1141 if (tp_palm_detect_dwt_triggered(tp, t, time))
1144 if (tp_palm_detect_trackpoint_triggered(tp, t, time))
1147 if (tp_palm_detect_tool_triggered(tp, t, time))
1150 if (tp_palm_detect_touch_size_triggered(tp, t, time))
1153 if (tp_palm_detect_edge(tp, t, time))
1162 if (tp_palm_detect_pressure_triggered(tp, t, time))
1198 evdev_log_debug(tp->device,
1206 tp_unhover_pressure(struct tp_dispatch *tp, uint64_t time)
1213 nfake_touches = tp_fake_finger_count(tp);
1217 for (i = 0; i < (int)tp->num_slots; i++) {
1218 t = tp_get_touch(tp, i);
1225 if (t->pressure >= tp->pressure.high) {
1226 evdev_log_debug(tp->device,
1231 tp_begin_touch(tp, t, time);
1238 } else if (nfake_touches <= tp->num_slots ||
1239 tp->num_slots == 1) {
1240 if (t->pressure < tp->pressure.low) {
1241 evdev_log_debug(tp->device,
1244 tp_maybe_end_touch(tp, t, time);
1254 if (nfake_touches <= tp->num_slots ||
1255 tp->nfingers_down == 0)
1263 tp_for_each_touch(tp, t) {
1267 tp_begin_touch(tp, t, time);
1269 if (tp->nfingers_down >= nfake_touches)
1275 if (tp->nfingers_down > nfake_touches ||
1277 for (i = tp->ntouches - 1; i >= 0; i--) {
1278 t = tp_get_touch(tp, i);
1285 tp_maybe_end_touch(tp, t, time);
1288 tp->nfingers_down == nfake_touches)
1295 tp_unhover_size(struct tp_dispatch *tp, uint64_t time)
1298 int low = tp->touch_size.low,
1299 high = tp->touch_size.high;
1305 for (i = 0; i < (int)tp->num_slots; i++) {
1306 t = tp_get_touch(tp, i);
1317 evdev_log_debug(tp->device,
1322 tp_begin_touch(tp, t, time);
1326 evdev_log_debug(tp->device,
1329 tp_maybe_end_touch(tp, t, time);
1336 tp_unhover_fake_touches(struct tp_dispatch *tp, uint64_t time)
1342 if (!tp->fake_touches && !tp->nfingers_down)
1345 nfake_touches = tp_fake_finger_count(tp);
1349 if (tp->nfingers_down == nfake_touches &&
1350 ((tp->nfingers_down == 0 && !tp_fake_finger_is_touching(tp)) ||
1351 (tp->nfingers_down > 0 && tp_fake_finger_is_touching(tp))))
1358 if (tp_fake_finger_is_touching(tp) &&
1359 tp->nfingers_down < nfake_touches) {
1360 tp_for_each_touch(tp, t) {
1362 tp_begin_touch(tp, t, time);
1364 if (tp->nfingers_down >= nfake_touches)
1374 if (tp->nfingers_down > nfake_touches ||
1375 !tp_fake_finger_is_touching(tp)) {
1376 for (i = tp->ntouches - 1; i >= 0; i--) {
1377 t = tp_get_touch(tp, i);
1383 tp_maybe_end_touch(tp, t, time);
1385 if (tp_fake_finger_is_touching(tp) &&
1386 tp->nfingers_down == nfake_touches)
1393 tp_unhover_touches(struct tp_dispatch *tp, uint64_t time)
1395 if (tp->pressure.use_pressure)
1396 tp_unhover_pressure(tp, time);
1397 else if (tp->touch_size.use_touch_size)
1398 tp_unhover_size(tp, time);
1400 tp_unhover_fake_touches(tp, time);
1405 tp_position_fake_touches(struct tp_dispatch *tp)
1411 if (tp_fake_finger_count(tp) <= tp->num_slots ||
1412 tp->nfingers_down == 0)
1419 for (i = 0; i < tp->num_slots; i++) {
1420 t = tp_get_touch(tp, i);
1430 evdev_log_bug_libinput(tp->device,
1435 start = tp->has_mt ? tp->num_slots : 1;
1436 for (i = start; i < tp->ntouches; i++) {
1437 t = tp_get_touch(tp, i);
1449 tp_need_motion_history_reset(struct tp_dispatch *tp)
1457 if (tp->nfingers_down != tp->old_nfingers_down)
1465 if (tp->device->model_flags & EVDEV_MODEL_LENOVO_T450_TOUCHPAD) {
1466 if (tp->queued & TOUCHPAD_EVENT_MOTION) {
1467 if (tp->quirks.nonmotion_event_count > 10) {
1468 tp->queued &= ~TOUCHPAD_EVENT_MOTION;
1471 tp->quirks.nonmotion_event_count = 0;
1474 if ((tp->queued & (TOUCHPAD_EVENT_OTHERAXIS|TOUCHPAD_EVENT_MOTION)) ==
1476 tp->quirks.nonmotion_event_count++;
1483 tp_detect_jumps(const struct tp_dispatch *tp,
1501 if (tp->jump.detection_disabled)
1507 if (tp->device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD)
1522 if (tp->device->model_flags & EVDEV_MODEL_TEST_DEVICE)
1536 mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
1547 if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD &&
1576 tp_motion_history_fix_last(struct tp_dispatch *tp,
1601 tp_process_msc_timestamp(struct tp_dispatch *tp, uint64_t time)
1603 struct msc_timestamp *m = &tp->quirks.msc_timestamp;
1659 tp_for_each_touch(tp, t) {
1660 tp_motion_history_fix_last(tp,
1674 filter_restart(tp->device->pointer.filter, tp, time - tdelta);
1683 tp_pre_process_state(struct tp_dispatch *tp, uint64_t time)
1687 if (tp->queued & TOUCHPAD_EVENT_TIMESTAMP)
1688 tp_process_msc_timestamp(tp, time);
1690 tp_process_fake_touches(tp, time);
1691 tp_unhover_touches(tp, time);
1693 tp_for_each_touch(tp, t) {
1695 tp_end_touch(tp, t, time);
1706 tp_process_state(struct tp_dispatch *tp, uint64_t time)
1714 tp_position_fake_touches(tp);
1716 want_motion_reset = tp_need_motion_history_reset(tp);
1718 tp_for_each_touch(tp, t) {
1746 if (tp_detect_jumps(tp, t, time)) {
1747 if (!tp->semi_mt)
1748 evdev_log_bug_kernel_ratelimit(tp->device,
1749 &tp->jump.warning,
1756 tp_thumb_update_touch(tp, t, time);
1757 tp_palm_detect(tp, t, time);
1758 tp_detect_wobbling(tp, t, time);
1759 tp_motion_hysteresis(tp, t);
1784 tp_calculate_motion_speed(tp, t, time);
1786 tp_unpin_finger(tp, t);
1794 if (tp->thumb.detect_thumbs &&
1796 tp->nfingers_down >= 2)
1797 tp_thumb_update_multifinger(tp);
1800 filter_restart(tp->device->pointer.filter, tp, time);
1802 tp_button_handle_state(tp, time);
1803 tp_edge_scroll_handle_state(tp, time);
1811 if ((tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) &&
1812 tp->buttons.is_clickpad)
1813 tp_pin_fingers(tp);
1815 tp_gesture_handle_state(tp, time);
1819 tp_post_process_state(struct tp_dispatch *tp, uint64_t time)
1823 tp_for_each_touch(tp, t) {
1840 tp->old_nfingers_down = tp->nfingers_down;
1841 tp->buttons.old_state = tp->buttons.state;
1843 tp->queued = TOUCHPAD_EVENT_NONE;
1845 if (tp->nfingers_down == 0)
1846 tp_thumb_reset(tp);
1848 tp_tap_post_process_state(tp);
1852 tp_post_events(struct tp_dispatch *tp, uint64_t time)
1857 if (tp->device->is_suspended) {
1858 tp_post_button_events(tp, time);
1862 ignore_motion |= tp_tap_handle_state(tp, time);
1863 ignore_motion |= tp_post_button_events(tp, time);
1865 if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) {
1866 tp_edge_scroll_stop_events(tp, time);
1867 tp_gesture_cancel(tp, time);
1872 tp_edge_scroll_stop_events(tp, time);
1873 tp_gesture_cancel_motion_gestures(tp, time);
1874 tp_gesture_post_events(tp, time, true);
1878 if (tp_edge_scroll_post_events(tp, time) != 0)
1881 tp_gesture_post_events(tp, time, false);
1887 struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
1889 if (tp->left_handed.want_rotate == tp->left_handed.rotate)
1892 if (tp->nfingers_down)
1895 tp->left_handed.rotate = tp->left_handed.want_rotate;
1899 tp->left_handed.rotate ? "on" : "off");
1903 tp_handle_state(struct tp_dispatch *tp,
1906 tp_pre_process_state(tp, time);
1907 tp_process_state(tp, time);
1908 tp_post_events(tp, time);
1909 tp_post_process_state(tp, time);
1911 tp_clickpad_middlebutton_apply_config(tp->device);
1912 tp_apply_rotation(tp->device);
1917 tp_debug_touch_state(struct tp_dispatch *tp,
1924 tp_for_each_touch(tp, t) {
1925 if (i >= tp->nfingers_down)
1933 tp_touch_active(tp, t) ? "" : "inactive");
1945 struct tp_dispatch *tp = tp_dispatch(dispatch);
1949 if (tp->has_mt)
1950 tp_process_absolute(tp, e, time);
1952 tp_process_absolute_st(tp, e, time);
1955 tp_process_key(tp, e, time);
1958 tp_process_msc(tp, e, time);
1961 tp_handle_state(tp, time);
1963 tp_debug_touch_state(tp, device);
1970 tp_remove_sendevents(struct tp_dispatch *tp)
1974 libinput_timer_cancel(&tp->palm.trackpoint_timer);
1975 libinput_timer_cancel(&tp->dwt.keyboard_timer);
1977 if (tp->buttons.trackpoint &&
1978 tp->palm.monitor_trackpoint)
1980 &tp->palm.trackpoint_listener);
1982 list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) {
1986 if (tp->lid_switch.lid_switch)
1988 &tp->lid_switch.listener);
1990 if (tp->tablet_mode_switch.tablet_mode_switch)
1992 &tp->tablet_mode_switch.listener);
1998 struct tp_dispatch *tp = tp_dispatch(dispatch);
2001 libinput_timer_cancel(&tp->arbitration.arbitration_timer);
2003 list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) {
2006 tp->dwt.keyboard_active = false;
2008 tp_remove_tap(tp);
2009 tp_remove_buttons(tp);
2010 tp_remove_sendevents(tp);
2011 tp_remove_edge_scroll(tp);
2012 tp_remove_gesture(tp);
2018 struct tp_dispatch *tp = tp_dispatch(dispatch);
2020 libinput_timer_destroy(&tp->arbitration.arbitration_timer);
2021 libinput_timer_destroy(&tp->palm.trackpoint_timer);
2022 libinput_timer_destroy(&tp->dwt.keyboard_timer);
2023 libinput_timer_destroy(&tp->tap.timer);
2024 libinput_timer_destroy(&tp->gesture.finger_count_switch_timer);
2025 libinput_timer_destroy(&tp->gesture.hold_timer);
2026 free(tp->touches);
2027 free(tp);
2031 tp_release_fake_touches(struct tp_dispatch *tp)
2033 tp->fake_touches = 0;
2037 tp_clear_state(struct tp_dispatch *tp)
2039 uint64_t now = libinput_now(tp_libinput_context(tp));
2043 * Release buttons first. If tp is a clickpad, the button event
2055 tp_release_all_buttons(tp, now);
2056 tp_release_all_taps(tp, now);
2058 tp_for_each_touch(tp, t) {
2059 tp_end_sequence(tp, t, now);
2061 tp_release_fake_touches(tp);
2063 tp_thumb_reset(tp);
2065 tp_handle_state(tp, now);
2069 tp_suspend(struct tp_dispatch *tp,
2073 if (tp->suspend_reason & trigger)
2076 if (tp->suspend_reason != 0)
2079 tp_clear_state(tp);
2085 if (tp->buttons.has_topbuttons) {
2088 tp_init_top_softbuttons(tp, device, 3.0);
2094 tp->suspend_reason |= trigger;
2101 struct tp_dispatch *tp = tp_dispatch(dispatch);
2103 tp_clear_state(tp);
2107 tp_sync_touch(struct tp_dispatch *tp,
2148 tp->nactive_slots++;
2152 tp_sync_slots(struct tp_dispatch *tp,
2157 tp_sync_touch(tp, device, &tp->touches[0], 0);
2158 for (unsigned int i = 1; i < tp->num_slots; i++)
2159 tp_sync_touch(tp, device, &tp->touches[i], i);
2163 tp_resume(struct tp_dispatch *tp,
2167 tp->suspend_reason &= ~trigger;
2168 if (tp->suspend_reason != 0)
2171 if (tp->buttons.has_topbuttons) {
2173 tp_clear_state(tp);
2175 tp_init_top_softbuttons(tp, device, 1.0);
2181 tp_sync_slots(tp, device);
2187 struct tp_dispatch *tp = data;
2189 if (tp->palm.trackpoint_active) {
2190 tp_tap_resume(tp, now);
2191 tp->palm.trackpoint_active = false;
2193 tp->palm.trackpoint_event_count = 0;
2199 struct tp_dispatch *tp = data;
2201 if (!tp->palm.dwtp_enabled)
2209 tp->palm.trackpoint_last_event_time = time;
2210 tp->palm.trackpoint_event_count++;
2213 if (tp->palm.trackpoint_event_count < 3) {
2214 libinput_timer_set(&tp->palm.trackpoint_timer,
2219 if (!tp->palm.trackpoint_active) {
2220 tp_stop_actions(tp, time);
2221 tp->palm.trackpoint_active = true;
2224 libinput_timer_set(&tp->palm.trackpoint_timer,
2231 struct tp_dispatch *tp = data;
2233 if (tp->dwt.dwt_enabled &&
2234 long_any_bit_set(tp->dwt.key_mask,
2235 ARRAY_LENGTH(tp->dwt.key_mask))) {
2236 libinput_timer_set(&tp->dwt.keyboard_timer,
2238 tp->dwt.keyboard_last_press_time = now;
2239 evdev_log_debug(tp->device, "palm: keyboard timeout refresh\n");
2243 tp_tap_resume(tp, now);
2245 tp->dwt.keyboard_active = false;
2247 evdev_log_debug(tp->device, "palm: keyboard timeout\n");
2295 struct tp_dispatch *tp = data;
2310 long_clear_bit(tp->dwt.key_mask, key);
2311 long_clear_bit(tp->dwt.mod_mask, key);
2315 if (!tp->dwt.dwt_enabled)
2325 long_set_bit(tp->dwt.mod_mask, key);
2329 if (!tp->dwt.keyboard_active) {
2335 if (long_any_bit_set(tp->dwt.mod_mask,
2336 ARRAY_LENGTH(tp->dwt.mod_mask)))
2339 tp_stop_actions(tp, time);
2340 tp->dwt.keyboard_active = true;
2346 tp->dwt.keyboard_last_press_time = time;
2347 long_set_bit(tp->dwt.key_mask, key);
2348 libinput_timer_set(&tp->dwt.keyboard_timer,
2378 struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
2388 list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) {
2401 tp_keyboard_event, tp);
2402 list_insert(&tp->dwt.paired_keyboard_list, &kbd->link);
2413 struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
2423 if (tp->buttons.trackpoint == NULL &&
2426 tp->buttons.active_is_topbutton = false;
2427 tp->buttons.trackpoint = trackpoint;
2428 if (tp->palm.monitor_trackpoint)
2430 &tp->palm.trackpoint_listener,
2431 tp_trackpoint_event, tp);
2438 struct tp_dispatch *tp = data;
2450 tp_resume(tp, tp->device, SUSPEND_LID);
2451 evdev_log_debug(tp->device, "lid: resume touchpad\n");
2454 tp_suspend(tp, tp->device, SUSPEND_LID);
2455 evdev_log_debug(tp->device, "lid: suspending touchpad\n");
2465 struct tp_dispatch *tp = data;
2478 tp_resume(tp, tp->device, SUSPEND_TABLET_MODE);
2479 evdev_log_debug(tp->device, "tablet-mode: resume touchpad\n");
2482 tp_suspend(tp, tp->device, SUSPEND_TABLET_MODE);
2483 evdev_log_debug(tp->device, "tablet-mode: suspending touchpad\n");
2492 struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
2500 if (tp->lid_switch.lid_switch == NULL) {
2507 &tp->lid_switch.listener,
2508 tp_lid_switch_event, tp);
2509 tp->lid_switch.lid_switch = lid_switch;
2517 struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
2522 if (tp->tablet_mode_switch.tablet_mode_switch)
2538 &tp->tablet_mode_switch.listener,
2539 tp_tablet_mode_switch_event, tp);
2540 tp->tablet_mode_switch.tablet_mode_switch = tablet_mode_switch;
2545 tp_suspend(tp, touchpad, SUSPEND_TABLET_MODE);
2552 struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
2553 struct evdev_device *tablet_device = tp->left_handed.tablet_device;
2556 if (!tp->left_handed.must_rotate)
2560 tablet_is_left = tp->left_handed.tablet_left_handed_state;
2562 tp->left_handed.want_rotate = touchpad_is_left || tablet_is_left;
2572 tp->left_handed.want_rotate);
2580 struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
2582 if (!tp->left_handed.must_rotate)
2592 tp->left_handed.tablet_device = tablet;
2600 tp->left_handed.want_rotate = true;
2601 tp->left_handed.tablet_left_handed_state = true;
2610 struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
2618 if (tp->sendevents.current_mode !=
2623 tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE);
2630 struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
2633 if (removed_device == tp->buttons.trackpoint) {
2635 if (tp->buttons.active && tp->buttons.active_is_topbutton) {
2636 tp->buttons.active = 0;
2637 tp->buttons.active_is_topbutton = false;
2639 if (tp->palm.monitor_trackpoint)
2641 &tp->palm.trackpoint_listener);
2642 tp->buttons.trackpoint = NULL;
2645 list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) {
2648 tp->dwt.keyboard_active = false;
2652 if (removed_device == tp->lid_switch.lid_switch) {
2654 &tp->lid_switch.listener);
2655 tp->lid_switch.lid_switch = NULL;
2656 tp_resume(tp, device, SUSPEND_LID);
2659 if (removed_device == tp->tablet_mode_switch.tablet_mode_switch) {
2661 &tp->tablet_mode_switch.listener);
2662 tp->tablet_mode_switch.tablet_mode_switch = NULL;
2663 tp_resume(tp, device, SUSPEND_TABLET_MODE);
2666 if (tp->sendevents.current_mode ==
2680 tp_resume(tp, device, SUSPEND_EXTERNAL_MOUSE);
2683 if (removed_device == tp->left_handed.tablet_device) {
2684 tp->left_handed.tablet_device = NULL;
2685 tp->left_handed.tablet_left_handed_state = false;
2776 struct tp_dispatch *tp = data;
2778 if (tp->arbitration.state != ARBITRATION_NOT_ACTIVE)
2779 tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
2789 struct tp_dispatch *tp = tp_dispatch(dispatch);
2791 if (which == tp->arbitration.state)
2797 libinput_timer_cancel(&tp->arbitration.arbitration_timer);
2798 tp_clear_state(tp);
2799 tp->arbitration.state = which;
2809 libinput_timer_set(&tp->arbitration.arbitration_timer,
2821 struct tp_dispatch *tp = tp_dispatch(dispatch);
2823 if (!tp->left_handed.tablet_device)
2835 tp->left_handed.tablet_left_handed_state = left_handed_enabled;
2856 tp_init_touch(struct tp_dispatch *tp,
2860 t->tp = tp;
2876 tp_init_slots(struct tp_dispatch *tp,
2893 tp->num_slots = absinfo->maximum + 1;
2894 tp->slot = absinfo->value;
2895 tp->has_mt = true;
2897 tp->num_slots = 1;
2898 tp->slot = 0;
2899 tp->has_mt = false;
2902 tp->semi_mt = libevdev_has_property(device->evdev, INPUT_PROP_SEMI_MT);
2922 if (tp->semi_mt ||
2923 evdev_device_has_model_quirk(tp->device,
2925 tp->num_slots = 1;
2926 tp->slot = 0;
2927 tp->has_mt = false;
2930 if (!tp->has_mt)
2942 tp->ntouches = max(tp->num_slots, n_btn_tool_touches);
2943 tp->touches = zalloc(tp->ntouches * sizeof(struct tp_touch));
2945 for (i = 0; i < tp->ntouches; i++)
2946 tp_init_touch(tp, &tp->touches[i], i);
2948 tp_sync_slots(tp, device);
2956 tp_fake_finger_set(tp, BTN_TOOL_FINGER, 1);
2966 tp_init_accel(struct tp_dispatch *tp, enum libinput_config_accel_profile which)
2968 struct evdev_device *device = tp->device;
2974 res_x = tp->device->abs.absinfo_x->resolution;
2975 res_y = tp->device->abs.absinfo_y->resolution;
2984 tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
2985 tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
2986 tp->accel.xy_scale_coeff = 1.0 * res_x/res_y;
2993 tp->device->model_flags & EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81) {
3012 evdev_device_init_pointer_acceleration(tp->device, filter);
3035 struct tp_dispatch *tp = tp_dispatch(device->dispatch);
3046 if (tp_init_accel(tp, profile)) {
3058 tp_scroll_get_methods(struct tp_dispatch *tp)
3065 if (evdev_device_has_model_quirk(tp->device,
3069 if (tp->ntouches >= 2)
3079 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3081 return tp_scroll_get_methods(tp);
3089 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3090 uint64_t time = libinput_now(tp_libinput_context(tp));
3092 if (method == tp->scroll.method)
3095 tp_edge_scroll_stop_events(tp, time);
3096 tp_gesture_stop_twofinger_scroll(tp, time);
3098 tp->scroll.method = method;
3107 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3109 return tp->scroll.method;
3113 tp_scroll_get_default_method(struct tp_dispatch *tp)
3118 methods = tp_scroll_get_methods(tp);
3126 evdev_log_bug_libinput(tp->device,
3136 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3138 return tp_scroll_get_default_method(tp);
3151 tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device)
3153 tp_edge_scroll_init(tp, device);
3160 tp->scroll.config_method.get_methods = tp_scroll_config_scroll_method_get_methods;
3161 tp->scroll.config_method.set_method = tp_scroll_config_scroll_method_set_method;
3162 tp->scroll.config_method.get_method = tp_scroll_config_scroll_method_get_method;
3163 tp->scroll.config_method.get_default_method = tp_scroll_config_scroll_method_get_default_method;
3164 tp->scroll.method = tp_scroll_get_default_method(tp);
3165 tp->device->base.config.scroll_method = &tp->scroll.config_method;
3168 tp->device->scroll.threshold = 0.0;
3169 tp->device->scroll.direction_lock_threshold = 5.0;
3183 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3193 tp->dwt.dwt_enabled = (enable == LIBINPUT_CONFIG_DWT_ENABLED);
3202 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3204 return tp->dwt.dwt_enabled ?
3210 tp_dwt_default_enabled(struct tp_dispatch *tp)
3219 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3221 return tp_dwt_default_enabled(tp) ?
3237 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3247 tp->palm.dwtp_enabled = (enable == LIBINPUT_CONFIG_DWTP_ENABLED);
3256 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3258 return tp->palm.dwtp_enabled ?
3264 tp_dwtp_default_enabled(struct tp_dispatch *tp)
3273 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3275 return tp_dwtp_default_enabled(tp) ?
3311 tp_init_dwt(struct tp_dispatch *tp,
3318 tp->dwt.config.is_available = tp_dwt_config_is_available;
3319 tp->dwt.config.set_enabled = tp_dwt_config_set;
3320 tp->dwt.config.get_enabled = tp_dwt_config_get;
3321 tp->dwt.config.get_default_enabled = tp_dwt_config_get_default;
3322 tp->dwt.dwt_enabled = tp_dwt_default_enabled(tp);
3323 device->base.config.dwt = &tp->dwt.config;
3327 tp_init_dwtp(struct tp_dispatch *tp,
3330 tp->palm.dwtp_enabled = tp_dwtp_default_enabled(tp);
3335 tp->palm.config.is_available = tp_dwtp_config_is_available;
3336 tp->palm.config.set_enabled = tp_dwtp_config_set;
3337 tp->palm.config.get_enabled = tp_dwtp_config_get;
3338 tp->palm.config.get_default_enabled = tp_dwtp_config_get_default;
3339 device->base.config.dwtp = &tp->palm.config;
3343 tp_init_palmdetect_edge(struct tp_dispatch *tp,
3368 tp->palm.left_edge = edges.x;
3372 tp->palm.right_edge = edges.x;
3374 if (!tp->buttons.has_topbuttons && height > 55) {
3378 tp->palm.upper_edge = edges.y;
3383 tp_read_palm_pressure_prop(struct tp_dispatch *tp,
3403 tp_init_palmdetect_pressure(struct tp_dispatch *tp,
3407 tp->palm.use_pressure = false;
3411 tp->palm.pressure_threshold = tp_read_palm_pressure_prop(tp, device);
3412 if (tp->palm.pressure_threshold != 0) {
3413 tp->palm.use_pressure = true;
3417 tp->palm.pressure_threshold);
3422 tp_init_palmdetect_size(struct tp_dispatch *tp,
3436 tp->palm.use_size = true;
3437 tp->palm.size_threshold = threshold;
3444 tp_init_palmdetect_arbitration(struct tp_dispatch *tp,
3453 libinput_timer_init(&tp->arbitration.arbitration_timer,
3454 tp_libinput_context(tp),
3456 tp_arbitration_timeout, tp);
3457 tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
3461 tp_init_palmdetect(struct tp_dispatch *tp,
3465 tp->palm.right_edge = INT_MAX;
3466 tp->palm.left_edge = INT_MIN;
3467 tp->palm.upper_edge = INT_MIN;
3469 tp_init_palmdetect_arbitration(tp, device);
3477 tp->palm.monitor_trackpoint = true;
3482 tp->palm.use_mt_tool = true;
3485 tp_init_palmdetect_edge(tp, device);
3486 tp_init_palmdetect_pressure(tp, device);
3487 tp_init_palmdetect_size(tp, device);
3491 tp_init_sendevents(struct tp_dispatch *tp,
3500 libinput_timer_init(&tp->palm.trackpoint_timer,
3501 tp_libinput_context(tp),
3503 tp_trackpoint_timeout, tp);
3509 libinput_timer_init(&tp->dwt.keyboard_timer,
3510 tp_libinput_context(tp),
3512 tp_keyboard_timeout, tp);
3516 tp_pass_sanity_check(struct tp_dispatch *tp,
3539 tp_init_default_resolution(struct tp_dispatch *tp,
3573 tp_init_hysteresis(struct tp_dispatch *tp)
3576 const struct input_absinfo *ax = tp->device->abs.absinfo_x,
3577 *ay = tp->device->abs.absinfo_y;
3589 tp->hysteresis.margin.x = xmargin;
3590 tp->hysteresis.margin.y = ymargin;
3591 tp->hysteresis.enabled = (ax->fuzz || ay->fuzz);
3592 if (tp->hysteresis.enabled)
3593 evdev_log_debug(tp->device,
3600 tp_init_pressure(struct tp_dispatch *tp,
3610 code = tp->has_mt ? ABS_MT_PRESSURE : ABS_PRESSURE;
3612 tp->pressure.use_pressure = false;
3646 tp->pressure.use_pressure = true;
3647 tp->pressure.high = hi;
3648 tp->pressure.low = lo;
3659 tp_init_touch_size(struct tp_dispatch *tp,
3696 tp->touch_size.low = lo;
3697 tp->touch_size.high = hi;
3698 tp->touch_size.use_touch_size = true;
3711 tp_init_pressurepad(struct tp_dispatch *tp,
3732 tp_init(struct tp_dispatch *tp,
3737 tp->base.dispatch_type = DISPATCH_TOUCHPAD;
3738 tp->base.interface = &tp_interface;
3739 tp->device = device;
3740 list_init(&tp->dwt.paired_keyboard_list);
3742 if (!tp_pass_sanity_check(tp, device))
3745 tp_init_default_resolution(tp, device);
3746 tp_init_pressurepad(tp, device);
3748 if (!tp_init_slots(tp, device))
3752 use_touch_size = tp_init_touch_size(tp, device);
3755 tp_init_pressure(tp, device);
3758 ratelimit_init(&tp->jump.warning, h2us(24), 5);
3764 tp_init_hysteresis(tp);
3766 if (!tp_init_accel(tp, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE))
3769 tp_init_tap(tp);
3770 tp_init_buttons(tp, device);
3771 tp_init_dwt(tp, device);
3772 tp_init_dwtp(tp, device);
3773 tp_init_palmdetect(tp, device);
3774 tp_init_sendevents(tp, device);
3775 tp_init_scroll(tp, device);
3776 tp_init_gesture(tp);
3777 tp_init_thumb(tp);
3785 tp->jump.detection_disabled = true;
3788 if (tp->gesture.enabled)
3807 tp_suspend_conditional(struct tp_dispatch *tp,
3815 tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE);
3826 struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
3833 if (mode == tp->sendevents.current_mode)
3838 tp_resume(tp, evdev, SUSPEND_SENDEVENTS);
3839 tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE);
3842 tp_suspend(tp, evdev, SUSPEND_SENDEVENTS);
3843 tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE);
3846 tp_suspend_conditional(tp, evdev);
3847 tp_resume(tp, evdev, SUSPEND_SENDEVENTS);
3853 tp->sendevents.current_mode = mode;
3876 struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
3881 if (tp->buttons.state & 0x3) /* BTN_LEFT|BTN_RIGHT */
3892 tp_requires_rotation(struct tp_dispatch *tp, struct evdev_device *device)
3896 struct libinput *li = tp_libinput_context(tp);
3951 tp_init_left_handed(struct tp_dispatch *tp,
3956 tp->left_handed.must_rotate = tp_requires_rotation(tp, device);
3968 struct tp_dispatch *tp;
3972 tp = zalloc(sizeof *tp);
3974 if (!tp_init(tp, device)) {
3975 tp_interface_destroy(&tp->base);
3979 device->base.config.sendevents = &tp->sendevents.config;
3981 tp->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
3982 tp->sendevents.config.get_modes = tp_sendevents_get_modes;
3983 tp->sendevents.config.set_mode = tp_sendevents_set_mode;
3984 tp->sendevents.config.get_mode = tp_sendevents_get_mode;
3985 tp->sendevents.config.get_default_mode = tp_sendevents_get_default_mode;
3987 tp_init_left_handed(tp, device);
3989 return &tp->base;