[gnome-software/wip/mcrha/libadwaita-api-changes] build: Prepare for AdwCarousel API changes




commit ac4bdf54a2125c3ec456e74e0258f83755f53215
Author: Milan Crha <mcrha redhat com>
Date:   Tue Dec 7 10:22:33 2021 +0100

    build: Prepare for AdwCarousel API changes
    
    The libadwaita 1.0.0.beta.1 contains API changes in AdwCarousel,
    thus prepare for it, but do not require newer libadwaita yet.

 meson.build                  | 13 +++++++++++++
 src/gs-featured-carousel.c   |  8 ++++++++
 src/gs-screenshot-carousel.c |  7 ++++++-
 3 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 9098324ad..423519543 100644
--- a/meson.build
+++ b/meson.build
@@ -148,6 +148,19 @@ libadwaita = dependency('libadwaita-1',
     ]
   )
 
+# FIXME: These libadwaita checks can be dropped when we depend on 1.0.0.beta.1
+if libadwaita.type_name() == 'internal'
+  conf.set('HAVE_ADW_CAROUSEL_GET_ANIMATION_DURATION', '1')
+  conf.set('HAVE_ADW_CAROUSEL_SCROLL_TO_FULL', '1')
+else
+  if meson.get_compiler('c').has_function('adw_carousel_get_animation_duration', prefix: '#include 
<adwaita.h>', dependencies: libadwaita)
+    conf.set('HAVE_ADW_CAROUSEL_GET_ANIMATION_DURATION', '1')
+  endif
+  if meson.get_compiler('c').has_function('adw_carousel_scroll_to_full', prefix: '#include <adwaita.h>', 
dependencies: libadwaita)
+    conf.set('HAVE_ADW_CAROUSEL_SCROLL_TO_FULL', '1')
+  endif
+endif
+
 libsysprof_capture_dep = dependency('sysprof-capture-4',
   required: get_option('sysprof'),
   default_options: [
diff --git a/src/gs-featured-carousel.c b/src/gs-featured-carousel.c
index 73b5938b8..5b83fe846 100644
--- a/src/gs-featured-carousel.c
+++ b/src/gs-featured-carousel.c
@@ -83,7 +83,11 @@ show_relative_page (GsFeaturedCarousel *self,
        guint n_pages = adw_carousel_get_n_pages (self->carousel);
        gdouble new_page;
        GtkWidget *new_page_widget;
+#ifdef HAVE_ADW_CAROUSEL_GET_ANIMATION_DURATION
        gint64 animation_duration_ms = adw_carousel_get_animation_duration (self->carousel);
+#else
+       gint64 animation_duration_ms = 1; /* Switch to boolean once the dependency is 1.0.0.beta.1 at least */
+#endif
 
        if (n_pages == 0)
                return;
@@ -101,7 +105,11 @@ show_relative_page (GsFeaturedCarousel *self,
        if ((new_page == 0.0 && delta > 0) || (new_page == n_pages - 1 && delta < 0))
                animation_duration_ms = 0;
 
+#ifdef HAVE_ADW_CAROUSEL_SCROLL_TO_FULL
        adw_carousel_scroll_to_full (self->carousel, new_page_widget, animation_duration_ms);
+#else
+       adw_carousel_scroll_to (self->carousel, new_page_widget, animation_duration_ms != 0);
+#endif
 }
 
 static gboolean
diff --git a/src/gs-screenshot-carousel.c b/src/gs-screenshot-carousel.c
index f9051892d..09965d634 100644
--- a/src/gs-screenshot-carousel.c
+++ b/src/gs-screenshot-carousel.c
@@ -200,8 +200,13 @@ _carousel_navigate (AdwCarousel *carousel, AdwNavigationDirection direction)
        position = MAX (0, position);
 
        child = g_list_nth_data (children, position);
-       if (child)
+       if (child) {
+#ifdef HAVE_ADW_CAROUSEL_SCROLL_TO_FULL
                adw_carousel_scroll_to (carousel, child);
+#else
+               adw_carousel_scroll_to (carousel, child, TRUE);
+#endif
+       }
 }
 
 static void


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