[PATCH libinput gestures 3/4] tools: add swipe support to the event-gui
Peter Hutterer
peter.hutterer at who-t.net
Thu May 21 19:03:56 PDT 2015
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
tools/event-gui.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/tools/event-gui.c b/tools/event-gui.c
index cb583af..c28aaf2 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -71,6 +71,12 @@ struct window {
/* l/m/r mouse buttons */
int l, m, r;
+ /* touchpad swipe */
+ struct {
+ int nfingers;
+ double x, y;
+ } swipe;
+
struct libinput_device *devices[50];
};
@@ -103,11 +109,28 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data)
{
struct window *w = data;
struct touch *t;
+ int i;
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_rectangle(cr, 0, 0, w->width, w->height);
cairo_fill(cr);
+ /* swipe */
+ cairo_save(cr);
+ cairo_translate(cr, w->swipe.x, w->swipe.y);
+ for (i = 0; i < w->swipe.nfingers; i++) {
+ cairo_set_source_rgb(cr, .8, .8, .4);
+ cairo_arc(cr, (i - 2) * 40, 0, 20, 0, 2 * M_PI);
+ cairo_fill(cr);
+ }
+
+ for (i = 0; i < 4; i++) { /* 4 fg max */
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ cairo_arc(cr, (i - 2) * 40, 0, 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);
@@ -185,6 +208,9 @@ map_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
w->hx = w->width/2;
w->hy = w->height/2;
+ w->swipe.x = w->width/2;
+ w->swipe.y = w->height/2;
+
g_signal_connect(G_OBJECT(w->area), "draw", G_CALLBACK(draw), w);
window = gdk_event_get_window(event);
@@ -425,6 +451,37 @@ handle_event_button(struct libinput_event *ev, struct window *w)
}
+static void
+handle_event_swipe(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_SWIPE_START:
+ w->swipe.nfingers = nfingers;
+ w->swipe.x = w->width/2;
+ w->swipe.y = w->height/2;
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
+ dx = libinput_event_gesture_get_dx(g);
+ dy = libinput_event_gesture_get_dy(g);
+ w->swipe.x += dx;
+ w->swipe.y += dy;
+ break;
+ case LIBINPUT_EVENT_GESTURE_SWIPE_END:
+ w->swipe.nfingers = 0;
+ w->swipe.x = w->width/2;
+ w->swipe.y = w->height/2;
+ break;
+ default:
+ abort();
+ }
+}
+
static gboolean
handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
{
@@ -472,6 +529,8 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
case LIBINPUT_EVENT_GESTURE_SWIPE_START:
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
case LIBINPUT_EVENT_GESTURE_SWIPE_END:
+ handle_event_swipe(ev, w);
+ break;
case LIBINPUT_EVENT_GESTURE_PINCH_START:
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
case LIBINPUT_EVENT_GESTURE_PINCH_END:
--
2.3.5
More information about the wayland-devel
mailing list