[libadwaita/wip/exalm/swipe-group: 137/143] swipeable: Remove switch_child()




commit 06a06d8abb01e70b011764508db0ae9677e64636
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Feb 26 14:33:54 2021 +0500

    swipeable: Remove switch_child()
    
    This was only needed for AdwSwipeGroup.

 src/adw-carousel.c  | 16 ---------
 src/adw-flap.c      | 26 +++------------
 src/adw-leaflet.c   | 93 ++++++-----------------------------------------------
 src/adw-swipeable.c | 78 --------------------------------------------
 src/adw-swipeable.h | 15 ---------
 5 files changed, 15 insertions(+), 213 deletions(-)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index fd5e9e7..15fe8c9 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -1052,17 +1052,6 @@ adw_carousel_buildable_init (GtkBuildableIface *iface)
   iface->add_child = adw_carousel_buildable_add_child;
 }
 
-static void
-adw_carousel_switch_child (AdwSwipeable *swipeable,
-                           guint         index,
-                           gint64        duration)
-{
-  AdwCarousel *self = ADW_CAROUSEL (swipeable);
-  GtkWidget *child = adw_carousel_get_nth_page (self, index);
-
-  scroll_to (self, child, duration);
-}
-
 static AdwSwipeTracker *
 adw_carousel_get_swipe_tracker (AdwSwipeable *swipeable)
 {
@@ -1123,7 +1112,6 @@ adw_carousel_get_cancel_progress (AdwSwipeable *swipeable)
 static void
 adw_carousel_swipeable_init (AdwSwipeableInterface *iface)
 {
-  iface->switch_child = adw_carousel_switch_child;
   iface->get_swipe_tracker = adw_carousel_get_swipe_tracker;
   iface->get_distance = adw_carousel_get_distance;
   iface->get_snap_points = adw_carousel_get_snap_points;
@@ -1356,15 +1344,11 @@ adw_carousel_scroll_to_full (AdwCarousel *self,
                              GtkWidget   *widget,
                              gint64       duration)
 {
-  int index;
-
   g_return_if_fail (ADW_IS_CAROUSEL (self));
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (duration >= 0);
 
-  index = find_child_index (self, widget, FALSE);
   scroll_to (self, widget, duration);
-  adw_swipeable_emit_child_switched (ADW_SWIPEABLE (self), index, duration);
 }
 
 /**
diff --git a/src/adw-flap.c b/src/adw-flap.c
index ce25878..4f0ba38 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -346,8 +346,7 @@ animate_reveal (AdwFlap *self,
 static void
 set_reveal_flap (AdwFlap  *self,
                  gboolean  reveal_flap,
-                 gint64    duration,
-                 gboolean  emit_child_switched)
+                 guint64   duration)
 {
   reveal_flap = !!reveal_flap;
 
@@ -356,13 +355,9 @@ set_reveal_flap (AdwFlap  *self,
 
   self->reveal_flap = reveal_flap;
 
-  if (!self->swipe_active) {
+  if (!self->swipe_active)
     animate_reveal (self, reveal_flap ? 1 : 0, duration);
 
-    if (emit_child_switched)
-      adw_swipeable_emit_child_switched (ADW_SWIPEABLE (self), reveal_flap ? 1 : 0, duration);
-  }
-
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL_FLAP]);
 }
 
@@ -391,7 +386,7 @@ set_folded (AdwFlap  *self,
     animate_fold (self);
 
   if (!self->locked)
-    set_reveal_flap (self, !self->folded, self->fold_duration, TRUE);
+    set_reveal_flap (self, !self->folded, self->fold_duration);
 
   context = gtk_widget_get_style_context (GTK_WIDGET (self));
   if (folded) {
@@ -458,7 +453,7 @@ end_swipe_cb (AdwSwipeTracker *tracker,
   if ((to > 0) == self->reveal_flap)
     animate_reveal (self, to, duration);
   else
-    set_reveal_flap (self, to > 0, duration, FALSE);
+    set_reveal_flap (self, to > 0, duration);
 }
 
 static void
@@ -1603,16 +1598,6 @@ adw_flap_buildable_init (GtkBuildableIface *iface)
   iface->add_child = adw_flap_add_child;
 }
 
-static void
-adw_flap_switch_child (AdwSwipeable *swipeable,
-                       guint         index,
-                       gint64        duration)
-{
-  AdwFlap *self = ADW_FLAP (swipeable);
-
-  set_reveal_flap (self, index > 0, duration, FALSE);
-}
-
 static AdwSwipeTracker *
 adw_flap_get_swipe_tracker (AdwSwipeable *swipeable)
 {
@@ -1769,7 +1754,6 @@ adw_flap_get_swipe_area (AdwSwipeable           *swipeable,
 static void
 adw_flap_swipeable_init (AdwSwipeableInterface *iface)
 {
-  iface->switch_child = adw_flap_switch_child;
   iface->get_swipe_tracker = adw_flap_get_swipe_tracker;
   iface->get_distance = adw_flap_get_distance;
   iface->get_snap_points = adw_flap_get_snap_points;
@@ -2027,7 +2011,7 @@ adw_flap_set_reveal_flap (AdwFlap  *self,
 {
   g_return_if_fail (ADW_IS_FLAP (self));
 
-  set_reveal_flap (self, reveal_flap, self->reveal_duration, TRUE);
+  set_reveal_flap (self, reveal_flap, self->reveal_duration);
 }
 
 /**
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index fa03770..b7144b9 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -720,8 +720,7 @@ static void
 set_visible_child (AdwLeaflet               *self,
                    AdwLeafletPage           *page,
                    AdwLeafletTransitionType  transition_type,
-                   guint                     transition_duration,
-                   gboolean                  emit_child_switched)
+                   guint                     transition_duration)
 {
   GtkWidget *widget = GTK_WIDGET (self);
   GtkRoot *root;
@@ -844,26 +843,6 @@ set_visible_child (AdwLeaflet               *self,
     start_child_transition (self, transition_duration, transition_direction);
   }
 
-  if (emit_child_switched) {
-    int index = 0;
-    GList *l;
-
-    for (l = self->children; l; l = l->next) {
-      AdwLeafletPage *p = l->data;
-
-      if (!p->navigatable)
-        continue;
-
-      if (p == page)
-        break;
-
-      index++;
-    }
-
-    adw_swipeable_emit_child_switched (ADW_SWIPEABLE (self), index,
-                                       transition_duration);
-  }
-
   if (self->pages) {
     if (old_pos == GTK_INVALID_LIST_POSITION && new_pos == GTK_INVALID_LIST_POSITION)
       ; /* nothing to do */
@@ -1528,9 +1507,9 @@ update_child_visible (AdwLeaflet     *self,
   enabled = gtk_widget_get_visible (page->widget);
 
   if (self->visible_child == NULL && enabled)
-    set_visible_child (self, page, self->transition_type, self->child_transition.duration, TRUE);
+    set_visible_child (self, page, self->transition_type, self->child_transition.duration);
   else if (self->visible_child == page && !enabled)
-    set_visible_child (self, NULL, self->transition_type, self->child_transition.duration, TRUE);
+    set_visible_child (self, NULL, self->transition_type, self->child_transition.duration);
 
   if (page == self->last_visible_child) {
     gtk_widget_set_child_visible (self->last_visible_child->widget, FALSE);
@@ -1604,7 +1583,7 @@ begin_swipe_cb (AdwSwipeTracker        *tracker,
     if (page) {
       self->child_transition.is_gesture_active = TRUE;
       set_visible_child (self, page, self->transition_type,
-                         self->child_transition.duration, FALSE);
+                         self->child_transition.duration);
 
       g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CHILD_TRANSITION_RUNNING]);
     }
@@ -1656,8 +1635,6 @@ add_page (AdwLeaflet     *self,
           AdwLeafletPage *page,
           AdwLeafletPage *sibling_page)
 {
-  int visible_child_pos_before_insert = -1;
-  int visible_child_pos_after_insert = -1;
   GList *l;
 
   g_return_if_fail (page->widget != NULL);
@@ -1673,9 +1650,6 @@ add_page (AdwLeaflet     *self,
     }
   }
 
-  if (self->visible_child)
-    visible_child_pos_before_insert = g_list_index (self->children, self->visible_child);
-
   g_object_ref (page);
 
   if (!sibling_page) {
@@ -1691,9 +1665,6 @@ add_page (AdwLeaflet     *self,
       g_list_insert (self->children_reversed, page, length - sibling_pos - 1);
   }
 
-  if (self->visible_child)
-    visible_child_pos_after_insert = g_list_index (self->children, self->visible_child);
-
   gtk_widget_set_child_visible (page->widget, FALSE);
 
   if (self->transition_type == ADW_LEAFLET_TRANSITION_TYPE_OVER)
@@ -1715,12 +1686,7 @@ add_page (AdwLeaflet     *self,
   if (self->visible_child == NULL &&
       gtk_widget_get_visible (page->widget))
     set_visible_child (self, page, self->transition_type,
-                       self->child_transition.duration, FALSE);
-  else if (visible_child_pos_before_insert != visible_child_pos_after_insert)
-    adw_swipeable_emit_child_switched (ADW_SWIPEABLE (self),
-                                       visible_child_pos_after_insert,
-                                       0);
-
+                       self->child_transition.duration);
   if (!self->folded ||
       (self->folded && (self->homogeneous[ADW_FOLD_FOLDED][GTK_ORIENTATION_HORIZONTAL] ||
                         self->homogeneous[ADW_FOLD_FOLDED][GTK_ORIENTATION_VERTICAL] ||
@@ -1756,7 +1722,7 @@ leaflet_remove (AdwLeaflet *self,
       if (in_dispose)
         self->visible_child = NULL;
       else
-        set_visible_child (self, NULL, self->transition_type, self->child_transition.duration, TRUE);
+        set_visible_child (self, NULL, self->transition_type, self->child_transition.duration);
     }
 
   if (self->last_visible_child == page)
@@ -2520,36 +2486,6 @@ adw_leaflet_buildable_init (GtkBuildableIface *iface)
   iface->add_child = adw_leaflet_buildable_add_child;
 }
 
-static void
-adw_leaflet_switch_child (AdwSwipeable *swipeable,
-                          guint         index,
-                          gint64        duration)
-{
-  AdwLeaflet *self = ADW_LEAFLET (swipeable);
-  AdwLeafletPage *page = NULL;
-  GList *l;
-  guint i = 0;
-
-  for (l = self->children; l; l = l->next) {
-    page = l->data;
-
-    if (!page->navigatable)
-      continue;
-
-    if (i == index)
-      break;
-
-    i++;
-  }
-
-  if (page == NULL) {
-    g_critical ("Couldn't find eligible child with index %u", index);
-    return;
-  }
-
-  set_visible_child (self, page, self->transition_type, duration, FALSE);
-}
-
 static AdwSwipeTracker *
 adw_leaflet_get_swipe_tracker (AdwSwipeable *swipeable)
 {
@@ -2708,7 +2644,6 @@ adw_leaflet_get_swipe_area (AdwSwipeable           *swipeable,
 static void
 adw_leaflet_swipeable_init (AdwSwipeableInterface *iface)
 {
-  iface->switch_child = adw_leaflet_switch_child;
   iface->get_swipe_tracker = adw_leaflet_get_swipe_tracker;
   iface->get_distance = adw_leaflet_get_distance;
   iface->get_snap_points = adw_leaflet_get_snap_points;
@@ -2858,7 +2793,7 @@ adw_leaflet_page_set_navigatable (AdwLeafletPage *self,
 
     if (self == leaflet->visible_child)
       set_visible_child (leaflet, NULL, leaflet->transition_type,
-                         leaflet->child_transition.duration, TRUE);
+                         leaflet->child_transition.duration);
   }
 
   g_object_notify_by_pspec (G_OBJECT (self), page_props[PAGE_PROP_NAVIGATABLE]);
@@ -2978,8 +2913,6 @@ adw_leaflet_reorder_child_after (AdwLeaflet *self,
   AdwLeafletPage *child_page;
   AdwLeafletPage *sibling_page;
   int sibling_page_pos;
-  int visible_child_pos_before_reorder;
-  int visible_child_pos_after_reorder;
   int previous_position;
 
   g_return_if_fail (ADW_IS_LEAFLET (self));
@@ -2992,7 +2925,6 @@ adw_leaflet_reorder_child_after (AdwLeaflet *self,
   if (child == sibling)
     return;
 
-  visible_child_pos_before_reorder = g_list_index (self->children, self->visible_child);
   previous_position = g_list_index (self->children, child) - 1;
 
   /* Cancel a gesture if there's one in progress */
@@ -3029,11 +2961,6 @@ adw_leaflet_reorder_child_after (AdwLeaflet *self,
     max = MAX (position, previous_position) + 1;
     g_list_model_items_changed (G_LIST_MODEL (self->pages), min, max - min, max - min);
   }
-
-  visible_child_pos_after_reorder = g_list_index (self->children, self->visible_child);
-
-  if (visible_child_pos_before_reorder != visible_child_pos_after_reorder)
-    adw_swipeable_emit_child_switched (ADW_SWIPEABLE (self), visible_child_pos_after_reorder, 0);
 }
 
 /**
@@ -3365,7 +3292,7 @@ adw_leaflet_set_visible_child (AdwLeaflet *self,
 
   g_return_if_fail (contains_child);
 
-  set_visible_child (self, page, self->transition_type, self->child_transition.duration, TRUE);
+  set_visible_child (self, page, self->transition_type, self->child_transition.duration);
 }
 
 /**
@@ -3415,7 +3342,7 @@ adw_leaflet_set_visible_child_name (AdwLeaflet *self,
 
   g_return_if_fail (contains_child);
 
-  set_visible_child (self, page, self->transition_type, self->child_transition.duration, TRUE);
+  set_visible_child (self, page, self->transition_type, self->child_transition.duration);
 }
 
 /**
@@ -3628,7 +3555,7 @@ adw_leaflet_navigate (AdwLeaflet             *self,
   if (!page)
     return FALSE;
 
-  set_visible_child (self, page, self->transition_type, self->child_transition.duration, TRUE);
+  set_visible_child (self, page, self->transition_type, self->child_transition.duration);
 
   return TRUE;
 }
diff --git a/src/adw-swipeable.c b/src/adw-swipeable.c
index 5ab520a..4ae0297 100644
--- a/src/adw-swipeable.c
+++ b/src/adw-swipeable.c
@@ -23,87 +23,9 @@
 
 G_DEFINE_INTERFACE (AdwSwipeable, adw_swipeable, GTK_TYPE_WIDGET)
 
-enum {
-  SIGNAL_CHILD_SWITCHED,
-  SIGNAL_LAST_SIGNAL,
-};
-
-static guint signals[SIGNAL_LAST_SIGNAL];
-
 static void
 adw_swipeable_default_init (AdwSwipeableInterface *iface)
 {
-  /**
-   * AdwSwipeable::child-switched:
-   * @self: The #AdwSwipeable instance
-   * @index: the index of the child to switch to
-   * @duration: Animation duration in milliseconds
-   *
-   * This signal should be emitted when the widget's visible child is changed.
-   *
-   * @duration can be 0 if the child is switched without animation.
-   *
-   * This is used by #AdwSwipeGroup, applications should not connect to it.
-   *
-   * Since: 1.0
-   */
-  signals[SIGNAL_CHILD_SWITCHED] =
-    g_signal_new ("child-switched",
-                  G_TYPE_FROM_INTERFACE (iface),
-                  G_SIGNAL_RUN_FIRST,
-                  0,
-                  NULL, NULL, NULL,
-                  G_TYPE_NONE,
-                  2,
-                  G_TYPE_UINT, G_TYPE_INT64);
-}
-
-/**
- * adw_swipeable_switch_child:
- * @self: a #AdwSwipeable
- * @index: the index of the child to switch to
- * @duration: Animation duration in milliseconds
- *
- * See AdwSwipeable::child-switched.
- *
- * Since: 1.0
- */
-void
-adw_swipeable_switch_child (AdwSwipeable *self,
-                            guint         index,
-                            gint64        duration)
-{
-  AdwSwipeableInterface *iface;
-
-  g_return_if_fail (ADW_IS_SWIPEABLE (self));
-
-  iface = ADW_SWIPEABLE_GET_IFACE (self);
-  g_return_if_fail (iface->switch_child != NULL);
-
-  iface->switch_child (self, index, duration);
-}
-
-/**
- * adw_swipeable_emit_child_switched:
- * @self: a #AdwSwipeable
- * @index: the index of the child to switch to
- * @duration: Animation duration in milliseconds
- *
- * Emits AdwSwipeable::child-switched signal. This should be called when the
- * widget switches visible child widget.
- *
- * @duration can be 0 if the child is switched without animation.
- *
- * Since: 1.0
- */
-void
-adw_swipeable_emit_child_switched (AdwSwipeable *self,
-                                   guint         index,
-                                   gint64        duration)
-{
-  g_return_if_fail (ADW_IS_SWIPEABLE (self));
-
-  g_signal_emit (self, signals[SIGNAL_CHILD_SWITCHED], 0, index, duration);
 }
 
 /**
diff --git a/src/adw-swipeable.h b/src/adw-swipeable.h
index 514d893..a081eaf 100644
--- a/src/adw-swipeable.h
+++ b/src/adw-swipeable.h
@@ -26,7 +26,6 @@ G_DECLARE_INTERFACE (AdwSwipeable, adw_swipeable, ADW, SWIPEABLE, GtkWidget)
 /**
  * AdwSwipeableInterface:
  * @parent: The parent interface.
- * @switch_child: Switches visible child.
  * @get_swipe_tracker: Gets the swipe tracker.
  * @get_distance: Gets the swipe distance.
  * @get_snap_points: Gets the snap points
@@ -42,10 +41,6 @@ struct _AdwSwipeableInterface
 {
   GTypeInterface parent;
 
-  void (*switch_child) (AdwSwipeable *self,
-                        guint         index,
-                        gint64        duration);
-
   AdwSwipeTracker * (*get_swipe_tracker)   (AdwSwipeable *self);
   double            (*get_distance)        (AdwSwipeable *self);
   double *          (*get_snap_points)     (AdwSwipeable *self,
@@ -61,16 +56,6 @@ struct _AdwSwipeableInterface
   gpointer padding[4];
 };
 
-ADW_AVAILABLE_IN_ALL
-void adw_swipeable_switch_child (AdwSwipeable *self,
-                                 guint         index,
-                                 gint64        duration);
-
-ADW_AVAILABLE_IN_ALL
-void adw_swipeable_emit_child_switched (AdwSwipeable *self,
-                                        guint         index,
-                                        gint64        duration);
-
 ADW_AVAILABLE_IN_ALL
 AdwSwipeTracker *adw_swipeable_get_swipe_tracker   (AdwSwipeable *self);
 ADW_AVAILABLE_IN_ALL


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