[PATCH libinput] tablet: delay initial proximity in event until we have a serial

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 2 05:28:57 UTC 2016


If the tablet is already in proximity on startup, we used to immediately sent
a proximity event. We can't fetch MSC_SERIAL from the kernel, so that tool
always had a serial of 0, followed by events with the real serial. Since
clients are supposed to use the serial for the tracking of tools, this is
suboptimal.

When the tablet is added, merely set the internal proximity flags. This way we
wait until the first real event from the device (which includes the serial
number) and convert that into a proximity event.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-tablet.c | 12 +++++-------
 test/tablet.c      | 25 +++++++++++++++++++------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index e684055..8c3dbd3 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -1454,14 +1454,12 @@ tablet_check_initial_proximity(struct evdev_device *device,
 		libevdev_get_event_value(device->evdev,
 					 EV_ABS,
 					 ABS_MISC);
-	tablet->current_tool_serial =
-		libevdev_get_event_value(device->evdev,
-					 EV_MSC,
-					 MSC_SERIAL);
 
-	tablet_flush(tablet,
-		     device,
-		     libinput_now(device->base.seat->libinput));
+	/* we can't fetch MSC_SERIAL from the kernel, so we set the serial
+	 * to 0 for now. On the first real event from the device we get the
+	 * serial (if any) and that event will be converted into a proximity
+	 * event */
+	tablet->current_tool_serial = 0;
 }
 
 static struct evdev_dispatch_interface tablet_interface = {
diff --git a/test/tablet.c b/test/tablet.c
index 8936d57..6c24865 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -2006,6 +2006,8 @@ START_TEST(tool_in_prox_before_start)
 	struct libinput *li;
 	struct litest_device *dev = litest_current_device();
 	struct libinput_event *event;
+	struct libinput_event_tablet_tool *tev;
+	struct libinput_tablet_tool *tool;
 	struct axis_replacement axes[] = {
 		{ ABS_DISTANCE, 10 },
 		{ ABS_PRESSURE, 0 },
@@ -2014,6 +2016,7 @@ START_TEST(tool_in_prox_before_start)
 		{ -1, -1 }
 	};
 	const char *devnode;
+	unsigned int serial;
 
 	litest_tablet_proximity_in(dev, 10, 10, axes);
 
@@ -2028,17 +2031,27 @@ START_TEST(tool_in_prox_before_start)
 	event = libinput_get_event(li);
 	libinput_event_destroy(event);
 
-	litest_wait_for_event_of_type(li,
-				      LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY,
-				      -1);
-	event = libinput_get_event(li);
-	libinput_event_destroy(event);
 	litest_assert_empty_queue(li);
 
 	litest_tablet_motion(dev, 10, 20, axes);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	tev = litest_is_tablet_event(event,
+				     LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
+	tool = libinput_event_tablet_tool_get_tool(tev);
+	serial = libinput_tablet_tool_get_serial(tool);
+	libinput_event_destroy(event);
+
 	litest_tablet_motion(dev, 30, 40, axes);
+	libinput_dispatch(li);
+	event = libinput_get_event(li);
+	tev = litest_is_tablet_event(event,
+				     LIBINPUT_EVENT_TABLET_TOOL_AXIS);
+	tool = libinput_event_tablet_tool_get_tool(tev);
+	ck_assert_int_eq(serial,
+			 libinput_tablet_tool_get_serial(tool));
+	libinput_event_destroy(event);
 
-	litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
 	litest_assert_empty_queue(li);
 	litest_event(dev, EV_KEY, BTN_STYLUS, 1);
 	litest_event(dev, EV_SYN, SYN_REPORT, 0);
-- 
2.5.0



More information about the wayland-devel mailing list