[libadwaita/bilelmoussaoui/carousel-cb] carousel: Avoid race condition on animation callback
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/bilelmoussaoui/carousel-cb] carousel: Avoid race condition on animation callback
- Date: Wed, 1 Jun 2022 11:19:39 +0000 (UTC)
commit fd4577f3b5237cc59a19cc41b6c32108507d21a6
Author: Bilal Elmoussaoui <belmouss redhat com>
Date: Wed Jun 1 13:19:09 2022 +0200
carousel: Avoid race condition on animation callback
The callback uses the resize animation to get the animated carousel
in case the animation was not created yet
Fixes #453
src/adw-carousel.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 6b115f03..b45164dc 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -82,6 +82,11 @@ struct _AdwCarousel
gboolean can_scroll;
};
+typedef struct {
+ ChildInfo *child;
+ AdwCarousel *carousel;
+} AnimationData;
+
static void adw_carousel_buildable_init (GtkBuildableIface *iface);
static void adw_carousel_swipeable_init (AdwSwipeableInterface *iface);
@@ -284,10 +289,11 @@ set_position (AdwCarousel *self,
}
static void
-resize_animation_value_cb (double value,
- ChildInfo *child)
+resize_animation_value_cb (double value,
+ AnimationData *data)
{
- AdwCarousel *self = ADW_CAROUSEL (adw_animation_get_widget (child->resize_animation));
+ AdwCarousel *self = data->carousel;
+ ChildInfo *child = data->child;
double delta = value - child->size;
child->size = value;
@@ -325,15 +331,20 @@ animate_child_resize (AdwCarousel *self,
{
AdwAnimationTarget *target;
double old_size = child->size;
+ AnimationData *data;
update_shift_position_flag (self, child);
if (child->resize_animation)
adw_animation_skip (child->resize_animation);
+ data = g_new (AnimationData, 1);
+ data->child = child;
+ data->carousel = self;
+
target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
resize_animation_value_cb,
- child, NULL);
+ data, NULL);
child->resize_animation =
adw_timed_animation_new (GTK_WIDGET (self), old_size,
value, duration, target);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]