[PATCH libinput 07/11] gestures: check for valid types on the gesture event API

Peter Hutterer peter.hutterer at who-t.net
Thu Jul 2 21:15:45 PDT 2015


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
---
 src/evdev-mt-touchpad-gestures.c |  3 +-
 src/libinput-private.h           |  1 +
 src/libinput.c                   | 65 +++++++++++++++++++++++++++++++++++++++-
 src/libinput.h                   | 13 ++++++--
 4 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index 90835d7..cd853ec 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -97,7 +97,7 @@ tp_gesture_start(struct tp_dispatch *tp, uint64_t time)
 		case GESTURE_2FG_STATE_PINCH:
 			gesture_notify_pinch(&tp->device->base, time,
 					    LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
-					    &zero, &zero, 0.0, 0.0);
+					    &zero, &zero, 1.0, 0.0);
 			break;
 		}
 		break;
@@ -481,6 +481,7 @@ tp_gesture_end(struct tp_dispatch *tp, uint64_t time, bool cancelled)
 			break;
 		case GESTURE_2FG_STATE_PINCH:
 			gesture_notify_pinch_end(&tp->device->base, time,
+						 tp->gesture.prev_scale,
 						 cancelled);
 			break;
 		}
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 3fa6d26..d9dcffc 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -391,6 +391,7 @@ gesture_notify_pinch(struct libinput_device *device,
 void
 gesture_notify_pinch_end(struct libinput_device *device,
 			 uint64_t time,
+			 double scale,
 			 int cancelled);
 
 void
diff --git a/src/libinput.c b/src/libinput.c
index 16c3c4f..93a6eb8 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -667,30 +667,68 @@ libinput_event_touch_get_y(struct libinput_event_touch *event)
 LIBINPUT_EXPORT uint32_t
 libinput_event_gesture_get_time(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_PINCH_END,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_END);
+
 	return event->time;
 }
 
 LIBINPUT_EXPORT int
 libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_PINCH_END,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_END);
+
 	return event->finger_count;
 }
 
 LIBINPUT_EXPORT int
 libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_END,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_END);
+
 	return event->cancelled;
 }
 
 LIBINPUT_EXPORT double
 libinput_event_gesture_get_dx(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
+
 	return event->delta.x;
 }
 
 LIBINPUT_EXPORT double
 libinput_event_gesture_get_dy(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
+
 	return event->delta.y;
 }
 
@@ -698,6 +736,12 @@ LIBINPUT_EXPORT double
 libinput_event_gesture_get_dx_unaccelerated(
 	struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
+
 	return event->delta_unaccel.x;
 }
 
@@ -705,18 +749,36 @@ LIBINPUT_EXPORT double
 libinput_event_gesture_get_dy_unaccelerated(
 	struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
+
 	return event->delta_unaccel.y;
 }
 
 LIBINPUT_EXPORT double
 libinput_event_gesture_get_scale(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_PINCH_END);
+
 	return event->scale;
 }
 
 LIBINPUT_EXPORT double
 libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event)
 {
+	require_event_type(libinput_event_get_context(&event->base),
+			   event->base.type,
+			   0.0,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE);
+
 	return event->angle;
 }
 
@@ -1502,12 +1564,13 @@ gesture_notify_pinch(struct libinput_device *device,
 void
 gesture_notify_pinch_end(struct libinput_device *device,
 			 uint64_t time,
+			 double scale,
 			 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);
+		       2, cancelled, &zero, &zero, scale, 0.0);
 }
 
 static void
diff --git a/src/libinput.h b/src/libinput.h
index a7164d3..15d70fb 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1103,10 +1103,19 @@ libinput_event_gesture_get_dy_unaccelerated(
  * together by 50% then the scale will become 0.5, if they move twice as far
  * apart as initially the scale becomes 2.0, etc.
  *
- * For gesture events that are not of type @ref
- * LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0.
+ * For gesture events that are of type @ref
+ * LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, this function returns 1.0.
+ *
+ * For gesture events that are of type @ref
+ * LIBINPUT_EVENT_GESTURE_PINCH_END, this function returns the scale value
+ * of the most recent @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE event (if
+ * any) or 1.0 otherwise.
+ *
+ * For all other events this function returns 0.
  *
  * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, @ref
+ * LIBINPUT_EVENT_GESTURE_PINCH_END or
  * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE.
  *
  * @return the absolute scale of a pinch gesture
-- 
2.4.3



More information about the wayland-devel mailing list