[PATCH weston v5 4/4] clients: Add pointer pinch gesture support to weston-image

Carlos Garnacho carlosg at gnome.org
Fri Jan 27 15:41:46 UTC 2017


It will allow zooming in/out the loaded image.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
Reviewed-by: Jonas Ã…dahl <jadahl at gmail.com>
---
 clients/image.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/clients/image.c b/clients/image.c
index db9ccd6..5057d0a 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -61,6 +61,7 @@ struct image {
 
 	bool initialized;
 	cairo_matrix_t matrix;
+	float last_scale;
 };
 
 static double
@@ -330,6 +331,35 @@ axis_handler(struct widget *widget, struct input *input, uint32_t time,
 }
 
 static void
+pinch_begin_handler(struct widget *widget,
+		    struct input *input,
+		    uint32_t time,
+		    uint32_t n_fingers,
+		    void *data)
+{
+	struct image *image = data;
+
+	image->last_scale = 1;
+}
+
+static void
+pinch_update_handler(struct widget *widget,
+		     struct input *input,
+		     uint32_t time,
+		     float dx,
+		     float dy,
+		     float scale,
+		     float rotation_delta,
+		     void *data)
+{
+	struct image *image = data;
+
+	zoom(image, scale / image->last_scale);
+	window_schedule_redraw(image->window);
+	image->last_scale = scale;
+}
+
+static void
 fullscreen_handler(struct window *window, void *data)
 {
 	struct image *image = data;
@@ -400,6 +430,11 @@ image_create(struct display *display, const char *filename,
 	widget_set_button_handler(image->widget, button_handler);
 	widget_set_axis_handler(image->widget, axis_handler);
 	window_set_key_handler(image->window, key_handler);
+	widget_set_pointer_gesture_pinch_begin_handler(image->widget,
+						       pinch_begin_handler);
+	widget_set_pointer_gesture_pinch_update_handler(image->widget,
+							pinch_update_handler);
+
 	widget_schedule_resize(image->widget, 500, 400);
 
 	return image;
-- 
2.9.3



More information about the wayland-devel mailing list