[libhandy] swipe-tracker: Add allow-long-swipes property



commit 82d6c2d9574c84d4278f7d087b9913e67e7de424
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Jul 9 19:31:13 2020 +0500

    swipe-tracker: Add allow-long-swipes property
    
    Since we now have the ability to support swiping through multiple pages,
    expose it as a property.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 debian/libhandy-1-0.symbols |  2 +
 src/hdy-swipe-tracker.c     | 95 +++++++++++++++++++++++++++++++++++++++++----
 src/hdy-swipe-tracker.h     |  6 +++
 3 files changed, 95 insertions(+), 8 deletions(-)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 72363c3c..0c8aebb2 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -311,12 +311,14 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
  hdy_swipe_group_get_type@LIBHANDY_1_0 0.0.12
  hdy_swipe_group_new@LIBHANDY_1_0 0.0.12
  hdy_swipe_group_remove_swipeable@LIBHANDY_1_0 0.0.12
+ hdy_swipe_tracker_get_allow_long_swipes@LIBHANDY_1_0 1.1.0
  hdy_swipe_tracker_get_allow_mouse_drag@LIBHANDY_1_0 0.0.12
  hdy_swipe_tracker_get_enabled@LIBHANDY_1_0 0.0.11
  hdy_swipe_tracker_get_reversed@LIBHANDY_1_0 0.0.11
  hdy_swipe_tracker_get_swipeable@LIBHANDY_1_0 0.82.0
  hdy_swipe_tracker_get_type@LIBHANDY_1_0 0.0.11
  hdy_swipe_tracker_new@LIBHANDY_1_0 0.0.11
+ hdy_swipe_tracker_set_allow_long_swipes@LIBHANDY_1_0 1.1.0
  hdy_swipe_tracker_set_allow_mouse_drag@LIBHANDY_1_0 0.0.12
  hdy_swipe_tracker_set_enabled@LIBHANDY_1_0 0.0.11
  hdy_swipe_tracker_set_reversed@LIBHANDY_1_0 0.0.11
diff --git a/src/hdy-swipe-tracker.c b/src/hdy-swipe-tracker.c
index 5133e7b6..7fed5ef3 100644
--- a/src/hdy-swipe-tracker.c
+++ b/src/hdy-swipe-tracker.c
@@ -69,6 +69,7 @@ struct _HdySwipeTracker
   gboolean enabled;
   gboolean reversed;
   gboolean allow_mouse_drag;
+  gboolean allow_long_swipes;
   GtkOrientation orientation;
 
   GArray *event_history;
@@ -98,10 +99,11 @@ enum {
   PROP_ENABLED,
   PROP_REVERSED,
   PROP_ALLOW_MOUSE_DRAG,
+  PROP_ALLOW_LONG_SWIPES,
 
   /* GtkOrientable */
   PROP_ORIENTATION,
-  LAST_PROP = PROP_ALLOW_MOUSE_DRAG + 1,
+  LAST_PROP = PROP_ALLOW_LONG_SWIPES + 1,
 };
 
 static GParamSpec *props[LAST_PROP];
@@ -375,14 +377,19 @@ gesture_update (HdySwipeTracker *self,
 {
   gdouble lower, upper;
   gdouble progress;
-  g_autofree gdouble *points = NULL;
-  gint n;
 
   if (self->state != HDY_SWIPE_TRACKER_STATE_SCROLLING)
     return;
 
-  points = hdy_swipeable_get_snap_points (self->swipeable, &n);
-  get_bounds (self, points, n, self->initial_progress, &lower, &upper);
+  if (!self->allow_long_swipes) {
+    g_autofree gdouble *points = NULL;
+    gint n;
+
+    points = hdy_swipeable_get_snap_points (self->swipeable, &n);
+    get_bounds (self, points, n, self->initial_progress, &lower, &upper);
+  } else {
+    get_range (self, &lower, &upper);
+  }
 
   progress = self->progress + delta;
   progress = CLAMP (progress, lower, upper);
@@ -397,7 +404,7 @@ get_end_progress (HdySwipeTracker *self,
                   gdouble          velocity,
                   gboolean         is_touchpad)
 {
-  gdouble pos, decel, slope, lower, upper;
+  gdouble pos, decel, slope;
   g_autofree gdouble *points = NULL;
   gint n;
 
@@ -425,9 +432,13 @@ get_end_progress (HdySwipeTracker *self,
 
   pos = (pos * SIGN (velocity)) + self->progress;
 
-  get_bounds (self, points, n, self->initial_progress, &lower, &upper);
+  if (!self->allow_long_swipes) {
+    gdouble lower, upper;
 
-  pos = CLAMP (pos, lower, upper);
+    get_bounds (self, points, n, self->initial_progress, &lower, &upper);
+
+    pos = CLAMP (pos, lower, upper);
+  }
 
   pos = points[find_point_for_projection (self, points, n, pos, velocity)];
 
@@ -953,6 +964,10 @@ hdy_swipe_tracker_get_property (GObject    *object,
     g_value_set_boolean (value, hdy_swipe_tracker_get_allow_mouse_drag (self));
     break;
 
+  case PROP_ALLOW_LONG_SWIPES:
+    g_value_set_boolean (value, hdy_swipe_tracker_get_allow_long_swipes (self));
+    break;
+
   case PROP_ORIENTATION:
     g_value_set_enum (value, self->orientation);
     break;
@@ -987,6 +1002,10 @@ hdy_swipe_tracker_set_property (GObject      *object,
     hdy_swipe_tracker_set_allow_mouse_drag (self, g_value_get_boolean (value));
     break;
 
+  case PROP_ALLOW_LONG_SWIPES:
+    hdy_swipe_tracker_set_allow_long_swipes (self, g_value_get_boolean (value));
+    break;
+
   case PROP_ORIENTATION:
     {
       GtkOrientation orientation = g_value_get_enum (value);
@@ -1071,6 +1090,21 @@ hdy_swipe_tracker_class_init (HdySwipeTrackerClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * HdySwipeTracker:allow-long-swipes:
+   *
+   * Whether to allow swiping for more than one snap point at a time. If the
+   * value is %FALSE, each swipe can only move to the adjacent snap points.
+   *
+   * Since: 1.1
+   */
+  props[PROP_ALLOW_LONG_SWIPES] =
+    g_param_spec_boolean ("allow-long-swipes",
+                          _("Allow long swipes"),
+                          _("Whether to allow swiping for more than one snap point at a time"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
                                     "orientation");
@@ -1327,6 +1361,51 @@ hdy_swipe_tracker_set_allow_mouse_drag (HdySwipeTracker *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
 }
 
+/**
+ * hdy_swipe_tracker_get_allow_long_swipes:
+ * @self: a #HdySwipeTracker
+ *
+ * Whether to allow swiping for more than one snap point at a time. If the
+ * value is %FALSE, each swipe can only move to the adjacent snap points.
+ *
+ * Returns: %TRUE if long swipes are allowed, %FALSE otherwise
+ *
+ * Since: 1.1
+ */
+gboolean
+hdy_swipe_tracker_get_allow_long_swipes (HdySwipeTracker *self)
+{
+  g_return_val_if_fail (HDY_IS_SWIPE_TRACKER (self), FALSE);
+
+  return self->allow_long_swipes;
+}
+
+/**
+ * hdy_swipe_tracker_set_allow_long_swipes:
+ * @self: a #HdySwipeTracker
+ * @allow_long_swipes: whether to allow long swipes
+ *
+ * Sets whether to allow swiping for more than one snap point at a time. If the
+ * value is %FALSE, each swipe can only move to the adjacent snap points.
+ *
+ * Since: 1.1
+ */
+void
+hdy_swipe_tracker_set_allow_long_swipes (HdySwipeTracker *self,
+                                         gboolean         allow_long_swipes)
+{
+  g_return_if_fail (HDY_IS_SWIPE_TRACKER (self));
+
+  allow_long_swipes = !!allow_long_swipes;
+
+  if (self->allow_long_swipes == allow_long_swipes)
+    return;
+
+  self->allow_long_swipes = allow_long_swipes;
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_LONG_SWIPES]);
+}
+
 /**
  * hdy_swipe_tracker_shift_position:
  * @self: a #HdySwipeTracker
diff --git a/src/hdy-swipe-tracker.h b/src/hdy-swipe-tracker.h
index 20fe751f..471f71c1 100644
--- a/src/hdy-swipe-tracker.h
+++ b/src/hdy-swipe-tracker.h
@@ -46,6 +46,12 @@ HDY_AVAILABLE_IN_ALL
 void             hdy_swipe_tracker_set_allow_mouse_drag (HdySwipeTracker *self,
                                                          gboolean         allow_mouse_drag);
 
+HDY_AVAILABLE_IN_1_1
+gboolean         hdy_swipe_tracker_get_allow_long_swipes (HdySwipeTracker *self);
+HDY_AVAILABLE_IN_1_1
+void             hdy_swipe_tracker_set_allow_long_swipes (HdySwipeTracker *self,
+                                                          gboolean         allow_long_swipes);
+
 HDY_AVAILABLE_IN_ALL
 void             hdy_swipe_tracker_shift_position (HdySwipeTracker *self,
                                                    gdouble          delta);


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