[mutter/gnome-40] plugins/default: Add env var to disable animations



commit 16b2b5b31029c60234188bdec62e6f882bc444ed
Author: Jonas Ådahl <jadahl gmail com>
Date:   Tue Sep 28 10:53:55 2021 +0200

    plugins/default: Add env var to disable animations
    
    Intended to be used by tests, as animations may interfere with testing.
    Eventually, a dedicated test plugin should be added, but it is out of
    scope for this branch.

 src/compositor/plugins/default.c | 78 +++++++++++++++++++++++++++++++---------
 1 file changed, 62 insertions(+), 16 deletions(-)
---
diff --git a/src/compositor/plugins/default.c b/src/compositor/plugins/default.c
index c89c84121f..2af9b15f11 100644
--- a/src/compositor/plugins/default.c
+++ b/src/compositor/plugins/default.c
@@ -37,10 +37,20 @@
 #include "meta/util.h"
 #include "meta/window.h"
 
-#define DESTROY_TIMEOUT   100
-#define MINIMIZE_TIMEOUT  250
-#define MAP_TIMEOUT       250
-#define SWITCH_TIMEOUT    500
+typedef enum
+{
+  ANIMATION_DESTROY,
+  ANIMATION_MINIMIZE,
+  ANIMATION_MAP,
+  ANIMATION_SWITCH,
+} Animation;
+
+static unsigned int animation_durations[] = {
+  100, /* destroy */
+  250, /* minimize */
+  250, /* map */
+  500, /* switch */
+};
 
 #define ACTOR_DATA_KEY "MCCP-Default-actor-data"
 #define DISPLAY_TILE_PREVIEW_DATA_KEY "MCCP-Default-display-tile-preview-data"
@@ -256,10 +266,38 @@ get_actor_private (MetaWindowActor *actor)
   return priv;
 }
 
+static gboolean
+is_animations_disabled (void)
+{
+  static gboolean is_animations_disabled_set;
+  static gboolean is_animations_disabled;
+
+  if (!is_animations_disabled_set)
+    {
+      if (g_strcmp0 (getenv ("MUTTER_DEBUG_DISABLE_ANIMATIONS"), "1") == 0)
+        is_animations_disabled = TRUE;
+      else
+        is_animations_disabled = FALSE;
+
+      is_animations_disabled_set = TRUE;
+    }
+
+  return is_animations_disabled;
+}
+
+static unsigned int
+get_animation_duration (Animation animation)
+{
+  if (is_animations_disabled ())
+    return 0;
+
+  return animation_durations[animation];
+}
+
 static ClutterTimeline *
 actor_animate (ClutterActor         *actor,
                ClutterAnimationMode  mode,
-               guint                 duration,
+               Animation             animation,
                const gchar          *first_property,
                ...)
 {
@@ -268,7 +306,7 @@ actor_animate (ClutterActor         *actor,
 
   clutter_actor_save_easing_state (actor);
   clutter_actor_set_easing_mode (actor, mode);
-  clutter_actor_set_easing_duration (actor, duration);
+  clutter_actor_set_easing_duration (actor, get_animation_duration (animation));
 
   va_start (args, first_property);
   g_object_set_valist (G_OBJECT (actor), first_property, args);
@@ -538,7 +576,7 @@ switch_workspace (MetaPlugin *plugin,
   priv->desktop2 = workspace1;
 
   priv->tml_switch_workspace1 = actor_animate (workspace0, CLUTTER_EASE_IN_SINE,
-                                               SWITCH_TIMEOUT,
+                                               ANIMATION_SWITCH,
                                                "scale-x", 1.0,
                                                "scale-y", 1.0,
                                                NULL);
@@ -548,7 +586,7 @@ switch_workspace (MetaPlugin *plugin,
                     plugin);
 
   priv->tml_switch_workspace2 = actor_animate (workspace1, CLUTTER_EASE_IN_SINE,
-                                               SWITCH_TIMEOUT,
+                                               ANIMATION_SWITCH,
                                                "scale-x", 0.0,
                                                "scale-y", 0.0,
                                                NULL);
@@ -611,7 +649,7 @@ minimize (MetaPlugin *plugin, MetaWindowActor *window_actor)
     {
       timeline = actor_animate (actor,
                                 CLUTTER_EASE_IN_SINE,
-                                MINIMIZE_TIMEOUT,
+                                ANIMATION_MINIMIZE,
                                 "scale-x", 0.0,
                                 "scale-y", 0.0,
                                 "x", (double)icon_geometry.x,
@@ -678,16 +716,24 @@ map (MetaPlugin *plugin, MetaWindowActor *window_actor)
 
       apriv->tml_map = actor_animate (actor,
                                       CLUTTER_EASE_OUT_QUAD,
-                                      MAP_TIMEOUT,
+                                      ANIMATION_MAP,
                                       "opacity", 255,
                                       "scale-x", 1.0,
                                       "scale-y", 1.0,
                                       NULL);
-      data->actor = actor;
-      data->plugin = plugin;
-      g_signal_connect (apriv->tml_map, "completed",
-                        G_CALLBACK (on_map_effect_complete),
-                        data);
+      if (apriv->tml_map)
+        {
+          data->actor = actor;
+          data->plugin = plugin;
+          g_signal_connect (apriv->tml_map, "completed",
+                            G_CALLBACK (on_map_effect_complete),
+                            data);
+        }
+      else
+        {
+          g_free (data);
+          meta_plugin_map_completed (plugin, window_actor);
+        }
     }
   else
     meta_plugin_map_completed (plugin, window_actor);
@@ -726,7 +772,7 @@ destroy (MetaPlugin *plugin, MetaWindowActor *window_actor)
     {
       timeline = actor_animate (actor,
                                 CLUTTER_EASE_OUT_QUAD,
-                                DESTROY_TIMEOUT,
+                                ANIMATION_DESTROY,
                                 "opacity", 0,
                                 "scale-x", 0.8,
                                 "scale-y", 0.8,


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