[gnome-shell] Move Tweener.slowDownFactor into St



commit 35764fa09e4341e79732409c4e74c226d19f780f
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Jun 20 04:16:06 2010 +0200

    Move Tweener.slowDownFactor into St
    
    It has probably crossed the line to evil by a mile or so, but here
    it is: a Tweener.slowDownFactor replacement used by all animations
    without exception.
    While at it, update Tweener to use the new setTimeScale() upstream
    function instead of adjusting the timeline directly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622249

 js/ui/environment.js   |    8 ++++++++
 js/ui/tweener.js       |   18 ++++--------------
 src/st/st-scroll-bar.c |    6 ++++--
 src/st/st-theme-node.c |    6 ++++--
 src/st/st-tooltip.c    |    4 +++-
 src/st/st-widget.c     |   26 ++++++++++++++++++++++++++
 src/st/st-widget.h     |    6 ++++--
 7 files changed, 53 insertions(+), 21 deletions(-)
---
diff --git a/js/ui/environment.js b/js/ui/environment.js
index 98caa55..03ddccf 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -1,6 +1,7 @@
 /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
 
 const Clutter = imports.gi.Clutter;;
+const GLib = imports.gi.GLib;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
 const Gettext_gtk20 = imports.gettext.domain('gtk20');
@@ -68,6 +69,13 @@ function init() {
         St.Widget.set_default_direction(St.TextDirection.RTL);
     }
 
+    let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
+    if (slowdownEnv) {
+        let factor = parseFloat(slowdownEnv);
+        if (!isNaN(factor) && factor > 0.0)
+            St.set_slow_down_factor(factor);
+    }
+
     _patchContainerClass(St.BoxLayout);
     _patchContainerClass(St.Table);
 
diff --git a/js/ui/tweener.js b/js/ui/tweener.js
index f2e3b53..685f4b3 100644
--- a/js/ui/tweener.js
+++ b/js/ui/tweener.js
@@ -1,10 +1,10 @@
 /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
 
 const Clutter = imports.gi.Clutter;
-const GLib = imports.gi.GLib;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Shell = imports.gi.Shell;
+const St = imports.gi.St;
 const Signals = imports.signals;
 const Tweener = imports.tweener.tweener;
 
@@ -43,17 +43,8 @@ const Tweener = imports.tweener.tweener;
 // calls any of these is almost certainly wrong anyway, because they
 // affect the entire application.)
 
-let slowDownFactor = 1.0;
-
 // Called from Main.start
 function init() {
-    let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
-    if (slowdownEnv) {
-        let factor = parseFloat(slowdownEnv);
-        if (!isNaN(factor) && factor > 0.0)
-            slowDownFactor = factor;
-    }
-
     Tweener.setFrameTicker(new ClutterFrameTicker());
 }
 
@@ -216,7 +207,6 @@ ClutterFrameTicker.prototype = {
         // when we need to stop, so use 1000 seconds as "infinity"
         this._timeline = new Clutter.Timeline({ duration: 1000*1000 });
         this._startTime = -1;
-        this._currentTime = -1;
 
         this._timeline.connect('new-frame', Lang.bind(this,
             function(timeline, frame) {
@@ -243,17 +233,18 @@ ClutterFrameTicker.prototype = {
 
         // currentTime is in milliseconds
         let perf_log = Shell.PerfLog.get_default();
-        this._currentTime = (this._timeline.get_elapsed_time() - this._startTime) / slowDownFactor;
         perf_log.event("tweener.framePrepareStart");
         this.emit('prepare-frame');
         perf_log.event("tweener.framePrepareDone");
     },
 
     getTime : function() {
-        return this._currentTime;
+        return this._timeline.get_elapsed_time();
     },
 
     start : function() {
+        if (St.get_slow_down_factor() > 0)
+            Tweener.setTimeScale(1 / St.get_slow_down_factor());
         this._timeline.start();
         global.begin_work();
     },
@@ -261,7 +252,6 @@ ClutterFrameTicker.prototype = {
     stop : function() {
         this._timeline.stop();
         this._startTime = -1;
-        this._currentTime = -1;
         global.end_work();
     }
 };
diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c
index 5264320..7bf7803 100644
--- a/src/st/st-scroll-bar.c
+++ b/src/st/st-scroll-bar.c
@@ -106,6 +106,8 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0, };
 
+extern gfloat st_slow_down_factor;
+
 static gboolean
 handle_button_press_event_cb (ClutterActor       *actor,
                               ClutterButtonEvent *event,
@@ -875,7 +877,7 @@ trough_paging_cb (StScrollBar *self)
   * idea, but it's a lot less involved than extenind the current animation */
   a = self->priv->paging_animation = g_object_new (CLUTTER_TYPE_ANIMATION,
                                                    "object", self->priv->adjustment,
-                                                   "duration", PAGING_SUBSEQUENT_REPEAT_TIMEOUT,
+                                                   "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * st_slow_down_factor),
                                                    "mode", mode,
                                                    NULL);
   g_value_init (&v, G_TYPE_DOUBLE);
@@ -961,7 +963,7 @@ stepper_move_on (StScrollBarPrivate *priv,
 
   a = g_object_new (CLUTTER_TYPE_ANIMATION,
                     "object", priv->adjustment,
-                    "duration", PAGING_SUBSEQUENT_REPEAT_TIMEOUT,
+                    "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * st_slow_down_factor),
                     "mode", mode,
                     NULL);
 
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 639c566..08a9357 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -15,6 +15,8 @@ static void st_theme_node_finalize           (GObject                 *object);
 static const ClutterColor BLACK_COLOR = { 0, 0, 0, 0xff };
 static const ClutterColor TRANSPARENT_COLOR = { 0, 0, 0, 0 };
 
+extern gfloat st_slow_down_factor;
+
 G_DEFINE_TYPE (StThemeNode, st_theme_node, G_TYPE_OBJECT)
 
 static void
@@ -1683,13 +1685,13 @@ st_theme_node_get_transition_duration (StThemeNode *node)
   g_return_val_if_fail (ST_IS_THEME_NODE (node), 0);
 
   if (node->transition_duration > -1)
-    return node->transition_duration;
+    return st_slow_down_factor * node->transition_duration;
 
   st_theme_node_get_double (node, "transition-duration", FALSE, &value);
 
   node->transition_duration = (int)value;
 
-  return node->transition_duration;
+  return st_slow_down_factor * node->transition_duration;
 }
 
 StTextDecoration
diff --git a/src/st/st-tooltip.c b/src/st/st-tooltip.c
index 5195270..c458fb5 100644
--- a/src/st/st-tooltip.c
+++ b/src/st/st-tooltip.c
@@ -68,6 +68,8 @@ struct _StTooltipPrivate
   ClutterGeometry *tip_area;
 };
 
+extern gfloat st_slow_down_factor;
+
 G_DEFINE_TYPE (StTooltip, st_tooltip, ST_TYPE_WIDGET);
 
 static void
@@ -540,7 +542,7 @@ st_tooltip_hide (StTooltip *tooltip)
                 NULL);
   animation =
     clutter_actor_animate (CLUTTER_ACTOR (tooltip), CLUTTER_EASE_IN_SINE,
-                           150,
+                           (guint)(150 * st_slow_down_factor),
                            "scale-x", 0.0,
                            "scale-y", 0.0,
                            NULL);
diff --git a/src/st/st-widget.c b/src/st/st-widget.c
index 18fb55c..eb976ac 100644
--- a/src/st/st-widget.c
+++ b/src/st/st-widget.c
@@ -105,6 +105,8 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0, };
 
+gfloat st_slow_down_factor = 1.0;
+
 G_DEFINE_ABSTRACT_TYPE (StWidget, st_widget, CLUTTER_TYPE_ACTOR);
 
 #define ST_WIDGET_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ST_TYPE_WIDGET, StWidgetPrivate))
@@ -1704,3 +1706,27 @@ st_describe_actor (ClutterActor *actor)
 
   return g_string_free (desc, FALSE);
 }
+
+/**
+ * st_set_slow_down_factor:
+ *
+ * @factor: new slow-down factor
+ *
+ * Set a global factor applied to all animation durations
+ */
+void
+st_set_slow_down_factor (gfloat factor)
+{
+  st_slow_down_factor = factor;
+}
+
+/**
+ * st_get_slow_down_factor:
+ *
+ * Returns: the global factor applied to all animation durations
+ */
+gfloat
+st_get_slow_down_factor ()
+{
+  return st_slow_down_factor;
+}
diff --git a/src/st/st-widget.h b/src/st/st-widget.h
index 620c55b..2a65f8f 100644
--- a/src/st/st-widget.h
+++ b/src/st/st-widget.h
@@ -141,8 +141,10 @@ void                  st_widget_set_direction             (StWidget        *self
 void                  st_widget_style_changed             (StWidget        *widget);
 StThemeNode *         st_widget_get_theme_node            (StWidget        *widget);
 
-/* debug method */
-char *st_describe_actor (ClutterActor *actor);
+/* debug methods */
+char  *st_describe_actor       (ClutterActor *actor);
+void   st_set_slow_down_factor (gfloat factor);
+gfloat st_get_slow_down_factor (void);
 
 G_END_DECLS
 



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