[gtk/wip/exalm/scroll-gesture: 5/11] gestureswipe: Don't emit :swipe for cancelled gestures
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/scroll-gesture: 5/11] gestureswipe: Don't emit :swipe for cancelled gestures
- Date: Tue, 28 Sep 2021 19:33:51 +0000 (UTC)
commit d516468dfd82fda5430dbaf5bc202a80c4531bf0
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Fri Sep 17 18:39:33 2021 +0500
gestureswipe: Don't emit :swipe for cancelled gestures
Turns out that it was emitting the :swipe signal when ending the gesture
unconditionally, even if was cancelled. That shouldn't happen.
gtk/gtkgestureswipe.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkgestureswipe.c b/gtk/gtkgestureswipe.c
index 9540fa6df3..991e7bf860 100644
--- a/gtk/gtkgestureswipe.c
+++ b/gtk/gtkgestureswipe.c
@@ -58,6 +58,7 @@ struct _EventData
struct _GtkGestureSwipePrivate
{
GArray *events;
+ gboolean cancelled;
};
enum {
@@ -148,6 +149,16 @@ gtk_gesture_swipe_append_event (GtkGestureSwipe *swipe,
g_array_append_val (priv->events, new);
}
+static void
+gtk_gesture_swipe_begin (GtkGesture *gesture,
+ GdkEventSequence *sequence)
+{
+ GtkGestureSwipe *swipe = GTK_GESTURE_SWIPE (gesture);
+ GtkGestureSwipePrivate *priv = gtk_gesture_swipe_get_instance_private (swipe);
+
+ priv->cancelled = FALSE;
+}
+
static void
gtk_gesture_swipe_update (GtkGesture *gesture,
GdkEventSequence *sequence)
@@ -198,10 +209,13 @@ gtk_gesture_swipe_end (GtkGesture *gesture,
GdkEventSequence *sequence)
{
GtkGestureSwipe *swipe = GTK_GESTURE_SWIPE (gesture);
- GtkGestureSwipePrivate *priv;
+ GtkGestureSwipePrivate *priv = gtk_gesture_swipe_get_instance_private (swipe);
double velocity_x, velocity_y;
GdkEventSequence *seq;
+ if (priv->cancelled)
+ return;
+
seq = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
if (gtk_gesture_get_sequence_state (gesture, seq) == GTK_EVENT_SEQUENCE_DENIED)
@@ -212,7 +226,6 @@ gtk_gesture_swipe_end (GtkGesture *gesture,
gtk_gesture_swipe_append_event (swipe, sequence);
- priv = gtk_gesture_swipe_get_instance_private (swipe);
_gtk_gesture_swipe_calculate_velocity (swipe, &velocity_x, &velocity_y);
g_signal_emit (gesture, signals[SWIPE], 0, velocity_x, velocity_y);
@@ -220,6 +233,18 @@ gtk_gesture_swipe_end (GtkGesture *gesture,
g_array_remove_range (priv->events, 0, priv->events->len);
}
+static void
+gtk_gesture_swipe_cancel (GtkGesture *gesture,
+ GdkEventSequence *sequence)
+{
+ GtkGestureSwipe *swipe = GTK_GESTURE_SWIPE (gesture);
+ GtkGestureSwipePrivate *priv = gtk_gesture_swipe_get_instance_private (swipe);
+
+ priv->cancelled = TRUE;
+
+ GTK_GESTURE_CLASS (gtk_gesture_swipe_parent_class)->cancel (gesture, sequence);
+}
+
static void
gtk_gesture_swipe_class_init (GtkGestureSwipeClass *klass)
{
@@ -231,8 +256,10 @@ gtk_gesture_swipe_class_init (GtkGestureSwipeClass *klass)
event_controller_class->filter_event = gtk_gesture_swipe_filter_event;
+ gesture_class->begin = gtk_gesture_swipe_begin;
gesture_class->update = gtk_gesture_swipe_update;
gesture_class->end = gtk_gesture_swipe_end;
+ gesture_class->cancel = gtk_gesture_swipe_cancel;
/**
* GtkGestureSwipe::swipe:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]