Skip to content

Commit

Permalink
tablet: fix the handling of axis updates after a forced proximity out
Browse files Browse the repository at this point in the history
Where a pen was forced out of proximity and an eraser came into proximity
without axis updates on the prox-in, subsequent axis updates would trigger the
pen back into proximity. This resulted in two tools in proximity at once
though the new pen never went out of proximity

This would trigger crashes in various compositors/applications, see
xournalpp/xournalpp#1141 (comment)

The cause was a wrong condition introduced in ffd8c71. We only need to
force the pen bit on if the current tool state is currently zero and no tool
update was sent with the axis event. In our case, the tool state is nonzero
already (eraser) and we can skip this bit.

Fixes #418

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Feb 2, 2020
1 parent 8705aba commit 71830dd
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 2 deletions.
1 change: 1 addition & 0 deletions meson.build
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/evdev-tablet.c
Expand Up @@ -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 &&
Expand Down
103 changes: 103 additions & 0 deletions 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,
)
1 change: 1 addition & 0 deletions test/litest.h
Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions test/test-tablet.c
Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 71830dd

Please sign in to comment.