[libadwaita/wip/exalm/begin-prepare] swipe-tracker: Split begin-swipe and prepare
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/begin-prepare] swipe-tracker: Split begin-swipe and prepare
- Date: Mon, 8 Nov 2021 21:37:20 +0000 (UTC)
commit 25df5d5ef891ac79b2fd392812b121ff0c87aca9
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 5cfac2d4..1705f4e7 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -409,9 +409,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 e2c40f3f..47972d6d 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -418,20 +418,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);
}
@@ -1586,6 +1593,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 c5d6245e..7917954e 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -1512,9 +1512,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;
@@ -2441,7 +2441,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 7bc65a20..c29c1dd7 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -109,6 +109,7 @@ enum {
static GParamSpec *props[LAST_PROP];
enum {
+ SIGNAL_PREPARE,
SIGNAL_BEGIN_SWIPE,
SIGNAL_UPDATE_SWIPE,
SIGNAL_END_SWIPE,
@@ -183,7 +184,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;
@@ -256,6 +257,8 @@ gesture_begin (AdwSwipeTracker *self)
return;
self->state = ADW_SWIPE_TRACKER_STATE_SCROLLING;
+
+ g_signal_emit (self, signals[SIGNAL_BEGIN_SWIPE], 0);
}
static int
@@ -1086,7 +1089,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
*
@@ -1097,8 +1100,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,
@@ -1107,6 +1110,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]