[PATCH libinput gestures 2/4] gestures: allow the scale to be queried for all pinch events

Peter Hutterer peter.hutterer at who-t.net
Thu May 21 19:03:55 PDT 2015


The scale is an absolute value (relative to the gesture) rather than a delta
between events, so we should allow it to be queried for all events.
For START it's always 1.0, for END we can return whatever the most recent one
was.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-gestures.c |  3 ++-
 src/libinput-private.h           |  1 +
 src/libinput.c                   |  7 +++++--
 src/libinput.h                   | 15 +++++++++++++--
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index b270b3e..0de056c 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -96,7 +96,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_START,
-					    &zero, &zero, 0.0, 0.0);
+					    &zero, &zero, 1.0, 0.0);
 			break;
 		}
 		break;
@@ -476,6 +476,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 36e9988..70e42f3 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -384,6 +384,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 0346578..5861b21 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -762,7 +762,9 @@ 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_UPDATE);
+			   LIBINPUT_EVENT_GESTURE_PINCH_START,
+			   LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
+			   LIBINPUT_EVENT_GESTURE_PINCH_END);
 
 	return event->scale;
 }
@@ -1560,12 +1562,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 d49fc37..ea7006b 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1096,10 +1096,21 @@ libinput_event_gesture_get_dy_unaccelerated(
  * current distance between the fingers and the distance at the start of the
  * gesture. The scale begins at 1.0, and if e.g. the fingers moved 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.
+ * initially the scale becomes 2.0, etc.
+ *
+ * For gesture events that are of type @ref
+ * LIBINPUT_EVENT_GESTURE_PINCH_START, 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_START, @ref
+ * LIBINPUT_EVENT_GESTURE_PINCH_END or
  * @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE.
  *
  * @return the scale of a pinch gesture
-- 
2.3.5



More information about the wayland-devel mailing list