diff --git a/src/Background/Background.vala b/src/Background/Background.vala index c58d131bd..627706446 100644 --- a/src/Background/Background.vala +++ b/src/Background/Background.vala @@ -20,8 +20,9 @@ namespace Gala { private const double ANIMATION_OPACITY_STEP_INCREMENT = 4.0; private const double ANIMATION_MIN_WAKEUP_INTERVAL = 1.0; - public signal void changed (); public signal void loaded (); + public signal void invalidate (); + public signal void changed (); public Meta.Display display { get; construct; } public int monitor_index { get; construct; } @@ -35,6 +36,8 @@ namespace Gala { private Gee.HashMap file_watches; private Cancellable cancellable; private uint update_animation_timeout_id = 0; + private string? previous_animation_file = null; + private double previous_animation_progress = 0.0; private Gnome.WallClock clock; private ulong clock_timezone_handler = 0; @@ -133,7 +136,7 @@ namespace Gala { if (changed_file == filename) { var image_cache = Meta.BackgroundImageCache.get_default (); image_cache.purge (File.new_for_path (changed_file)); - changed (); + invalidate (); } }); } @@ -148,12 +151,33 @@ namespace Gala { private void finish_animation (string[] files) { set_loaded (); - if (files.length > 1) + string? new_last_animation_file = null; + + if (files.length > 1) { background.set_blend (File.new_for_path (files[0]), File.new_for_path (files[1]), animation.transition_progress, style); - else if (files.length > 0) + new_last_animation_file = files[1]; + } else if (files.length == 1) { background.set_file (File.new_for_path (files[0]), style); - else + new_last_animation_file = files[0]; + } else { background.set_file (null, style); + new_last_animation_file = null; + } + + if (previous_animation_file != new_last_animation_file) { + previous_animation_file = new_last_animation_file; + previous_animation_progress = 0.0; + } + + if ( + animation.transition_progress >= 0.25 && previous_animation_progress < 0.25 || + animation.transition_progress >= 0.5 && previous_animation_progress < 0.5 || + animation.transition_progress >= 0.75 && previous_animation_progress < 0.75 + ) { + changed (); + } + + previous_animation_progress = animation.transition_progress; queue_update_animation (); } @@ -206,10 +230,9 @@ namespace Gala { if (interval > uint32.MAX) return; - update_animation_timeout_id = Timeout.add (interval, () => { + update_animation_timeout_id = Timeout.add_once (interval, () => { update_animation_timeout_id = 0; update_animation (); - return Source.REMOVE; }); } @@ -259,7 +282,7 @@ namespace Gala { } private void settings_changed () { - changed (); + invalidate (); } } } diff --git a/src/Background/BackgroundManager.vala b/src/Background/BackgroundManager.vala index f51f82601..1a682ff73 100644 --- a/src/Background/BackgroundManager.vala +++ b/src/Background/BackgroundManager.vala @@ -124,6 +124,8 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag unowned var display = wm.get_display (); var background = background_source.get_background (monitor_index); + background.changed.connect (() => changed ()); + var background_actor = new Meta.BackgroundActor (display, monitor_index); unowned var content = (Meta.BackgroundContent) background_actor.content; @@ -145,7 +147,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag } ulong changed_handler = 0; - changed_handler = background.changed.connect (() => { + changed_handler = background.invalidate.connect (() => { background.disconnect (changed_handler); changed_handler = 0; update_background_actor (); diff --git a/src/Background/BackgroundSource.vala b/src/Background/BackgroundSource.vala index 095340567..1ec0b5801 100644 --- a/src/Background/BackgroundSource.vala +++ b/src/Background/BackgroundSource.vala @@ -96,7 +96,7 @@ namespace Gala { background.update_resolution (); return false; } else { - background.changed.disconnect (background_changed); + background.invalidate.disconnect (background_invalidated); background.destroy (); return true; } @@ -121,7 +121,7 @@ namespace Gala { var background = backgrounds.lookup (monitor_index); if (background == null) { background = new Background (display, monitor_index, filename, this, (GDesktop.BackgroundStyle) style); - background.changed.connect (background_changed); + background.invalidate.connect (background_invalidated); backgrounds.insert (monitor_index, background); } @@ -146,8 +146,8 @@ namespace Gala { return uri; } - private void background_changed (Background background) { - background.changed.disconnect (background_changed); + private void background_invalidated (Background background) { + background.invalidate.disconnect (background_invalidated); background.destroy (); backgrounds.remove (background.monitor_index); } @@ -157,7 +157,7 @@ namespace Gala { monitor_manager = null; backgrounds.foreach_remove ((hash, background) => { - background.changed.disconnect (background_changed); + background.invalidate.disconnect (background_invalidated); background.destroy (); return true; });