[gnome-shell/wip/bg-fixes: 3/6] background: properly disconnect background signals



commit 2e6c160822d2c67555525342cae73fdd4ec72f71
Author: Ray Strode <rstrode redhat com>
Date:   Tue Mar 19 15:26:05 2013 -0400

    background: properly disconnect background signals
    
    BackgroundManager connects to the changed signal in
    the backgrounds it manages.
    
    The signal ids for the changed signal connectionss are stored
    as state on the background manager object.
    
    If the background being managed changes while the manager
    is still loading the old background, then the signal id
    variable can get out of sync with the background object being
    managed.
    
    This commit ties the signal id to the background objects themselves,
    so there is no opportunity for them to desynchronize.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696157

 js/ui/background.js |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/js/ui/background.js b/js/ui/background.js
index e95cbc0..cacdffb 100644
--- a/js/ui/background.js
+++ b/js/ui/background.js
@@ -654,17 +654,9 @@ const BackgroundManager = new Lang.Class({
 
         this.background = this._createBackground();
         this._newBackground = null;
-        this._loadedSignalId = 0;
-        this._changedSignalId = 0;
     },
 
     destroy: function() {
-        if (this._loadedSignalId)
-            this._newBackground.disconnect(this._loadedSignalId);
-
-        if (this._changedSignalId)
-            this.background.disconnect(this._changedSignalId);
-
         if (this._newBackground) {
             this._newBackground.actor.destroy();
             this._newBackground = null;
@@ -683,22 +675,24 @@ const BackgroundManager = new Lang.Class({
         newBackground.saturation = background.saturation;
         newBackground.visible = background.visible;
 
-        let signalId = newBackground.connect('loaded',
+        newBackground.loadedSignalId = newBackground.connect('loaded',
             Lang.bind(this, function() {
-                newBackground.disconnect(signalId);
+                newBackground.disconnect(newBackground.loadedSignalId);
+                newBackground.loadedSignalId = 0;
                 Tweener.addTween(background.actor,
                                  { opacity: 0,
                                    time: FADE_ANIMATION_TIME,
                                    transition: 'easeOutQuad',
                                    onComplete: Lang.bind(this, function() {
-                                       this.background = newBackground;
-                                       this._newBackground = null;
-                                       background.actor.destroy();
+                                       if (this.background == background) {
+                                           this.background = newBackground;
+                                           this._newBackground = null;
+                                           background.actor.destroy();
+                                       }
                                        this.emit('changed');
                                    })
                                  });
         }));
-        this._loadedSignalId = signalId;
 
         this._newBackground = newBackground;
     },
@@ -717,12 +711,19 @@ const BackgroundManager = new Lang.Class({
             background.actor.lower_bottom();
         }
 
-        let signalId = background.connect('changed', Lang.bind(this, function() {
-            background.disconnect(signalId);
+        background.changeSignalId = background.connect('changed', Lang.bind(this, function() {
+            background.disconnect(background.changeSignalId);
+            background.changeSignalId = 0;
             this._updateBackground(background, this._monitorIndex);
         }));
 
-        this._changedSignalId = signalId;
+        background.actor.connect('destroy', Lang.bind(this, function() {
+            if (background.changeSignalId)
+                background.disconnect(background.changeSignalId);
+
+            if (background.loadedSignalId)
+                background.disconnect(background.loadedSignalId);
+        }));
 
         return background;
     },


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