diff --git a/meson.build b/meson.build index f588862c2..114148c1b 100644 --- a/meson.build +++ b/meson.build @@ -785,6 +785,7 @@ if get_option('tests') 'test/litest-device-dell-canvas-totem.c', 'test/litest-device-dell-canvas-totem-touch.c', 'test/litest-device-elantech-touchpad.c', + 'test/litest-device-elan-tablet.c', 'test/litest-device-generic-singletouch.c', 'test/litest-device-gpio-keys.c', 'test/litest-device-huion-pentablet.c', diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 67880d037..e152065ec 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1755,8 +1755,8 @@ tablet_update_tool_state(struct tablet_dispatch *tablet, */ if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { if (tablet->quirks.proximity_out_forced) { - if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) || - tablet->tool_state) + if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) && + !tablet->tool_state) tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN); tablet->quirks.proximity_out_forced = false; } else if (tablet->tool_state == 0 && diff --git a/test/litest-device-elan-tablet.c b/test/litest-device-elan-tablet.c new file mode 100644 index 000000000..7b8e70227 --- /dev/null +++ b/test/litest-device-elan-tablet.c @@ -0,0 +1,103 @@ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" + +#include "litest.h" +#include "litest-int.h" + +static struct input_event proximity_in[] = { + { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static struct input_event proximity_out[] = { + { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static struct input_event motion[] = { + { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, + { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, + { .type = -1, .code = -1 }, +}; + +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_PRESSURE: + *value = 100; + return 0; + } + return 1; +} + +static struct litest_device_interface interface = { + .tablet_proximity_in_events = proximity_in, + .tablet_proximity_out_events = proximity_out, + .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, +}; + +static struct input_absinfo absinfo[] = { + { ABS_X, 0, 18176, 0, 0, 62 }, + { ABS_Y, 0, 10240, 0, 0, 62 }, + { ABS_PRESSURE, 0, 4096, 0, 0, 0 }, + { .value = -1 }, +}; + +static struct input_id input_id = { + .bustype = 0x18, + .vendor = 0x4f3, + .product = 0x23b9, + .version = 0x100, +}; + +static int events[] = { + EV_KEY, BTN_TOOL_PEN, + EV_KEY, BTN_TOOL_RUBBER, + EV_KEY, BTN_TOUCH, + EV_KEY, BTN_STYLUS, + EV_MSC, MSC_SCAN, + -1, -1, +}; + +TEST_DEVICE("elan-tablet", + .type = LITEST_ELAN_TABLET, + .features = LITEST_TABLET, + .interface = &interface, + + .name = "ELAN2514:00 04F3:23B9", + .id = &input_id, + .events = events, + .absinfo = absinfo, +) diff --git a/test/litest.h b/test/litest.h index ab2633bc5..e145f3a84 100644 --- a/test/litest.h +++ b/test/litest.h @@ -301,6 +301,7 @@ enum litest_device_type { LITEST_DELL_CANVAS_TOTEM_TOUCH, LITEST_WACOM_ISDV4_4200_PEN, LITEST_ALPS_3FG, + LITEST_ELAN_TABLET, }; #define LITEST_DEVICELESS -2 diff --git a/test/test-tablet.c b/test/test-tablet.c index 340615c4d..13d7ce20a 100644 --- a/test/test-tablet.c +++ b/test/test-tablet.c @@ -2954,6 +2954,84 @@ START_TEST(tool_direct_switch_skip_tool_update) } END_TEST +START_TEST(tool_direct_switch_with_forced_proxout) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_RUBBER)) + return; + + litest_drain_events(li); + + /* This is a *very* specific event sequence to trigger a bug: + - pen proximity in + - pen proximity forced out + - eraser proximity in without axis movement + - eraser axis move + */ + + /* pen prox in */ + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + litest_is_proximity_event(event, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); + libinput_event_destroy(event); + + /* pen motion */ + litest_tablet_motion(dev, 20, 30, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + + /* pen forced prox out */ + litest_timeout_tablet_proxout(); + libinput_dispatch(li); + + /* actual prox out for tablets that don't do forced prox out */ + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_proximity_event(event, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); + libinput_event_destroy(event); + + /* eraser prox in without axes */ + litest_event(dev, EV_KEY, BTN_TOOL_RUBBER, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + event = libinput_get_event(li); + litest_is_proximity_event(event, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); + libinput_event_destroy(event); + + /* eraser motion */ + litest_tablet_motion(dev, 30, 40, axes); + litest_tablet_motion(dev, 40, 50, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + + event = libinput_get_event(li); + litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + START_TEST(mouse_tool) { struct litest_device *dev = litest_current_device(); @@ -5756,6 +5834,7 @@ TEST_COLLECTION(tablet) litest_add("tablet:tool", tool_type, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tool", tool_in_prox_before_start, LITEST_TABLET, LITEST_TOTEM); litest_add("tablet:tool", tool_direct_switch_skip_tool_update, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tool", tool_direct_switch_with_forced_proxout, LITEST_TABLET, LITEST_ANY); /* Tablets hold back the proximity until the first event from the * kernel, the totem sends it immediately */