Lines Matching defs:tablet

25 #include "evdev-tablet.h"
41 /* The tablet sends events every ~2ms , 50ms should be plenty enough to
51 tablet_get_pressed_buttons(struct tablet_dispatch *tablet,
55 const struct button_state *state = &tablet->button_state,
56 *prev_state = &tablet->prev_button_state;
63 tablet_get_released_buttons(struct tablet_dispatch *tablet,
67 const struct button_state *state = &tablet->button_state,
68 *prev_state = &tablet->prev_button_state;
78 tablet_force_button_presses(struct tablet_dispatch *tablet)
80 struct button_state *state = &tablet->button_state,
81 *prev_state = &tablet->prev_button_state;
91 tablet_history_size(const struct tablet_dispatch *tablet)
93 return tablet->history.size;
97 tablet_history_reset(struct tablet_dispatch *tablet)
99 tablet->history.count = 0;
103 tablet_history_push(struct tablet_dispatch *tablet,
106 unsigned int index = (tablet->history.index + 1) %
107 tablet_history_size(tablet);
109 tablet->history.samples[index] = *axes;
110 tablet->history.index = index;
111 tablet->history.count = min(tablet->history.count + 1,
112 tablet_history_size(tablet));
114 if (tablet->history.count < tablet_history_size(tablet))
115 tablet_history_push(tablet, axes);
123 tablet_history_get(const struct tablet_dispatch *tablet, unsigned int index)
125 size_t sz = tablet_history_size(tablet);
128 assert(index < tablet->history.count);
130 index = (tablet->history.index + sz - index) % sz;
131 return &tablet->history.samples[index];
135 tablet_reset_changed_axes(struct tablet_dispatch *tablet)
137 memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
141 tablet_device_has_axis(struct tablet_dispatch *tablet,
144 struct libevdev *evdev = tablet->device->evdev;
177 tablet_filter_axis_fuzz(const struct tablet_dispatch *tablet,
185 previous = tablet->prev_value[axis];
207 tablet_process_absolute(struct tablet_dispatch *tablet,
231 tablet->prev_value[axis] = tablet->current_value[axis];
232 if (tablet_filter_axis_fuzz(tablet, device, e, axis))
235 tablet->current_value[axis] = e->value;
236 set_bit(tablet->changed_axes, axis);
237 tablet_set_status(tablet, TABLET_AXES_UPDATED);
242 tablet->current_tool.id = e->value;
266 struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
268 if (tablet->rotation.rotate == tablet->rotation.want_rotate)
271 if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
274 tablet->rotation.rotate = tablet->rotation.want_rotate;
277 "tablet-rotation: rotation is %s\n",
278 tablet->rotation.rotate ? "on" : "off");
284 struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
285 struct evdev_device *touch_device = tablet->touch_device;
289 tablet_is_left = tablet->device->left_handed.enabled;
290 touchpad_is_left = tablet->rotation.touch_device_left_handed_state;
292 tablet->rotation.want_rotate = tablet_is_left || touchpad_is_left;
318 tablet_update_tool(struct tablet_dispatch *tablet,
326 tablet->current_tool.type = tool;
327 tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
328 tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
330 else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
331 tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
407 convert_tilt_to_rotation(struct tablet_dispatch *tablet)
417 x = tablet->axes.tilt.x;
418 y = tablet->axes.tilt.y;
426 tablet->axes.rotation = angle;
427 set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
440 normalize_wheel(struct tablet_dispatch *tablet,
443 struct evdev_device *device = tablet->device;
449 tablet_update_xy(struct tablet_dispatch *tablet,
459 if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
460 bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
463 if (tablet->rotation.rotate)
468 tablet->axes.point.x = value;
472 if (tablet->rotation.rotate)
477 tablet->axes.point.y = value;
479 evdev_transform_absolute(device, &tablet->axes.point);
484 tablet_tool_process_delta(struct tablet_dispatch *tablet,
496 if (!tablet_has_status(tablet,
498 !tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) &&
499 !tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
500 (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
501 bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y))) {
502 delta.x = axes->point.x - tablet->last_smooth_point.x;
503 delta.y = axes->point.y - tablet->last_smooth_point.y;
506 if (axes->point.x != tablet->last_smooth_point.x)
507 set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X);
508 if (axes->point.y != tablet->last_smooth_point.y)
509 set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y);
511 tablet->last_smooth_point = axes->point;
526 tablet_update_pressure(struct tablet_dispatch *tablet,
535 if (bit_is_set(tablet->changed_axes,
538 tablet->axes.pressure = normalize_pressure(absinfo, tool);
543 tablet_update_distance(struct tablet_dispatch *tablet,
551 if (bit_is_set(tablet->changed_axes,
554 tablet->axes.distance = normalize_distance(absinfo);
559 tablet_update_slider(struct tablet_dispatch *tablet,
567 if (bit_is_set(tablet->changed_axes,
570 tablet->axes.slider = normalize_slider(absinfo);
575 tablet_update_tilt(struct tablet_dispatch *tablet,
586 if (bit_is_set(tablet->changed_axes,
588 bit_is_set(tablet->changed_axes,
592 tablet->axes.tilt.x = adjust_tilt(absinfo);
595 tablet->axes.tilt.y = adjust_tilt(absinfo);
598 tablet->axes.tilt.x *= -1;
599 tablet->axes.tilt.y *= -1;
605 tablet_update_artpen_rotation(struct tablet_dispatch *tablet,
613 if (bit_is_set(tablet->changed_axes,
618 tablet->axes.rotation = convert_to_degrees(absinfo, 90);
623 tablet_update_mouse_rotation(struct tablet_dispatch *tablet,
626 if (bit_is_set(tablet->changed_axes,
628 bit_is_set(tablet->changed_axes,
630 convert_tilt_to_rotation(tablet);
635 tablet_update_rotation(struct tablet_dispatch *tablet,
640 if (tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
641 tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) {
642 tablet_update_mouse_rotation(tablet, device);
643 clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
644 clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
645 tablet->axes.tilt.x = 0;
646 tablet->axes.tilt.y = 0;
652 tablet_update_artpen_rotation(tablet, device);
655 double r = tablet->axes.rotation;
656 tablet->axes.rotation = fmod(180 + r, 360);
662 tablet_update_wheel(struct tablet_dispatch *tablet,
668 if (bit_is_set(tablet->changed_axes, a)) {
669 /* tablet->axes.wheel_discrete is already set */
670 tablet->axes.wheel = normalize_wheel(tablet,
671 tablet->axes.wheel_discrete);
673 tablet->axes.wheel = 0;
674 tablet->axes.wheel_discrete = 0;
679 tablet_smoothen_axes(const struct tablet_dispatch *tablet,
683 size_t count = tablet_history_size(tablet);
687 const struct tablet_axes *a = tablet_history_get(tablet, i);
704 tablet_check_notify_axes(struct tablet_dispatch *tablet,
711 const char tmp[sizeof(tablet->changed_axes)] = {0};
714 if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) {
715 axes = tablet->axes;
719 tablet_update_xy(tablet, device);
720 tablet_update_pressure(tablet, device, tool);
721 tablet_update_distance(tablet, device);
722 tablet_update_slider(tablet, device);
723 tablet_update_tilt(tablet, device);
724 tablet_update_wheel(tablet, device);
727 tablet_update_rotation(tablet, device);
729 axes.point = tablet->axes.point;
730 axes.pressure = tablet->axes.pressure;
731 axes.distance = tablet->axes.distance;
732 axes.slider = tablet->axes.slider;
733 axes.tilt = tablet->axes.tilt;
734 axes.wheel = tablet->axes.wheel;
735 axes.wheel_discrete = tablet->axes.wheel_discrete;
736 axes.rotation = tablet->axes.rotation;
744 if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) ||
745 tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
746 tablet_history_reset(tablet);
749 tablet_history_push(tablet, &tablet->axes);
750 tablet_smoothen_axes(tablet, &axes);
753 axes.delta = tablet_tool_process_delta(tablet, tool, device, &axes, time);
761 tablet_update_button(struct tablet_dispatch *tablet,
778 evdev_log_info(tablet->device,
786 set_bit(tablet->button_state.bits, evcode);
787 tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
789 clear_bit(tablet->button_state.bits, evcode);
790 tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
815 tablet_process_key(struct tablet_dispatch *tablet,
829 "Invalid tool 'finger' on tablet interface\n");
839 tablet_set_status(tablet, TABLET_TOOL_UPDATED);
841 tablet->tool_state |= bit(type);
843 tablet->tool_state &= ~bit(type);
846 if (!bit_is_set(tablet->axis_caps,
849 tablet_set_status(tablet,
852 tablet_set_status(tablet,
857 tablet_update_button(tablet, e->code, e->value);
863 tablet_process_relative(struct tablet_dispatch *tablet,
879 set_bit(tablet->changed_axes, axis);
880 tablet->axes.wheel_discrete = -1 * e->value;
881 tablet_set_status(tablet, TABLET_AXES_UPDATED);
893 tablet_process_misc(struct tablet_dispatch *tablet,
901 tablet->current_tool.serial = e->value;
916 copy_axis_cap(const struct tablet_dispatch *tablet,
920 if (bit_is_set(tablet->axis_caps, axis))
925 copy_button_cap(const struct tablet_dispatch *tablet,
929 struct libevdev *evdev = tablet->device->evdev;
936 tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet,
946 db = tablet_libinput_context(tablet)->libwacom.db;
959 copy_button_cap(tablet, tool, code);
962 copy_button_cap(tablet, tool, BTN_STYLUS2);
964 copy_button_cap(tablet, tool, BTN_STYLUS);
968 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
978 copy_axis_cap(tablet,
981 copy_axis_cap(tablet,
987 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
989 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
991 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
993 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
1002 tool_set_bits(const struct tablet_dispatch *tablet,
1007 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_X);
1008 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_Y);
1011 if (tool_set_bits_from_libwacom(tablet, tool) == 0)
1015 tablet onto the tool. Except we know that mice only have rotation
1024 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
1025 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
1026 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
1027 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
1028 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
1037 if (libevdev_has_event_code(tablet->device->evdev, EV_ABS,
1039 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
1043 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
1044 copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
1051 tablet vs all mouse-related buttons */
1058 copy_button_cap(tablet, tool, BTN_STYLUS);
1059 copy_button_cap(tablet, tool, BTN_STYLUS2);
1063 copy_button_cap(tablet, tool, BTN_LEFT);
1064 copy_button_cap(tablet, tool, BTN_MIDDLE);
1065 copy_button_cap(tablet, tool, BTN_RIGHT);
1066 copy_button_cap(tablet, tool, BTN_SIDE);
1067 copy_button_cap(tablet, tool, BTN_EXTRA);
1081 tool_set_pressure_thresholds(struct tablet_dispatch *tablet,
1084 struct evdev_device *device = tablet->device;
1131 tablet_get_tool(struct tablet_dispatch *tablet,
1136 struct libinput *libinput = tablet_libinput_context(tablet);
1157 tool_list = &tablet->tool_list;
1159 * unique, so we keep them local to the tablet that they come
1189 tool_set_pressure_thresholds(tablet, tool);
1190 tool_set_bits(tablet, tool);
1199 tablet_notify_button_mask(struct tablet_dispatch *tablet,
1211 if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
1224 &tablet->axes,
1231 tablet_notify_buttons(struct tablet_dispatch *tablet,
1240 tablet_get_pressed_buttons(tablet, &buttons);
1242 tablet_get_released_buttons(tablet, &buttons);
1244 tablet_notify_button_mask(tablet,
1253 sanitize_pressure_distance(struct tablet_dispatch *tablet,
1260 distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
1261 pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
1266 bool pressure_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
1267 bool distance_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
1282 clear_bit(tablet->changed_axes,
1284 tablet->axes.distance = 0;
1286 clear_bit(tablet->changed_axes,
1288 tablet->axes.pressure = 0;
1292 if (tablet->axes.pressure == 0)
1293 clear_bit(tablet->changed_axes,
1296 tablet->axes.pressure = 0;
1301 sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet)
1305 if ((tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
1306 tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) &&
1307 (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
1308 bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)))
1309 set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
1313 sanitize_tablet_axes(struct tablet_dispatch *tablet,
1316 sanitize_pressure_distance(tablet, tool);
1317 sanitize_mouse_lens_rotation(tablet);
1336 update_pressure_offset(struct tablet_dispatch *tablet,
1344 !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
1365 detect_pressure_offset(struct tablet_dispatch *tablet,
1373 !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
1421 "See %s/tablet-support.html\n",
1430 "See %s/tablet-support.html\n",
1439 detect_tool_contact(struct tablet_dispatch *tablet,
1450 if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT))
1453 if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
1454 !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
1458 p = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
1467 tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
1468 tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
1470 !tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
1471 tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
1476 tablet_mark_all_axes_changed(struct tablet_dispatch *tablet,
1479 static_assert(sizeof(tablet->changed_axes) ==
1483 memcpy(tablet->changed_axes,
1485 sizeof(tablet->changed_axes));
1489 tablet_update_proximity_state(struct tablet_dispatch *tablet,
1494 int dist_max = tablet->cursor_proximity_threshold;
1497 distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
1507 (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
1508 tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))) {
1509 tablet_unset_status(tablet,
1511 tablet_unset_status(tablet,
1513 tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
1514 tablet_mark_all_axes_changed(tablet, tool);
1516 tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
1517 tablet_force_button_presses(tablet);
1525 if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
1526 tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
1530 if (tablet_has_status(tablet,
1532 tablet_set_status(tablet,
1534 tablet_unset_status(tablet,
1542 tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
1546 tablet_calculate_arbitration_rect(struct tablet_dispatch *tablet)
1548 struct evdev_device *device = tablet->device;
1552 mm = evdev_device_units_to_mm(device, &tablet->axes.point);
1562 if (tablet->axes.tilt.x > 0) {
1587 tablet_update_touch_device_rect(struct tablet_dispatch *tablet,
1594 if (tablet->touch_device == NULL ||
1595 tablet->arbitration != ARBITRATION_IGNORE_RECT)
1598 rect = tablet_calculate_arbitration_rect(tablet);
1600 dispatch = tablet->touch_device->dispatch;
1603 tablet->touch_device,
1609 tablet_send_proximity_in(struct tablet_dispatch *tablet,
1615 if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY))
1622 tablet->changed_axes,
1624 tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
1625 tablet_unset_status(tablet, TABLET_AXES_UPDATED);
1627 tablet_reset_changed_axes(tablet);
1635 tablet_send_proximity_out(struct tablet_dispatch *tablet,
1641 if (!tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
1648 tablet->changed_axes,
1651 tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
1652 tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
1654 tablet_reset_changed_axes(tablet);
1662 tablet_send_tip(struct tablet_dispatch *tablet,
1668 if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) {
1673 tablet->changed_axes,
1675 tablet_unset_status(tablet, TABLET_AXES_UPDATED);
1676 tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
1677 tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT);
1679 tablet_reset_changed_axes(tablet);
1686 if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
1691 tablet->changed_axes,
1693 tablet_unset_status(tablet, TABLET_AXES_UPDATED);
1694 tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
1695 tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT);
1697 tablet_reset_changed_axes(tablet);
1708 tablet_send_axes(struct tablet_dispatch *tablet,
1716 if (!tablet_has_status(tablet, TABLET_AXES_UPDATED))
1719 if (tablet_has_status(tablet,
1729 tablet->changed_axes,
1731 tablet_unset_status(tablet, TABLET_AXES_UPDATED);
1732 tablet_reset_changed_axes(tablet);
1738 tablet_send_buttons(struct tablet_dispatch *tablet,
1743 if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) {
1744 tablet_notify_buttons(tablet,
1749 tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
1752 if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) {
1753 tablet_notify_buttons(tablet,
1758 tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
1763 tablet_send_events(struct tablet_dispatch *tablet,
1770 if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
1775 axes = tablet->axes;
1779 tablet_unset_status(tablet, TABLET_AXES_UPDATED);
1781 if (tablet_check_notify_axes(tablet, device, tool, &axes, time))
1782 tablet_update_touch_device_rect(tablet, &axes, time);
1785 assert(tablet->axes.delta.x == 0);
1786 assert(tablet->axes.delta.y == 0);
1788 tablet_send_proximity_in(tablet, tool, device, &axes, time);
1789 if (!tablet_send_tip(tablet, tool, device, &axes, time))
1790 tablet_send_axes(tablet, tool, device, &axes, time);
1792 tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
1793 tablet_reset_changed_axes(tablet);
1795 tablet_send_buttons(tablet, tool, device, time);
1797 if (tablet_send_proximity_out(tablet, tool, device, &axes, time)) {
1800 tablet_history_reset(tablet);
1810 * To avoid this, we set a timer on BTN_TOOL_PEN in. We expect the tablet to
1824 tablet_proximity_out_quirk_set_timer(struct tablet_dispatch *tablet,
1827 if (tablet->quirks.need_to_force_prox_out)
1828 libinput_timer_set(&tablet->quirks.prox_out_timer,
1833 tablet_update_tool_state(struct tablet_dispatch *tablet,
1846 if (tablet->quirks.proximity_out_forced &&
1847 tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
1848 !tablet->tool_state) {
1849 tablet->quirks.need_to_force_prox_out = false;
1850 tablet->quirks.proximity_out_forced = false;
1864 if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
1865 if (tablet->quirks.proximity_out_forced) {
1866 if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
1867 !tablet->tool_state)
1868 tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
1869 tablet->quirks.proximity_out_forced = false;
1870 } else if (tablet->tool_state == 0 &&
1871 tablet->current_tool.type == LIBINPUT_TOOL_NONE) {
1872 tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
1873 tablet->quirks.proximity_out_forced = false;
1877 if (tablet->tool_state == tablet->prev_tool_state)
1892 if (tablet->tool_state & (tablet->tool_state - 1)) {
1893 doubled_up_new_tool_bit = tablet->tool_state ^ tablet->prev_tool_state;
1897 tablet->tool_state &= ~bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
1909 tablet->tool_state = 0;
1912 changed = tablet->tool_state ^ tablet->prev_tool_state;
1914 state = !!(tablet->tool_state & bit(type));
1916 tablet_update_tool(tablet, device, type, state);
1922 tablet_proximity_out_quirk_set_timer(tablet, time);
1925 * events it means the tablet will give us the right
1929 if (!tablet->quirks.proximity_out_in_progress)
1930 tablet->quirks.need_to_force_prox_out = false;
1932 libinput_timer_cancel(&tablet->quirks.prox_out_timer);
1936 tablet->prev_tool_state = tablet->tool_state;
1939 tablet->tool_state = doubled_up_new_tool_bit;
1946 tablet_get_current_tool(struct tablet_dispatch *tablet)
1948 if (tablet->current_tool.type == LIBINPUT_TOOL_NONE)
1951 return tablet_get_tool(tablet,
1952 tablet->current_tool.type,
1953 tablet->current_tool.id,
1954 tablet->current_tool.serial);
1958 tablet_flush(struct tablet_dispatch *tablet,
1966 process_tool_twice = tablet_update_tool_state(tablet, device, time);
1968 tool = tablet_get_current_tool(tablet);
1974 tablet_update_proximity_state(tablet, device, tool);
1976 if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) ||
1977 tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE))
1980 if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
1982 memset(tablet->button_state.bits,
1984 sizeof(tablet->button_state.bits));
1985 tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
1986 if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
1987 tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
1988 } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
1989 tablet_mark_all_axes_changed(tablet, tool);
1990 update_pressure_offset(tablet, device, tool);
1991 detect_pressure_offset(tablet, device, tool);
1992 detect_tool_contact(tablet, device, tool);
1993 sanitize_tablet_axes(tablet, tool);
1994 } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
1995 update_pressure_offset(tablet, device, tool);
1996 detect_tool_contact(tablet, device, tool);
1997 sanitize_tablet_axes(tablet, tool);
2000 tablet_send_events(tablet, tool, device, time);
2007 tablet_set_touch_device_enabled(struct tablet_dispatch *tablet,
2012 struct evdev_device *touch_device = tablet->touch_device;
2018 tablet->arbitration = which;
2030 tablet_toggle_touch_device(struct tablet_dispatch *tablet,
2038 if (tablet_has_status(tablet,
2040 tablet_has_status(tablet, TABLET_NONE) ||
2041 tablet_has_status(tablet,
2043 tablet_has_status(tablet,
2046 } else if (tablet->axes.tilt.x == 0) {
2048 } else if (tablet->arbitration != ARBITRATION_IGNORE_RECT) {
2051 r = tablet_calculate_arbitration_rect(tablet);
2058 tablet_set_touch_device_enabled(tablet,
2065 tablet_reset_state(struct tablet_dispatch *tablet)
2070 memcpy(&tablet->prev_button_state,
2071 &tablet->button_state,
2072 sizeof(tablet->button_state));
2073 tablet_unset_status(tablet, TABLET_TOOL_UPDATED);
2075 if (memcmp(&tablet->button_state, &zero, sizeof(zero)) == 0)
2076 tablet_unset_status(tablet, TABLET_BUTTONS_DOWN);
2078 tablet_set_status(tablet, TABLET_BUTTONS_DOWN);
2084 struct tablet_dispatch *tablet = data;
2099 if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ||
2100 tablet_has_status(tablet, TABLET_BUTTONS_DOWN)) {
2101 tablet_proximity_out_quirk_set_timer(tablet, now);
2105 if (tablet->quirks.last_event_time > now - FORCED_PROXOUT_TIMEOUT) {
2106 tablet_proximity_out_quirk_set_timer(tablet,
2107 tablet->quirks.last_event_time);
2111 evdev_log_debug(tablet->device, "tablet: forcing proximity after timeout\n");
2113 tablet->quirks.proximity_out_in_progress = true;
2115 tablet->base.interface->process(&tablet->base,
2116 tablet->device,
2120 tablet->quirks.proximity_out_in_progress = false;
2122 tablet->quirks.proximity_out_forced = true;
2131 struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
2135 tablet_process_absolute(tablet, device, e, time);
2138 tablet_process_relative(tablet, device, e, time);
2141 tablet_process_key(tablet, device, e, time);
2144 tablet_process_misc(tablet, device, e, time);
2147 tablet_flush(tablet, device, time);
2148 tablet_toggle_touch_device(tablet, device, time);
2149 tablet_reset_state(tablet);
2150 tablet->quirks.last_event_time = time;
2165 struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
2166 struct libinput *li = tablet_libinput_context(tablet);
2169 tablet_set_touch_device_enabled(tablet,
2174 if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
2175 tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
2176 tablet_flush(tablet, device, libinput_now(li));
2183 struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
2185 struct libinput *li = tablet_libinput_context(tablet);
2187 libinput_timer_cancel(&tablet->quirks.prox_out_timer);
2188 libinput_timer_destroy(&tablet->quirks.prox_out_timer);
2190 list_for_each_safe(tool, &tablet->tool_list, link) {
2196 free(tablet);
2203 struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
2209 if (tablet->touch_device != NULL) {
2218 struct libinput *li = tablet_libinput_context(tablet);
2219 tablet_set_touch_device_enabled(tablet,
2226 tablet->touch_device->devname);
2233 tablet->touch_device = new_device;
2240 struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
2244 if (tablet->rotation.touch_device == NULL && (group1 == group2)) {
2246 "tablet-rotation: %s will rotate %s\n",
2249 tablet->rotation.touch_device = new_device;
2252 tablet->rotation.touch_device_left_handed_state = true;
2281 struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
2283 if (tablet->touch_device == removed_device)
2284 tablet->touch_device = NULL;
2286 if (tablet->rotation.touch_device == removed_device) {
2287 tablet->rotation.touch_device = NULL;
2288 tablet->rotation.touch_device_left_handed_state = false;
2297 struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
2298 struct libinput *li = tablet_libinput_context(tablet);
2312 tablet->tool_state = bit(tool);
2313 tablet->prev_tool_state = bit(tool);
2318 if (!tablet->tool_state)
2321 tablet_update_tool(tablet, device, tool, state);
2322 if (tablet->quirks.need_to_force_prox_out)
2323 tablet_proximity_out_quirk_set_timer(tablet, libinput_now(li));
2325 tablet->current_tool.id =
2334 tablet->current_tool.serial = 0;
2343 struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
2345 if (!tablet->rotation.touch_device)
2349 "tablet-rotation: touchpad is %s\n",
2357 tablet->rotation.touch_device_left_handed_state = left_handed_enabled;
2378 tablet_init_calibration(struct tablet_dispatch *tablet,
2382 evdev_init_calibration(device, &tablet->calibration);
2386 tablet_init_proximity_threshold(struct tablet_dispatch *tablet,
2406 tablet->cursor_proximity_threshold = 42;
2435 tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device)
2470 struct tablet_dispatch *tablet)
2484 * lenovo pens so we use that as the flag of whether the tablet
2485 * is an AES tablet
2490 db = tablet_libinput_context(tablet)->libwacom.db;
2516 struct tablet_dispatch *tablet)
2518 size_t history_size = ARRAY_LENGTH(tablet->history.samples);
2530 use_smoothing = !tablet_is_aes(device, tablet);
2537 tablet->history.size = history_size;
2557 "missing tablet capabilities:%s%s%s%s. "
2567 tablet_init(struct tablet_dispatch *tablet,
2574 tablet->base.dispatch_type = DISPATCH_TABLET;
2575 tablet->base.interface = &tablet_interface;
2576 tablet->device = device;
2577 tablet->status = TABLET_NONE;
2578 tablet->current_tool.type = LIBINPUT_TOOL_NONE;
2579 list_init(&tablet->tool_list);
2586 tablet->quirks.proximity_out_forced = true;
2596 tablet_init_calibration(tablet, device);
2597 tablet_init_proximity_threshold(tablet, device);
2598 rc = tablet_init_accel(tablet, device);
2602 evdev_init_sendevents(device, &tablet->base);
2604 tablet_init_smoothing(device, tablet);
2609 if (tablet_device_has_axis(tablet, axis))
2610 set_bit(tablet->axis_caps, axis);
2613 tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
2617 tablet->quirks.need_to_force_prox_out = true;
2619 libinput_timer_init(&tablet->quirks.prox_out_timer,
2620 tablet_libinput_context(tablet),
2623 tablet);
2631 struct tablet_dispatch *tablet;
2640 tablet = zalloc(sizeof *tablet);
2642 if (tablet_init(tablet, device) != 0) {
2643 tablet_destroy(&tablet->base);
2647 return &tablet->base;