[PATCH libinput v3 1/5] tablet: Stop redundant proximity-out events from being reported

Stephen Chandler Paul thatslyude at gmail.com
Thu Jun 26 15:02:48 PDT 2014


Because bad distance events still trigger calls to tablet_flush(),
tablet_flush() will see that the tablet is out of proximity and assume it's an
appropriate time to send a proximity-out event, even when we've already sent
one. This results in multiple proximity-out events being sent in a row instead
of just one.
In addition, the bad distance events test has been modified to pick up on this.
We shouldn't be receiving /any/ events when we get false distance events from
evdev anyway.

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 src/evdev-tablet.c | 12 ++++++++----
 src/evdev-tablet.h |  3 ++-
 test/tablet.c      | 27 +++++----------------------
 3 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index a6acca4..584b49e 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -102,7 +102,7 @@ tablet_update_tool(struct tablet_dispatch *tablet,
 		tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
 	}
 	else
-		tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
+		tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
 }
 
 static inline double
@@ -164,7 +164,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
 	}
 
 	if (axis_update_needed &&
-	    !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
+	    !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) &&
+	    !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
 		tablet_notify_axis(base,
 				   time,
 				   tablet->changed_axes,
@@ -378,7 +379,7 @@ tablet_flush(struct tablet_dispatch *tablet,
 	     struct evdev_device *device,
 	     uint32_t time)
 {
-	if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
+	if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
 		/* Release all stylus buttons */
 		tablet->button_state.stylus_buttons = 0;
 		tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
@@ -405,8 +406,11 @@ tablet_flush(struct tablet_dispatch *tablet,
 		tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
 	}
 
-	if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
+	if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
 		tablet_notify_proximity_out(&device->base, time);
+		tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
+		tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
+	}
 
 	/* Update state */
 	memcpy(&tablet->prev_button_state,
diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
index 504b093..89cf224 100644
--- a/src/evdev-tablet.h
+++ b/src/evdev-tablet.h
@@ -34,7 +34,8 @@ enum tablet_status {
 	TABLET_BUTTONS_PRESSED = 1 << 2,
 	TABLET_BUTTONS_RELEASED = 1 << 3,
 	TABLET_STYLUS_IN_CONTACT = 1 << 4,
-	TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5
+	TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5,
+	TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6
 };
 
 struct button_state {
diff --git a/test/tablet.c b/test/tablet.c
index adecdab..99200de 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -243,15 +243,12 @@ START_TEST(bad_distance_events)
 {
 	struct litest_device *dev = litest_current_device();
 	struct libinput *li = dev->libinput;
-	struct libinput_event_tablet *tablet_event;
-	struct libinput_event *event;
-	bool bad_distance_event_received = false,
-	     axis_has_changed;
-	enum libinput_event_type type;
 	const struct input_absinfo *absinfo;
+	struct axis_replacement axes[] = {
+		{ -1, -1 },
+	};
 
-	litest_drain_events(dev->libinput);
-
+	litest_tablet_proximity_in(dev, 10, 10, axes);
 	litest_tablet_proximity_out(dev);
 	litest_drain_events(dev->libinput);
 
@@ -263,21 +260,7 @@ START_TEST(bad_distance_events)
 	litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum);
 	litest_event(dev, EV_SYN, SYN_REPORT, 0);
 
-	/* We shouldn't be able to see any of the bad distance events that got
-	 * sent
-	 */
-	while ((event = libinput_get_event(li))) {
-		tablet_event = libinput_event_get_tablet_event(event);
-		type = libinput_event_get_type(event);
-		axis_has_changed = libinput_event_tablet_axis_has_changed(
-		    tablet_event, LIBINPUT_TABLET_AXIS_DISTANCE);
-
-		if (type == LIBINPUT_EVENT_TABLET_AXIS && axis_has_changed)
-			bad_distance_event_received = true;
-
-		libinput_event_destroy(event);
-	}
-	ck_assert(!bad_distance_event_received);
+	litest_assert_empty_queue(li);
 }
 END_TEST
 
-- 
1.8.5.5



More information about the wayland-devel mailing list