[libhandy] swipe-tracker: Skip update and end for swipes outside swipe area



commit d8cddd95aa3ffe20e44c90b128841843e754760f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Jun 27 18:10:12 2020 +0500

    swipe-tracker: Skip update and end for swipes outside swipe area
    
    I forgot about these, should have tested not only with HdyDeck which will
    no-op in those handlers if begin-swipe didn't happen.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-swipe-tracker.c | 45 +++++++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 12 deletions(-)
---
diff --git a/src/hdy-swipe-tracker.c b/src/hdy-swipe-tracker.c
index 32e2ebae..f78951d6 100644
--- a/src/hdy-swipe-tracker.c
+++ b/src/hdy-swipe-tracker.c
@@ -46,6 +46,7 @@ typedef enum {
   HDY_SWIPE_TRACKER_STATE_PENDING,
   HDY_SWIPE_TRACKER_STATE_SCROLLING,
   HDY_SWIPE_TRACKER_STATE_FINISHING,
+  HDY_SWIPE_TRACKER_STATE_REJECTED,
 } HdySwipeTrackerState;
 
 struct _HdySwipeTracker
@@ -128,9 +129,22 @@ static void
 gesture_prepare (HdySwipeTracker        *self,
                  HdyNavigationDirection  direction)
 {
+  GdkRectangle rect;
+
   if (self->state != HDY_SWIPE_TRACKER_STATE_NONE)
     return;
 
+  hdy_swipeable_get_swipe_area (self->swipeable, &rect);
+
+  if (self->start_x < rect.x ||
+      self->start_x >= rect.x + rect.width ||
+      self->start_y < rect.y ||
+      self->start_y >= rect.y + rect.height) {
+    self->state = HDY_SWIPE_TRACKER_STATE_REJECTED;
+
+    return;
+  }
+
   hdy_swipe_tracker_emit_begin_swipe (self, direction, TRUE);
 
   self->initial_progress = hdy_swipeable_get_progress (self->swipeable);
@@ -311,6 +325,11 @@ drag_update_cb (HdySwipeTracker *self,
 
   is_offset_vertical = (ABS (offset_y) > ABS (offset_x));
 
+  if (self->state == HDY_SWIPE_TRACKER_STATE_REJECTED) {
+    gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
+    return;
+  }
+
   if (self->state == HDY_SWIPE_TRACKER_STATE_NONE) {
     if (is_vertical == is_offset_vertical)
       gesture_prepare (self, offset > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK);
@@ -356,6 +375,13 @@ drag_end_cb (HdySwipeTracker *self,
 
   distance = hdy_swipeable_get_distance (self->swipeable);
 
+  if (self->state == HDY_SWIPE_TRACKER_STATE_REJECTED) {
+    gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
+
+    reset (self);
+    return;
+  }
+
   if (self->state != HDY_SWIPE_TRACKER_STATE_SCROLLING) {
     gesture_cancel (self, distance);
     gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
@@ -416,6 +442,13 @@ handle_scroll_event (HdySwipeTracker *self,
     return GDK_EVENT_PROPAGATE;
   }
 
+  if (self->state == HDY_SWIPE_TRACKER_STATE_REJECTED) {
+    if (gdk_event_is_scroll_stop_event (event))
+      reset (self);
+
+    return GDK_EVENT_PROPAGATE;
+  }
+
   if (self->state == HDY_SWIPE_TRACKER_STATE_NONE) {
     if (gdk_event_is_scroll_stop_event (event))
       return GDK_EVENT_PROPAGATE;
@@ -1052,18 +1085,6 @@ hdy_swipe_tracker_emit_begin_swipe (HdySwipeTracker        *self,
 {
   g_return_if_fail (HDY_IS_SWIPE_TRACKER (self));
 
-  if (direct) {
-    GdkRectangle rect;
-
-    hdy_swipeable_get_swipe_area (self->swipeable, &rect);
-
-    if (self->start_x < rect.x ||
-        self->start_x >= rect.x + rect.width ||
-        self->start_y < rect.y ||
-        self->start_y >= rect.y + rect.height)
-      return;
-  }
-
   g_signal_emit (self, signals[SIGNAL_BEGIN_SWIPE], 0, direction, direct);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]