summaryrefslogtreecommitdiff
path: root/gtk/gtkgesturezoom.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-07-09 19:31:27 +0200
committerCarlos Garnacho <carlosg@gnome.org>2015-08-12 23:20:25 +0200
commit068a8449305b2674c6ff4c8ebc97fbe4782b9f35 (patch)
tree0fa2be3c580fde360d54a9742aa70a50115c9f26 /gtk/gtkgesturezoom.c
parentd756463d9b2ad1cf84c0ca4313a19227a89796b4 (diff)
downloadgtk+-068a8449305b2674c6ff4c8ebc97fbe4782b9f35.tar.gz
gtkgesturezoom: Handle touchpad pinch events
We let these through in GtkEventController::filter, and handle these especially on GtkGesture::update.
Diffstat (limited to 'gtk/gtkgesturezoom.c')
-rw-r--r--gtk/gtkgesturezoom.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/gtk/gtkgesturezoom.c b/gtk/gtkgesturezoom.c
index 02e5a08695..00a8f17639 100644
--- a/gtk/gtkgesturezoom.c
+++ b/gtk/gtkgesturezoom.c
@@ -75,6 +75,7 @@ static gboolean
_gtk_gesture_zoom_get_distance (GtkGestureZoom *zoom,
gdouble *distance)
{
+ const GdkEvent *last_event;
gdouble x1, y1, x2, y2;
GtkGesture *gesture;
GList *sequences;
@@ -86,15 +87,32 @@ _gtk_gesture_zoom_get_distance (GtkGestureZoom *zoom,
return FALSE;
sequences = gtk_gesture_get_sequences (gesture);
- g_assert (sequences && sequences->next);
-
- gtk_gesture_get_point (gesture, sequences->data, &x1, &y1);
- gtk_gesture_get_point (gesture, sequences->next->data, &x2, &y2);
- g_list_free (sequences);
+ if (!sequences)
+ return FALSE;
- dx = x1 - x2;
- dy = y1 - y2;;
- *distance = sqrt ((dx * dx) + (dy * dy));
+ last_event = gtk_gesture_get_last_event (gesture, sequences->data);
+
+ if (last_event->type == GDK_TOUCHPAD_PINCH &&
+ (last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
+ last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
+ last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END))
+ {
+ /* Touchpad pinch */
+ *distance = last_event->touchpad_pinch.scale;
+ }
+ else
+ {
+ if (!sequences->next)
+ return FALSE;
+
+ gtk_gesture_get_point (gesture, sequences->data, &x1, &y1);
+ gtk_gesture_get_point (gesture, sequences->next->data, &x2, &y2);
+ g_list_free (sequences);
+
+ dx = x1 - x2;
+ dy = y1 - y2;;
+ *distance = sqrt ((dx * dx) + (dy * dy));
+ }
return TRUE;
}
@@ -119,6 +137,22 @@ _gtk_gesture_zoom_check_emit (GtkGestureZoom *gesture)
return TRUE;
}
+static gboolean
+gtk_gesture_zoom_filter_event (GtkEventController *controller,
+ const GdkEvent *event)
+{
+ /* Let 2-finger touchpad pinch events go through */
+ if (event->type == GDK_TOUCHPAD_PINCH)
+ {
+ if (event->touchpad_pinch.n_fingers == 2)
+ return FALSE;
+ else
+ return TRUE;
+ }
+
+ return GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_zoom_parent_class)->filter_event (controller, event);
+}
+
static void
gtk_gesture_zoom_begin (GtkGesture *gesture,
GdkEventSequence *sequence)
@@ -141,10 +175,13 @@ static void
gtk_gesture_zoom_class_init (GtkGestureZoomClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkEventControllerClass *event_controller_class = GTK_EVENT_CONTROLLER_CLASS (klass);
GtkGestureClass *gesture_class = GTK_GESTURE_CLASS (klass);
object_class->constructor = gtk_gesture_zoom_constructor;
+ event_controller_class->filter_event = gtk_gesture_zoom_filter_event;
+
gesture_class->begin = gtk_gesture_zoom_begin;
gesture_class->update = gtk_gesture_zoom_update;