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

Submitted by Carlos Garnacho on Jan. 27, 2017, 3:41 p.m.

Details

Message ID 20170127154146.15590-4-carlosg@gnome.org
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Wayland

Not browsing as part of any series.

Commit Message

Carlos Garnacho Jan. 27, 2017, 3:41 p.m.
It will allow zooming in/out the loaded image.

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

Patch hide | download patch | download mbox

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;