[libhandy] swipeable: Add params to get_swipe_area()



commit 581c3b1048043c793722d20abd0ce2ccf329d3db
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Jul 15 12:29:44 2020 +0200

    swipeable: Add params to get_swipe_area()
    
    Add a navigation direction param and a gesture type param to
    get_swipe_area(). This allows having different swipe areas for swipes
    back and forward, and for drag swipes and non-drag swipes, which is
    needed to support e.g. swiping back from anywhere and swiping forward
    from the border with an 'over' transition on touchscreens, while
    changing nothing on touchpads.

 src/hdy-swipe-tracker.c |  9 +++++----
 src/hdy-swipeable.c     | 18 ++++++++++++------
 src/hdy-swipeable.h     | 12 ++++++++----
 3 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/src/hdy-swipe-tracker.c b/src/hdy-swipe-tracker.c
index f6f6d916..60a3a3b1 100644
--- a/src/hdy-swipe-tracker.c
+++ b/src/hdy-swipe-tracker.c
@@ -140,14 +140,15 @@ get_range (HdySwipeTracker *self,
 
 static void
 gesture_prepare (HdySwipeTracker        *self,
-                 HdyNavigationDirection  direction)
+                 HdyNavigationDirection  direction,
+                 gboolean                is_drag)
 {
   GdkRectangle rect;
 
   if (self->state != HDY_SWIPE_TRACKER_STATE_NONE)
     return;
 
-  hdy_swipeable_get_swipe_area (self->swipeable, &rect);
+  hdy_swipeable_get_swipe_area (self->swipeable, direction, is_drag, &rect);
 
   if (self->start_x < rect.x ||
       self->start_x >= rect.x + rect.width ||
@@ -345,7 +346,7 @@ drag_update_cb (HdySwipeTracker *self,
 
   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);
+      gesture_prepare (self, offset > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK, 
TRUE);
     else
       gtk_gesture_set_state (self->touch_gesture, GTK_EVENT_SEQUENCE_DENIED);
     return;
@@ -476,7 +477,7 @@ handle_scroll_event (HdySwipeTracker *self,
                                           event_x, event_y,
                                           &self->start_x, &self->start_y);
 
-        gesture_prepare (self, delta > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK);
+        gesture_prepare (self, delta > 0 ? HDY_NAVIGATION_DIRECTION_FORWARD : HDY_NAVIGATION_DIRECTION_BACK, 
FALSE);
       }
     } else {
       self->is_scrolling = TRUE;
diff --git a/src/hdy-swipeable.c b/src/hdy-swipeable.c
index d2d4b9b4..dcd16220 100644
--- a/src/hdy-swipeable.c
+++ b/src/hdy-swipeable.c
@@ -228,11 +228,15 @@ hdy_swipeable_get_cancel_progress (HdySwipeable *self)
 /**
  * hdy_swipeable_get_swipe_area:
  * @self: a #HdySwipeable
+ * @navigation_direction: the direction of the swipe
+ * @is_drag: whether the swipe is caused by a dragging gesture
  * @rect: (out): a pointer to a #GdkRectangle to store the swipe area
  *
- * Gets the area @self can start a swipe from. This can be used to restrict
- * swipes to only be possible from a certain area, for example, to only allow
- * edge swipes, or to have a draggable element and ignore swipes elsewhere.
+ * Gets the area @self can start a swipe from for the given direction and
+ * gesture type.
+ * This can be used to restrict swipes to only be possible from a certain area,
+ * for example, to only allow edge swipes, or to have a draggable element and
+ * ignore swipes elsewhere.
  *
  * Swipe area is only considered for direct swipes (as in, not initiated by
  * #HdySwipeGroup).
@@ -243,8 +247,10 @@ hdy_swipeable_get_cancel_progress (HdySwipeable *self)
  * Since: 1.0
  */
 void
-hdy_swipeable_get_swipe_area (HdySwipeable *self,
-                              GdkRectangle *rect)
+hdy_swipeable_get_swipe_area (HdySwipeable           *self,
+                              HdyNavigationDirection  navigation_direction,
+                              gboolean                is_drag,
+                              GdkRectangle           *rect)
 {
   HdySwipeableInterface *iface;
 
@@ -254,7 +260,7 @@ hdy_swipeable_get_swipe_area (HdySwipeable *self,
   iface = HDY_SWIPEABLE_GET_IFACE (self);
 
   if (iface->get_swipe_area) {
-    (* iface->get_swipe_area) (self, rect);
+    (* iface->get_swipe_area) (self, navigation_direction, is_drag, rect);
     return;
   }
 
diff --git a/src/hdy-swipeable.h b/src/hdy-swipeable.h
index 893c37dc..1218d624 100644
--- a/src/hdy-swipeable.h
+++ b/src/hdy-swipeable.h
@@ -50,8 +50,10 @@ struct _HdySwipeableInterface
                                             gint         *n_snap_points);
   gdouble           (*get_progress)        (HdySwipeable *self);
   gdouble           (*get_cancel_progress) (HdySwipeable *self);
-  void              (*get_swipe_area)      (HdySwipeable *self,
-                                            GdkRectangle *rect);
+  void              (*get_swipe_area)      (HdySwipeable           *self,
+                                            HdyNavigationDirection  navigation_direction,
+                                            gboolean                is_drag,
+                                            GdkRectangle           *rect);
 };
 
 void hdy_swipeable_switch_child (HdySwipeable *self,
@@ -68,7 +70,9 @@ gdouble         *hdy_swipeable_get_snap_points     (HdySwipeable *self,
                                                     gint         *n_snap_points);
 gdouble          hdy_swipeable_get_progress        (HdySwipeable *self);
 gdouble          hdy_swipeable_get_cancel_progress (HdySwipeable *self);
-void             hdy_swipeable_get_swipe_area      (HdySwipeable *self,
-                                                    GdkRectangle *rect);
+void             hdy_swipeable_get_swipe_area      (HdySwipeable           *self,
+                                                    HdyNavigationDirection  navigation_direction,
+                                                    gboolean                is_drag,
+                                                    GdkRectangle           *rect);
 
 G_END_DECLS


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