[libadwaita/wip/exalm/begin-prepare: 3/3] swipe-tracker: Split begin-swipe and prepare




commit 4a1bf1699d312b6ec426bb20aaf30d1ffd3baca1
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Nov 9 02:20:25 2021 +0500

    swipe-tracker: Split begin-swipe and prepare
    
    Move begin-swipe to when the swipe actually starts, replace what it was
    before with a prepare signal.
    
    Currently we have a hack in AdwFlap to check starting swipe in update-swipe
    instead of begin-swipe because the latter runs too early. Now it can be
    removed.
    
    Update migration guides.
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/79

 doc/migrating-between-development-versions.md |  9 +++++++++
 doc/migrating-libhandy-1-4-to-libadwaita.md   |  7 +++++++
 src/adw-carousel.c                            |  5 ++---
 src/adw-flap.c                                | 26 +++++++++++++++---------
 src/adw-leaflet.c                             |  8 ++++----
 src/adw-swipe-tracker.c                       | 29 +++++++++++++++++++++++----
 6 files changed, 64 insertions(+), 20 deletions(-)
---
diff --git a/doc/migrating-between-development-versions.md b/doc/migrating-between-development-versions.md
index 0f119128..735d56db 100644
--- a/doc/migrating-between-development-versions.md
+++ b/doc/migrating-between-development-versions.md
@@ -261,3 +261,12 @@ The `.content` style class currently remains for compatibility purposes.
 Neither the `.content` style class nor the `.boxed-list` style class work
 for [class@Gtk.ListView], as the widget cannot currently be used for the
 boxed list pattern.
+
+## Migrating from alpha 4 to alpha 5
+
+#### Adapt to [class@Adw.SwipeTracker] API changes
+
+The [signal@Adw.SwipeTracker::begin-swipe] signal is now emitted immediately
+before the swipe starts, after the drag threshold has been reached, and it has
+lost its `direction` parameter. The new [signal@Adw.SwipeTracker::prepare]
+signal behaves exactly like `begin-swipe` was, and can be used instead of it.
diff --git a/doc/migrating-libhandy-1-4-to-libadwaita.md b/doc/migrating-libhandy-1-4-to-libadwaita.md
index c280d828..aeddba02 100644
--- a/doc/migrating-libhandy-1-4-to-libadwaita.md
+++ b/doc/migrating-libhandy-1-4-to-libadwaita.md
@@ -322,6 +322,13 @@ equivalent to `ADW_COLOR_SCHEME_PREFER_LIGHT` instead of
 default. Make sure your application works with it, or otherwise set the
 `ADW_COLOR_SCHEME_FORCE_LIGHT` color scheme manually.
 
+### Adapt to [class@Adw.SwipeTracker] API changes
+
+The [signal@Adw.SwipeTracker::begin-swipe] signal is now emitted immediately
+before the swipe starts, after the drag threshold has been reached, and it has
+lost its `direction` parameter. The new [signal@Adw.SwipeTracker::prepare]
+signal behaves exactly like `begin-swipe` was, and can be used instead of it.
+
 ### Adapt to Stylesheet Changes
 
 Most widgets don't have a backdrop state anymore, and the following public
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 4bb82b41..4dfead4b 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -410,9 +410,8 @@ get_closest_snap_point (AdwCarousel *self)
 }
 
 static void
-begin_swipe_cb (AdwSwipeTracker        *tracker,
-                AdwNavigationDirection  direction,
-                AdwCarousel            *self)
+begin_swipe_cb (AdwSwipeTracker *tracker,
+                AdwCarousel     *self)
 {
   if (self->animation)
     adw_animation_stop (self->animation);
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 17b66029..0d67726d 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -419,20 +419,27 @@ get_start_or_end (AdwFlap *self)
   return (is_rtl && is_horiz) ? GTK_PACK_END : GTK_PACK_START;
 }
 
+static void
+begin_swipe_cb (AdwSwipeTracker *tracker,
+                AdwFlap         *self)
+{
+  if (self->reveal_progress <= 0 && !self->swipe_to_open)
+    return;
+
+  if (self->reveal_progress >= 1 && !self->swipe_to_close)
+    return;
+
+  if (self->reveal_animation)
+    adw_animation_stop (self->reveal_animation);
+
+  self->swipe_active = TRUE;
+}
+
 static void
 update_swipe_cb (AdwSwipeTracker *tracker,
                  double           progress,
                  AdwFlap         *self)
 {
-  if (!self->swipe_active &&
-      (self->reveal_progress > 0 || self->swipe_to_open) &&
-      (self->reveal_progress < 1 || self->swipe_to_close)) {
-    if (self->reveal_animation)
-      adw_animation_stop (self->reveal_animation);
-
-    self->swipe_active = TRUE;
-  }
-
   set_reveal_progress (self, progress);
 }
 
@@ -1587,6 +1594,7 @@ adw_flap_init (AdwFlap *self)
   self->tracker = adw_swipe_tracker_new (ADW_SWIPEABLE (self));
   adw_swipe_tracker_set_enabled (self->tracker, FALSE);
 
+  g_signal_connect_object (self->tracker, "begin-swipe", G_CALLBACK (begin_swipe_cb), self, 0);
   g_signal_connect_object (self->tracker, "update-swipe", G_CALLBACK (update_swipe_cb), self, 0);
   g_signal_connect_object (self->tracker, "end-swipe", G_CALLBACK (end_swipe_cb), self, 0);
 
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index 23ad219c..bdad663c 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -1513,9 +1513,9 @@ set_orientation (AdwLeaflet     *self,
 }
 
 static void
-begin_swipe_cb (AdwSwipeTracker        *tracker,
-                AdwNavigationDirection  direction,
-                AdwLeaflet             *self)
+prepare_cb (AdwSwipeTracker        *tracker,
+            AdwNavigationDirection  direction,
+            AdwLeaflet             *self)
 {
   self->child_transition.swipe_direction = direction;
 
@@ -2442,7 +2442,7 @@ adw_leaflet_init (AdwLeaflet *self)
 
   g_object_set (self->tracker, "orientation", self->orientation, "enabled", FALSE, NULL);
 
-  g_signal_connect_object (self->tracker, "begin-swipe", G_CALLBACK (begin_swipe_cb), self, 0);
+  g_signal_connect_object (self->tracker, "prepare", G_CALLBACK (prepare_cb), self, 0);
   g_signal_connect_object (self->tracker, "update-swipe", G_CALLBACK (update_swipe_cb), self, 0);
   g_signal_connect_object (self->tracker, "end-swipe", G_CALLBACK (end_swipe_cb), self, 0);
 
diff --git a/src/adw-swipe-tracker.c b/src/adw-swipe-tracker.c
index 1da0e89f..459e0dc9 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -110,6 +110,7 @@ enum {
 static GParamSpec *props[LAST_PROP];
 
 enum {
+  SIGNAL_PREPARE,
   SIGNAL_BEGIN_SWIPE,
   SIGNAL_UPDATE_SWIPE,
   SIGNAL_END_SWIPE,
@@ -184,7 +185,7 @@ gesture_prepare (AdwSwipeTracker        *self,
   if (self->state != ADW_SWIPE_TRACKER_STATE_NONE)
     return;
 
-  g_signal_emit (self, signals[SIGNAL_BEGIN_SWIPE], 0, direction);
+  g_signal_emit (self, signals[SIGNAL_PREPARE], 0, direction);
 
   self->initial_progress = adw_swipeable_get_progress (self->swipeable);
   self->progress = self->initial_progress;
@@ -257,6 +258,8 @@ gesture_begin (AdwSwipeTracker *self)
     return;
 
   self->state = ADW_SWIPE_TRACKER_STATE_SCROLLING;
+
+  g_signal_emit (self, signals[SIGNAL_BEGIN_SWIPE], 0);
 }
 
 static int
@@ -1087,7 +1090,7 @@ adw_swipe_tracker_class_init (AdwSwipeTrackerClass *klass)
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
   /**
-   * AdwSwipeTracker::begin-swipe:
+   * AdwSwipeTracker::prepare:
    * @self: the `AdwSwipeTracker` instance
    * @direction: the direction of the swipe
    *
@@ -1098,8 +1101,8 @@ adw_swipe_tracker_class_init (AdwSwipeTrackerClass *klass)
    *
    * Since: 1.0
    */
-  signals[SIGNAL_BEGIN_SWIPE] =
-    g_signal_new ("begin-swipe",
+  signals[SIGNAL_PREPARE] =
+    g_signal_new ("prepare",
                   G_TYPE_FROM_CLASS (klass),
                   G_SIGNAL_RUN_FIRST,
                   0,
@@ -1108,6 +1111,24 @@ adw_swipe_tracker_class_init (AdwSwipeTrackerClass *klass)
                   1,
                   ADW_TYPE_NAVIGATION_DIRECTION);
 
+  /**
+   * AdwSwipeTracker::begin-swipe:
+   * @self: the `AdwSwipeTracker` instance
+   *
+   * This signal is emitted right before a swipe will be started, after the
+   * drag threshold has been passed.
+   *
+   * Since: 1.0
+   */
+  signals[SIGNAL_BEGIN_SWIPE] =
+    g_signal_new ("begin-swipe",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE,
+                  0);
+
   /**
    * AdwSwipeTracker::update-swipe:
    * @self: the `AdwSwipeTracker` instance


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