From 4b38a39c9d02033875980732ed41e3ea848580c5 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 2 Mar 2017 18:18:31 +0100 Subject: [PATCH] gtk-demo: Add 3fg touchpad swipe handling to gestures demo We can handle those on wayland, so we should show it's possible. --- demos/gtk-demo/gestures.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/demos/gtk-demo/gestures.c b/demos/gtk-demo/gestures.c index f8e475817d..1e88a9ec91 100644 --- a/demos/gtk-demo/gestures.c +++ b/demos/gtk-demo/gestures.c @@ -13,6 +13,17 @@ static gdouble swipe_x = 0; static gdouble swipe_y = 0; static gboolean long_pressed = FALSE; +static gboolean +touchpad_swipe_gesture_begin (GtkGesture *gesture, + GdkEventSequence *sequence, + GtkWidget *widget) +{ + /* Disallow touchscreen events here */ + if (sequence != NULL) + gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED); + return sequence == NULL; +} + static void swipe_gesture_swept (GtkGestureSwipe *gesture, gdouble velocity_x, @@ -161,6 +172,19 @@ do_gestures (GtkWidget *do_widget) GTK_PHASE_BUBBLE); g_object_weak_ref (G_OBJECT (drawing_area), (GWeakNotify) g_object_unref, gesture); + /* 3fg swipe for touchpads */ + gesture = g_object_new (GTK_TYPE_GESTURE_SWIPE, + "widget", drawing_area, + "n-points", 3, + NULL); + g_signal_connect (gesture, "begin", + G_CALLBACK (touchpad_swipe_gesture_begin), drawing_area); + g_signal_connect (gesture, "swipe", + G_CALLBACK (swipe_gesture_swept), drawing_area); + gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), + GTK_PHASE_BUBBLE); + g_object_weak_ref (G_OBJECT (drawing_area), (GWeakNotify) g_object_unref, gesture); + /* Long press */ gesture = gtk_gesture_long_press_new (drawing_area); g_signal_connect (gesture, "pressed",