[PATCH libinput 10/11] tools: handle pinch event in event-gui
Peter Hutterer
peter.hutterer at who-t.net
Thu Jul 2 21:15:48 PDT 2015
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
---
tools/event-gui.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/tools/event-gui.c b/tools/event-gui.c
index 0c484cb..058c42d 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -78,6 +78,13 @@ struct window {
double x, y;
} swipe;
+ struct {
+ int nfingers;
+ double scale;
+ double angle;
+ double x, y;
+ } pinch;
+
struct libinput_device *devices[50];
};
@@ -110,7 +117,7 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
{
struct window *w = data;
struct touch *t;
- int i;
+ int i, offset;
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, 0, 0, w->width, w->height);
@@ -132,6 +139,26 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
}
cairo_restore(cr);
+ /* pinch */
+ cairo_save(cr);
+ offset = w->pinch.scale * 100;
+ cairo_translate(cr, w->pinch.x, w->pinch.y);
+ cairo_rotate(cr, w->pinch.angle * M_PI/180.0);
+ if (w->pinch.nfingers > 0) {
+ cairo_set_source_rgb(cr, .4, .4, .8);
+ cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI);
+ cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI);
+ cairo_fill(cr);
+ }
+
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ cairo_arc(cr, offset, -offset, 20, 0, 2 * M_PI);
+ cairo_stroke(cr);
+ cairo_arc(cr, -offset, offset, 20, 0, 2 * M_PI);
+ cairo_stroke(cr);
+
+ cairo_restore(cr);
+
/* draw pointer sprite */
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_save(cr);
@@ -212,6 +239,10 @@ map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
w->swipe.x = w->width/2;
w->swipe.y = w->height/2;
+ w->pinch.scale = 1.0;
+ w->pinch.x = w->width/2;
+ w->pinch.y = w->height/2;
+
g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w);
window = gdk_event_get_window(event);
@@ -485,6 +516,41 @@ handle_event_swipe(struct libinput_event *ev, struct window *w)
}
}
+static void
+handle_event_pinch(struct libinput_event *ev, struct window *w)
+{
+ struct libinput_event_gesture *g = libinput_event_get_gesture_event(ev);
+ int nfingers;
+ double dx, dy;
+
+ nfingers = libinput_event_gesture_get_finger_count(g);
+
+ switch (libinput_event_get_type(ev)) {
+ case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
+ w->pinch.nfingers = nfingers;
+ w->pinch.x = w->width/2;
+ w->pinch.y = w->height/2;
+ break;
+ case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
+ dx = libinput_event_gesture_get_dx(g);
+ dy = libinput_event_gesture_get_dy(g);
+ w->pinch.x += dx;
+ w->pinch.y += dy;
+ w->pinch.scale = libinput_event_gesture_get_scale(g);
+ w->pinch.angle += libinput_event_gesture_get_angle_delta(g);
+ break;
+ case LIBINPUT_EVENT_GESTURE_PINCH_END:
+ w->pinch.nfingers = 0;
+ w->pinch.x = w->width/2;
+ w->pinch.y = w->height/2;
+ w->pinch.angle = 0.0;
+ w->pinch.scale = 1.0;
+ break;
+ default:
+ abort();
+ }
+}
+
static gboolean
handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
{
@@ -538,6 +604,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN:
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
case LIBINPUT_EVENT_GESTURE_PINCH_END:
+ handle_event_pinch(ev, w);
break;
}
--
2.4.3
More information about the wayland-devel
mailing list