6f08de
From 49d066234f9f528122bb40c5144b40d8b19a0071 Mon Sep 17 00:00:00 2001
6f08de
From: rpm-build <rpm-build>
6f08de
Date: Mon, 22 Aug 2022 12:52:19 +0200
6f08de
Subject: [PATCH] Background: Avoid double dispose and actors recreations
6f08de
6f08de
Subject: [PATCH 1/2] background: Use Garbage Collector to dispose background:
6f08de
6f08de
The same Meta.Background could be used by multiple instances of background
6f08de
actors, and so should not be disposed when the actor using it is destroyed.
6f08de
6f08de
Instead of calling `run_dispose` directly on it, just nullify the reference
6f08de
on destroy method, leaving the job of doing the proper disposition to the
6f08de
gabage collector that keeps the proper reference count on the Meta.Background.
6f08de
6f08de
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/501
6f08de
6f08de
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/558
6f08de
6f08de
Subject: [PATCH 2/2] background: Group 'changed' signal emission
6f08de
6f08de
Background is monitoring the whole `org.gnome.desktop.background` gsettings keys
6f08de
for changes connecting to the non-specialized 'changed' signal and re-emitting
6f08de
this as-is.
6f08de
This means that when the background is changed via control-center, we get
6f08de
multiple 'changed' signal events from GSettings, and for each one of this we
6f08de
recreate a Background and a BackgroundActor.
6f08de
6f08de
Avoid this by using an idle to delay the emission of the 'changed' signal
6f08de
grouping the events.
6f08de
6f08de
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/558
6f08de
---
6f08de
 js/ui/background.js | 26 +++++++++++++++++++++-----
6f08de
 1 file changed, 21 insertions(+), 5 deletions(-)
6f08de
6f08de
diff --git a/js/ui/background.js b/js/ui/background.js
6f08de
index 06e0388..2a404ae 100644
6f08de
--- a/js/ui/background.js
6f08de
+++ b/js/ui/background.js
6f08de
@@ -257,14 +257,15 @@ var Background = class Background {
6f08de
                 this._refreshAnimation();
6f08de
             });
6f08de
 
6f08de
-        this._settingsChangedSignalId = this._settings.connect('changed', () => {
6f08de
-            this.emit('changed');
6f08de
-        });
6f08de
+        this._settingsChangedSignalId =
6f08de
+            this._settings.connect('changed', this._emitChangedSignal.bind(this));
6f08de
 
6f08de
         this._load();
6f08de
     }
6f08de
 
6f08de
     destroy() {
6f08de
+        this.background = null;
6f08de
+
6f08de
         this._cancellable.cancel();
6f08de
         this._removeAnimationTimeout();
6f08de
 
6f08de
@@ -288,6 +289,22 @@ var Background = class Background {
6f08de
         if (this._settingsChangedSignalId != 0)
6f08de
             this._settings.disconnect(this._settingsChangedSignalId);
6f08de
         this._settingsChangedSignalId = 0;
6f08de
+
6f08de
+        if (this._changedIdleId) {
6f08de
+            GLib.source_remove(this._changedIdleId);
6f08de
+            this._changedIdleId = 0;
6f08de
+        }
6f08de
+    }
6f08de
+
6f08de
+    _emitChangedSignal() {
6f08de
+        if (this._changedIdleId)
6f08de
+            return;
6f08de
+
6f08de
+        this._changedIdleId = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
6f08de
+            this._changedIdleId = 0;
6f08de
+            this.emit('changed');
6f08de
+            return GLib.SOURCE_REMOVE;
6f08de
+        });
6f08de
     }
6f08de
 
6f08de
     updateResolution() {
6f08de
@@ -343,7 +360,7 @@ var Background = class Background {
6f08de
                                                if (changedFile.equal(file)) {
6f08de
                                                    let imageCache = Meta.BackgroundImageCache.get_default();
6f08de
                                                    imageCache.purge(changedFile);
6f08de
-                                                   this.emit('changed');
6f08de
+                                                   this._emitChangedSignal();
6f08de
                                                }
6f08de
                                            });
6f08de
         this._fileWatches[key] = signalId;
6f08de
@@ -699,7 +716,6 @@ var BackgroundManager = class BackgroundManager {
6f08de
                            time: FADE_ANIMATION_TIME,
6f08de
                            transition: 'easeOutQuad',
6f08de
                            onComplete() {
6f08de
-                               oldBackgroundActor.background.run_dispose();
6f08de
                                oldBackgroundActor.destroy();
6f08de
                            }
6f08de
                          });
6f08de
-- 
6f08de
2.35.3
6f08de