[gnome-shell] st: Stop using (deprecated) ClutterAnimation



commit 3c5fea59df8befb991a66f46f0acb214294ea484
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Sep 26 05:20:04 2015 +0200

    st: Stop using (deprecated) ClutterAnimation
    
    Instead, make StAdjustment a ClutterAnimatable and use a property
    transition.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/572

 src/st/st-adjustment.c | 12 +++++++++++-
 src/st/st-scroll-bar.c | 44 ++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 25 deletions(-)
---
diff --git a/src/st/st-adjustment.c b/src/st/st-adjustment.c
index 598df4ee3..5fb68f732 100644
--- a/src/st/st-adjustment.c
+++ b/src/st/st-adjustment.c
@@ -53,7 +53,12 @@ struct _StAdjustmentPrivate
   gdouble  page_size;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (StAdjustment, st_adjustment, G_TYPE_OBJECT)
+static void animatable_iface_init (ClutterAnimatableInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (StAdjustment, st_adjustment, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (StAdjustment)
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE,
+                                                animatable_iface_init));
 
 enum
 {
@@ -87,6 +92,11 @@ static gboolean st_adjustment_set_page_increment (StAdjustment *adjustment,
 static gboolean st_adjustment_set_page_size      (StAdjustment *adjustment,
                                                   gdouble       size);
 
+static void
+animatable_iface_init (ClutterAnimatableInterface *iface)
+{
+}
+
 static void
 st_adjustment_constructed (GObject *object)
 {
diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c
index 561bb4b7d..64d687bd7 100644
--- a/src/st/st-scroll-bar.c
+++ b/src/st/st-scroll-bar.c
@@ -64,7 +64,7 @@ struct _StScrollBarPrivate
   guint             paging_source_id;
   guint             paging_event_no;
 
-  ClutterAnimation *paging_animation;
+  ClutterTransition *paging_animation;
 
   guint             vertical : 1;
 };
@@ -669,11 +669,11 @@ handle_button_press_event_cb (ClutterActor       *actor,
 }
 
 static void
-animation_completed_cb (ClutterAnimation   *animation,
+animation_completed_cb (ClutterTransition *animation,
+                        gboolean           is_finished,
                         StScrollBarPrivate *priv)
 {
-  g_object_unref (priv->paging_animation);
-  priv->paging_animation = NULL;
+  g_clear_object (&priv->paging_animation);
 }
 
 static gboolean
@@ -681,14 +681,11 @@ trough_paging_cb (StScrollBar *self)
 {
   StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
   gfloat handle_pos, event_pos, tx, ty;
-  gdouble value;
+  gdouble value, new_value;
   gdouble page_increment;
   gboolean ret;
 
   gulong mode;
-  ClutterAnimation *a;
-  GValue v = { 0, };
-  ClutterTimeline *t;
 
   if (priv->paging_event_no == 0)
     {
@@ -754,7 +751,7 @@ trough_paging_cb (StScrollBar *self)
           /* Scrolled far enough. */
           return FALSE;
         }
-      value += page_increment;
+      new_value = value + page_increment;
     }
   else
     {
@@ -768,27 +765,26 @@ trough_paging_cb (StScrollBar *self)
           /* Scrolled far enough. */
           return FALSE;
         }
-      value -= page_increment;
+      new_value = value - page_increment;
     }
 
   if (priv->paging_animation)
     {
-      clutter_animation_completed (priv->paging_animation);
+      clutter_timeline_stop (CLUTTER_TIMELINE (priv->paging_animation));
     }
 
-  /* FIXME: Creating a new animation for each scroll is probably not the best
-  * idea, but it's a lot less involved than extenind the current animation */
-  a = priv->paging_animation = g_object_new (CLUTTER_TYPE_ANIMATION,
-                                                   "object", priv->adjustment,
-                                                   "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * 
st_slow_down_factor),
-                                                   "mode", mode,
-                                                   NULL);
-  g_value_init (&v, G_TYPE_DOUBLE);
-  g_value_set_double (&v, value);
-  clutter_animation_bind (priv->paging_animation, "value", &v);
-  t = clutter_animation_get_timeline (priv->paging_animation);
-  g_signal_connect (a, "completed", G_CALLBACK (animation_completed_cb), priv);
-  clutter_timeline_start (t);
+  /* FIXME: Creating a new transition for each scroll is probably not the best
+  * idea, but it's a lot less involved than extending the current animation */
+  priv->paging_animation = g_object_new (CLUTTER_TYPE_PROPERTY_TRANSITION,
+                                         "animatable", priv->adjustment,
+                                         "property-name", "value",
+                                        "interval", clutter_interval_new (G_TYPE_DOUBLE, value, new_value),
+                                         "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * 
st_slow_down_factor),
+                                         "progress-mode", mode,
+                                         NULL);
+  g_signal_connect (priv->paging_animation, "stopped",
+                    G_CALLBACK (animation_completed_cb), priv);
+  clutter_timeline_start (CLUTTER_TIMELINE (priv->paging_animation));
 
   return ret;
 }


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