summaryrefslogtreecommitdiff
path: root/gtk/gtkgestureswipe.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-04-08 21:19:46 +0200
committerCarlos Garnacho <carlosg@gnome.org>2014-05-23 19:54:26 +0200
commit2166be96d2cc6dd133a13566ee85fa35fc04a4b2 (patch)
tree7346d4d8e9e483b487459e15001639598689fd37 /gtk/gtkgestureswipe.c
parentbd722499dcf4d3af8ec7f28600d72de131cb1f64 (diff)
downloadgtk+-2166be96d2cc6dd133a13566ee85fa35fc04a4b2.tar.gz
swipe: Add function to retrieve the current velocity
This can be used to fetch the current velocity on update(), as opposed to swipe() which happens after the sequence is finished.
Diffstat (limited to 'gtk/gtkgestureswipe.c')
-rw-r--r--gtk/gtkgestureswipe.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/gtk/gtkgestureswipe.c b/gtk/gtkgestureswipe.c
index d04504a276..e4f6e29dfa 100644
--- a/gtk/gtkgestureswipe.c
+++ b/gtk/gtkgestureswipe.c
@@ -109,13 +109,18 @@ _gtk_gesture_swipe_calculate_velocity (GtkGestureSwipe *gesture,
gdouble *velocity_y)
{
GtkGestureSwipePrivate *priv;
+ GdkEventSequence *sequence;
+ guint32 evtime, diff_time;
EventData *start, *end;
gdouble diff_x, diff_y;
- guint32 diff_time;
priv = gtk_gesture_swipe_get_instance_private (gesture);
*velocity_x = *velocity_y = 0;
+ sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
+ gtk_gesture_get_last_update_time (GTK_GESTURE (gesture), sequence, &evtime);
+ _gtk_gesture_swipe_clear_backlog (gesture, evtime);
+
if (priv->events->len == 0)
return;
@@ -141,14 +146,14 @@ gtk_gesture_swipe_end (GtkGesture *gesture,
GtkGestureSwipe *swipe = GTK_GESTURE_SWIPE (gesture);
GtkGestureSwipePrivate *priv;
gdouble velocity_x, velocity_y;
- guint32 evtime;
+ GdkEventSequence *seq;
+
+ seq = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
- if (gtk_gesture_get_sequence_state (gesture, sequence) == GTK_EVENT_SEQUENCE_DENIED)
+ if (gtk_gesture_get_sequence_state (gesture, seq) == GTK_EVENT_SEQUENCE_DENIED)
return;
priv = gtk_gesture_swipe_get_instance_private (swipe);
- gtk_gesture_get_last_update_time (gesture, sequence, &evtime);
- _gtk_gesture_swipe_clear_backlog (swipe, evtime);
_gtk_gesture_swipe_calculate_velocity (swipe, &velocity_x, &velocity_y);
g_signal_emit (gesture, signals[SWIPE], 0, velocity_x, velocity_y);
@@ -202,3 +207,25 @@ gtk_gesture_swipe_new (GtkWidget *widget)
"widget", widget,
NULL);
}
+
+gboolean
+gtk_gesture_swipe_get_velocity (GtkGestureSwipe *gesture,
+ gdouble *velocity_x,
+ gdouble *velocity_y)
+{
+ gdouble vel_x, vel_y;
+
+ g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
+
+ if (!gtk_gesture_is_recognized (GTK_GESTURE (gesture)))
+ return FALSE;
+
+ _gtk_gesture_swipe_calculate_velocity (gesture, &vel_x, &vel_y);
+
+ if (velocity_x)
+ *velocity_x = vel_x;
+ if (velocity_y)
+ *velocity_y = vel_y;
+
+ return TRUE;
+}