[PATCH libinput 4/8] tablet: release the tablet state on device delete

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 7 01:45:02 UTC 2018


When the device gets deleted in a non-neutral state, we need to release all
buttons, lift the tip up and send a proximity out event.

https://bugs.freedesktop.org/show_bug.cgi?id=104940

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-tablet.c |   6 ++++
 test/test-tablet.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 364cfda6..2f5b183b 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -1781,8 +1781,14 @@ tablet_suspend(struct evdev_dispatch *dispatch,
 	       struct evdev_device *device)
 {
 	struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
+	struct libinput *li = tablet_libinput_context(tablet);
 
 	tablet_set_touch_device_enabled(tablet->touch_device, true);
+
+	if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
+		tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
+		tablet_flush(tablet, device, libinput_now(li));
+	}
 }
 
 static void
diff --git a/test/test-tablet.c b/test/test-tablet.c
index 12ea3ec5..f8cb0b11 100644
--- a/test/test-tablet.c
+++ b/test/test-tablet.c
@@ -158,6 +158,46 @@ START_TEST(button_seat_count)
 }
 END_TEST
 
+START_TEST(button_up_on_delete)
+{
+	struct libinput *li = litest_create_context();
+	struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS);
+	struct libevdev *evdev = libevdev_new();
+	unsigned int code;
+
+	litest_tablet_proximity_in(dev, 10, 10, NULL);
+	litest_drain_events(li);
+
+	for (code = BTN_LEFT; code <= BTN_TASK; code++) {
+		if (!libevdev_has_event_code(dev->evdev, EV_KEY, code))
+			continue;
+
+		libevdev_enable_event_code(evdev, EV_KEY, code, NULL);
+		litest_event(dev, EV_KEY, code, 1);
+		litest_event(dev, EV_SYN, SYN_REPORT, 0);
+		libinput_dispatch(li);
+	}
+
+	litest_drain_events(li);
+	litest_delete_device(dev);
+	libinput_dispatch(li);
+
+	for (code = BTN_LEFT; code <= BTN_TASK; code++) {
+		if (!libevdev_has_event_code(evdev, EV_KEY, code))
+			continue;
+
+		litest_assert_tablet_button_event(li,
+					  code,
+					  LIBINPUT_BUTTON_STATE_RELEASED);
+	}
+
+	litest_assert_tablet_proximity_event(li,
+					     LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
+	libevdev_free(evdev);
+	libinput_unref(li);
+}
+END_TEST
+
 START_TEST(tip_down_up)
 {
 	struct litest_device *dev = litest_current_device();
@@ -795,6 +835,43 @@ START_TEST(tip_state_button)
 }
 END_TEST
 
+START_TEST(tip_up_on_delete)
+{
+	struct libinput *li = litest_create_context();
+	struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS);
+	struct libinput_event *event;
+	struct libinput_event_tablet_tool *tablet_event;
+	struct axis_replacement axes[] = {
+		{ ABS_DISTANCE, 10 },
+		{ ABS_PRESSURE, 0 },
+		{ -1, -1 }
+	};
+
+	litest_tablet_proximity_in(dev, 10, 10, axes);
+	litest_drain_events(li);
+
+	litest_axis_set_value(axes, ABS_DISTANCE, 0);
+	litest_axis_set_value(axes, ABS_PRESSURE, 30);
+	litest_push_event_frame(dev);
+	litest_tablet_motion(dev, 10, 10, axes);
+	litest_event(dev, EV_KEY, BTN_TOUCH, 1);
+	litest_pop_event_frame(dev);
+
+	litest_drain_events(li);
+	litest_delete_device(dev);
+	libinput_dispatch(li);
+
+	event = libinput_get_event(li);
+	tablet_event = litest_is_tablet_event(event,
+					      LIBINPUT_EVENT_TABLET_TOOL_TIP);
+	ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event),
+			 LIBINPUT_TABLET_TOOL_TIP_UP);
+	libinput_event_destroy(event);
+
+	libinput_unref(li);
+}
+END_TEST
+
 START_TEST(proximity_in_out)
 {
 	struct litest_device *dev = litest_current_device();
@@ -1310,6 +1387,23 @@ START_TEST(proximity_range_button_release)
 }
 END_TEST
 
+START_TEST(proximity_out_on_delete)
+{
+	struct libinput *li = litest_create_context();
+	struct litest_device *dev = litest_add_device(li, LITEST_WACOM_INTUOS);
+
+	litest_tablet_proximity_in(dev, 10, 10, NULL);
+	litest_drain_events(li);
+
+	litest_delete_device(dev);
+	libinput_dispatch(li);
+
+	litest_assert_tablet_proximity_event(li,
+					     LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
+	libinput_unref(li);
+}
+END_TEST
+
 START_TEST(motion)
 {
 	struct litest_device *dev = litest_current_device();
@@ -4155,6 +4249,8 @@ touch_arbitration_suspend_touch(struct litest_device *dev,
 
 	/* Remove tablet device to unpair, still disabled though */
 	litest_delete_device(tablet);
+	litest_assert_tablet_proximity_event(li,
+					     LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
 	litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
 
 	litest_touch_down(dev, 0, 30, 30);
@@ -4273,6 +4369,8 @@ touch_arbitration_remove_tablet(struct litest_device *dev,
 	litest_assert_empty_queue(li);
 
 	litest_delete_device(tablet);
+	litest_assert_tablet_proximity_event(li,
+			     LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT);
 	litest_assert_only_typed_events(li, LIBINPUT_EVENT_DEVICE_REMOVED);
 
 	/* Touch is still down, don't enable */
@@ -4516,8 +4614,10 @@ litest_setup_tests_tablet(void)
 	litest_add("tablet:proximity", proximity_range_button_click, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY);
 	litest_add("tablet:proximity", proximity_range_button_press, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY);
 	litest_add("tablet:proximity", proximity_range_button_release, LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_MOUSE, LITEST_ANY);
+	litest_add_no_device("tablet:proximity", proximity_out_on_delete);
 	litest_add("tablet:button", button_down_up, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:button", button_seat_count, LITEST_TABLET, LITEST_ANY);
+	litest_add_no_device("tablet:button", button_up_on_delete);
 	litest_add("tablet:tip", tip_down_up, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:tip", tip_down_prox_in, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:tip", tip_up_prox_out, LITEST_TABLET, LITEST_ANY);
@@ -4528,6 +4628,7 @@ litest_setup_tests_tablet(void)
 	litest_add("tablet:tip", tip_state_proximity, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:tip", tip_state_axis, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:tip", tip_state_button, LITEST_TABLET, LITEST_ANY);
+	litest_add_no_device("tablet:tip", tip_up_on_delete);
 	litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
 	litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY);
 	litest_add_for_device("tablet:motion", motion_outside_bounds, LITEST_WACOM_CINTIQ_24HD);
-- 
2.14.3



More information about the wayland-devel mailing list