[PATCH libinput v3 5/5] touchpad: Allow querying whether a gesture ended normally or was cancelled

Hans de Goede hdegoede at redhat.com
Wed Apr 29 05:18:53 PDT 2015


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad-gestures.c | 20 ++++++++------------
 src/evdev-mt-touchpad.c          |  4 ++--
 src/evdev-mt-touchpad.h          |  2 +-
 src/libinput-private.h           | 11 +++++++++++
 src/libinput.c                   | 37 +++++++++++++++++++++++++++++++++++--
 src/libinput.h                   | 17 +++++++++++++++++
 src/libinput.sym                 |  1 +
 tools/event-debug.c              |  4 +++-
 8 files changed, 78 insertions(+), 18 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index 00e267f..a0182ed 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -417,7 +417,7 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
 
 	/* When tap-and-dragging, or a clickpad is clicked force 1fg mode */
 	if (tp_tap_dragging(tp) || (tp->buttons.is_clickpad && tp->buttons.state)) {
-		tp_gesture_stop(tp, time);
+		tp_gesture_stop(tp, time, 1);
 		tp->gesture.finger_count = 1;
 		tp->gesture.finger_count_pending = 0;
 	}
@@ -452,11 +452,10 @@ tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
 }
 
 void
-tp_gesture_stop(struct tp_dispatch *tp, uint64_t time)
+tp_gesture_stop(struct tp_dispatch *tp, uint64_t time, int cancelled)
 {
 	struct libinput *libinput = tp->device->base.seat->libinput;
 	enum tp_gesture_2fg_state twofinger_state = tp->gesture.twofinger_state;
-	const struct normalized_coords zero = { 0.0, 0.0 };
 
 	tp->gesture.twofinger_state = GESTURE_2FG_STATE_NONE;
 
@@ -476,18 +475,15 @@ tp_gesture_stop(struct tp_dispatch *tp, uint64_t time)
 			tp_gesture_stop_twofinger_scroll(tp, time);
 			break;
 		case GESTURE_2FG_STATE_PINCH:
-			gesture_notify_pinch(&tp->device->base, time,
-					    LIBINPUT_EVENT_GESTURE_PINCH_END,
-					    &zero, &zero, 0.0, 0.0);
+			gesture_notify_pinch_end(&tp->device->base, time,
+						 cancelled);
 			break;
 		}
 		break;
 	case 3:
 	case 4:
-		gesture_notify_swipe(&tp->device->base, time,
-				     LIBINPUT_EVENT_GESTURE_SWIPE_END,
-				     tp->gesture.finger_count,
-				     &zero, &zero);
+		gesture_notify_swipe_end(&tp->device->base, time,
+					 tp->gesture.finger_count, cancelled);
 		break;
 	}
 	tp->gesture.started = false;
@@ -501,7 +497,7 @@ tp_gesture_finger_count_switch_timeout(uint64_t now, void *data)
 	if (!tp->gesture.finger_count_pending)
 		return;
 
-	tp_gesture_stop(tp, now); /* End current gesture */
+	tp_gesture_stop(tp, now, 1); /* End current gesture */
 	tp->gesture.finger_count = tp->gesture.finger_count_pending;
 	tp->gesture.finger_count_pending = 0;
 }
@@ -519,7 +515,7 @@ tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time)
 	if (active_touches != tp->gesture.finger_count) {
 		/* If all fingers are lifted immediately end the gesture */
 		if (active_touches == 0) {
-			tp_gesture_stop(tp, time);
+			tp_gesture_stop(tp, time, 0);
 			tp->gesture.finger_count = 0;
 			tp->gesture.finger_count_pending = 0;
 		/* Immediately switch to new mode to avoid initial latency */
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index d5ce880..8b2e6ef 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -672,7 +672,7 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time)
 
 	if (filter_motion || tp->sendevents.trackpoint_active) {
 		tp_edge_scroll_stop_events(tp, time);
-		tp_gesture_stop(tp, time);
+		tp_gesture_stop(tp, time, 1);
 		return;
 	}
 
@@ -829,7 +829,7 @@ tp_trackpoint_event(uint64_t time, struct libinput_event *event, void *data)
 
 	if (!tp->sendevents.trackpoint_active) {
 		tp_edge_scroll_stop_events(tp, time);
-		tp_gesture_stop(tp, time);
+		tp_gesture_stop(tp, time, 1);
 		tp_tap_suspend(tp, time);
 		tp->sendevents.trackpoint_active = true;
 	}
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index e769406..d9b2390 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -398,7 +398,7 @@ void
 tp_remove_gesture(struct tp_dispatch *tp);
 
 void
-tp_gesture_stop(struct tp_dispatch *tp, uint64_t time);
+tp_gesture_stop(struct tp_dispatch *tp, uint64_t time, int cancelled);
 
 void
 tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time);
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 6c2bdf4..36e9988 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -367,6 +367,12 @@ gesture_notify_swipe(struct libinput_device *device,
 		     const struct normalized_coords *unaccel);
 
 void
+gesture_notify_swipe_end(struct libinput_device *device,
+			 uint64_t time,
+			 int finger_count,
+			 int cancelled);
+
+void
 gesture_notify_pinch(struct libinput_device *device,
 		     uint64_t time,
 		     enum libinput_event_type type,
@@ -376,6 +382,11 @@ gesture_notify_pinch(struct libinput_device *device,
 		     double angle);
 
 void
+gesture_notify_pinch_end(struct libinput_device *device,
+			 uint64_t time,
+			 int cancelled);
+
+void
 touch_notify_frame(struct libinput_device *device,
 		   uint64_t time);
 
diff --git a/src/libinput.c b/src/libinput.c
index a8a24f2..e479e32 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -116,6 +116,7 @@ struct libinput_event_gesture {
 	struct libinput_event base;
 	uint32_t time;
 	int finger_count;
+	int cancelled;
 	struct normalized_coords delta;
 	struct normalized_coords delta_unaccel;
 	double scale;
@@ -673,6 +674,12 @@ libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event)
 	return event->finger_count;
 }
 
+LIBINPUT_EXPORT int
+libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event)
+{
+	return event->cancelled;
+}
+
 LIBINPUT_EXPORT double
 libinput_event_gesture_get_dx(struct libinput_event_gesture *event)
 {
@@ -1424,6 +1431,7 @@ gesture_notify(struct libinput_device *device,
 	       uint64_t time,
 	       enum libinput_event_type type,
 	       int finger_count,
+	       int cancelled,
 	       const struct normalized_coords *delta,
 	       const struct normalized_coords *unaccel,
 	       double scale,
@@ -1441,6 +1449,7 @@ gesture_notify(struct libinput_device *device,
 	*gesture_event = (struct libinput_event_gesture) {
 		.time = time,
 		.finger_count = finger_count,
+		.cancelled = cancelled,
 		.delta = *delta,
 		.delta_unaccel = *unaccel,
 		.scale = scale,
@@ -1459,11 +1468,23 @@ gesture_notify_swipe(struct libinput_device *device,
 		     const struct normalized_coords *delta,
 		     const struct normalized_coords *unaccel)
 {
-	gesture_notify(device, time, type, finger_count, delta, unaccel,
+	gesture_notify(device, time, type, finger_count, 0, delta, unaccel,
 		       0.0, 0.0);
 }
 
 void
+gesture_notify_swipe_end(struct libinput_device *device,
+			 uint64_t time,
+			 int finger_count,
+			 int cancelled)
+{
+	const struct normalized_coords zero = { 0.0, 0.0 };
+
+	gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_SWIPE_END,
+		       finger_count, cancelled, &zero, &zero, 0.0, 0.0);
+}
+
+void
 gesture_notify_pinch(struct libinput_device *device,
 		     uint64_t time,
 		     enum libinput_event_type type,
@@ -1472,7 +1493,19 @@ gesture_notify_pinch(struct libinput_device *device,
 		     double scale,
 		     double angle)
 {
-	gesture_notify(device, time, type, 2, delta, unaccel, scale, angle);
+	gesture_notify(device, time, type, 2, 0, delta, unaccel,
+		       scale, angle);
+}
+
+void
+gesture_notify_pinch_end(struct libinput_device *device,
+			 uint64_t time,
+			 int cancelled)
+{
+	const struct normalized_coords zero = { 0.0, 0.0 };
+
+	gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_PINCH_END,
+		       2, cancelled, &zero, &zero, 0.0, 0.0);
 }
 
 static void
diff --git a/src/libinput.h b/src/libinput.h
index a2efa75..d49fc37 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -985,6 +985,23 @@ libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event);
 /**
  * @ingroup event_gesture
  *
+ * Return if the gesture ended normally, or if it was cancelled.
+ * For gesture events that are not of type
+ * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or
+ * @ref LIBINPUT_EVENT_GESTURE_PINCH_END, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or
+ * @ref LIBINPUT_EVENT_GESTURE_PINCH_END.
+ *
+ * @return 0 or 1, with 1 indicating that the gesture was cancelled.
+ */
+int
+libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event);
+
+/**
+ * @ingroup event_gesture
+ *
  * Return the delta between the last event and the current event. For gesture
  * events that are not of type @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or
  * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0.
diff --git a/src/libinput.sym b/src/libinput.sym
index 255dfa8..70f7e5a 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -141,6 +141,7 @@ global:
 	libinput_device_keyboard_has_key;
 	libinput_event_gesture_get_angle;
 	libinput_event_gesture_get_base_event;
+	libinput_event_gesture_get_cancelled;
 	libinput_event_gesture_get_dx;
 	libinput_event_gesture_get_dx_unaccelerated;
 	libinput_event_gesture_get_dy;
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 6cf8b9d..5e6b451 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -311,9 +311,11 @@ static void
 print_gesture_event_without_coords(struct libinput_event *ev)
 {
 	struct libinput_event_gesture *t = libinput_event_get_gesture_event(ev);
+	int finger_count = libinput_event_gesture_get_finger_count(t);
+	int cancelled = libinput_event_gesture_get_cancelled(t);
 
 	print_event_time(libinput_event_gesture_get_time(t));
-	printf("%d\n", libinput_event_gesture_get_finger_count(t));
+	printf("%d%s\n", finger_count, cancelled ? " cancelled" : "");
 }
 
 static void
-- 
2.3.6



More information about the wayland-devel mailing list