From fc816e215d648dc6702b41d47c0b929d9adbbda5 Mon Sep 17 00:00:00 2001
From: Florian Müllner <fmuellner@gnome.org>
Date: Jul 09 2020 01:32:44 +0000
Subject: [PATCH 1/2] Adjust to changed resource scale API


https://pagure.io/background-logo-extension/issue/26

---

diff --git a/extension.js b/extension.js
index 17ef053..b557495 100644
--- a/extension.js
+++ b/extension.js
@@ -106,7 +106,7 @@ var BackgroundLogo = GObject.registerClass({
 
         this._bin = new IconContainer({ x_expand: true, y_expand: true });
         this.add_actor(this._bin);
-        this._bin.connect('notify::resource-scale',
+        this._bin.connect('resource-scale-changed',
             this._updateLogoTexture.bind(this));
 
         this._updateLogo();
@@ -152,15 +152,12 @@ var BackgroundLogo = GObject.registerClass({
             this._icon.destroy();
         this._icon = null;
 
-        let [valid, resourceScale] = this._bin.get_resource_scale();
-        if (!valid)
-            return;
-
         let key = this._settings.settings_schema.get_key('logo-size');
         let [, range] = key.get_range().deep_unpack();
         let [, max] = range.deep_unpack();
         let width = this._getWidthForRelativeSize(max);
 
+        const resourceScale = this._bin.get_resource_scale();
         let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
         this._icon = this._textureCache.load_file_async(this._logoFile, width, -1, scaleFactor, resourceScale);
         this._icon.connect('notify::content',

From e107e5d8be8e2347d8dbb63809ddbc470ada7d83 Mon Sep 17 00:00:00 2001
From: Florian Müllner <fmuellner@gnome.org>
Date: Jul 09 2020 01:38:04 +0000
Subject: [PATCH 2/2] Adjust to background changes


The actual background drawing is now delegated to a content, which
is also where the brightness and sharpness properties moved that are
animated during the overview transition. We do not have a content
with those properties, so everything is broken again :-(

For a fix, change how the extension works: Instead of adding the logo to
each backgroundGroup on monitor changes, monkey-patch BackgroundManager
to create the logo together with the backgroundActor, and use that as
parent instead of the group.

https://pagure.io/background-logo-extension/issue/26

---

diff --git a/extension.js b/extension.js
index b557495..6381857 100644
--- a/extension.js
+++ b/extension.js
@@ -46,22 +46,11 @@ class IconContainer extends St.Widget {
     }
 });
 
-var BackgroundLogo = GObject.registerClass({
-    Properties: {
-        // For compatibility with Meta.BackgroundActor
-        'brightness': GObject.ParamSpec.double(
-            'brightness', 'brightness', 'brightness',
-            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
-            0, 1, 1),
-        'vignette-sharpness': GObject.ParamSpec.double(
-            'vignette-sharpness', 'vignette-sharpness', 'vignette-sharpness',
-            GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
-            0, 1, 0),
-    },
-}, class BackgroundLogo extends St.Widget {
-    _init(bgManager) {
-        this._bgManager = bgManager;
-        this._monitorIndex = bgManager._monitorIndex;
+var BackgroundLogo = GObject.registerClass(
+class BackgroundLogo extends St.Widget {
+    _init(backgroundActor) {
+        this._backgroundActor = backgroundActor;
+        this._monitorIndex = this._backgroundActor.monitor;
 
         this._logoFile = null;
 
@@ -91,11 +80,11 @@ var BackgroundLogo = GObject.registerClass({
             layout_manager: new Clutter.BinLayout(),
             opacity: 0,
         });
-        bgManager._container.add_actor(this);
+        this._backgroundActor.add_child(this);
 
         this.connect('destroy', this._onDestroy.bind(this));
 
-        this.connect('notify::brightness',
+        this._backgroundActor.content.connect('notify::brightness',
             this._updateOpacity.bind(this));
 
         let constraint = new Layout.MonitorConstraint({
@@ -113,12 +102,6 @@ var BackgroundLogo = GObject.registerClass({
         this._updatePosition();
         this._updateBorder();
         this._updateOpacity();
-
-        this._bgDestroyedId = bgManager.backgroundActor.connect('destroy',
-            this._backgroundDestroyed.bind(this));
-
-        this._bgChangedId = bgManager.connect('changed',
-            this._updateVisibility.bind(this));
         this._updateVisibility();
     }
 
@@ -134,8 +117,10 @@ var BackgroundLogo = GObject.registerClass({
     }
 
     _updateOpacity() {
+        const brightness = this._backgroundActor.content.vignette
+            ? this._backgroundActor.content.brightness : 1.0;
         this._bin.opacity =
-            this._settings.get_uint('logo-opacity') * this.brightness;
+            this._settings.get_uint('logo-opacity') * brightness;
     }
 
     _getWorkArea() {
@@ -205,7 +190,7 @@ var BackgroundLogo = GObject.registerClass({
     }
 
     _updateVisibility() {
-        let { background } = this._bgManager.backgroundActor;
+        const { background } = this._backgroundActor.content;
         let defaultUri = background._settings.get_default_value('picture-uri');
         let file = Gio.File.new_for_commandline_arg(defaultUri.deep_unpack());
 
@@ -224,32 +209,10 @@ var BackgroundLogo = GObject.registerClass({
         });
     }
 
-    _backgroundDestroyed() {
-        this._bgDestroyedId = 0;
-
-        if (this._bgManager._backgroundSource) { // background swapped
-            this._bgDestroyedId =
-                this._bgManager.backgroundActor.connect('destroy',
-                    this._backgroundDestroyed.bind(this));
-        } else { // bgManager destroyed
-            this.destroy();
-        }
-    }
-
     _onDestroy() {
         this._settings.run_dispose();
         this._settings = null;
 
-        if (this._bgDestroyedId)
-            this._bgManager.backgroundActor.disconnect(this._bgDestroyedId);
-        this._bgDestroyedId = 0;
-
-        if (this._bgChangedId)
-            this._bgManager.disconnect(this._bgChangedId);
-        this._bgChangedId = 0;
-
-        this._bgManager = null;
-
         this._logoFile = null;
     }
 });
@@ -257,49 +220,29 @@ var BackgroundLogo = GObject.registerClass({
 
 class Extension {
     constructor() {
-        this._monitorsChangedId = 0;
-        this._startupPreparedId = 0;
-        this._logos = new Set();
+        this._bgManagerProto = Background.BackgroundManager.prototype;
+        this._createBackgroundOrig = this._bgManagerProto._createBackgroundActor;
     }
 
-    _forEachBackgroundManager(func) {
-        Main.overview._bgManagers.forEach(func);
-        Main.layoutManager._bgManagers.forEach(func);
-    }
-
-    _addLogo() {
-        this._destroyLogo();
-        this._forEachBackgroundManager(bgManager => {
-            let logo = new BackgroundLogo(bgManager);
-            logo.connect('destroy', () => {
-                this._logos.delete(logo);
-            });
-            this._logos.add(logo);
-        });
-    }
-
-    _destroyLogo() {
-        this._logos.forEach(l => l.destroy());
+    _reloadBackgrounds() {
+        Main.layoutManager._updateBackgrounds();
+        Main.overview._updateBackgrounds();
     }
 
     enable() {
-        this._monitorsChangedId =
-            Main.layoutManager.connect('monitors-changed', this._addLogo.bind(this));
-        this._startupPreparedId =
-            Main.layoutManager.connect('startup-prepared', this._addLogo.bind(this));
-        this._addLogo();
+        const { _createBackgroundOrig } = this;
+        this._bgManagerProto._createBackgroundActor = function () {
+            const backgroundActor = _createBackgroundOrig.call(this);
+            const logo_ = new BackgroundLogo(backgroundActor);
+
+            return backgroundActor;
+        };
+        this._reloadBackgrounds();
     }
 
     disable() {
-        if (this._monitorsChangedId)
-            Main.layoutManager.disconnect(this._monitorsChangedId);
-        this._monitorsChangedId = 0;
-
-        if (this._startupPreparedId)
-            Main.layoutManager.disconnect(this._startupPreparedId);
-        this._startupPreparedId = 0;
-
-        this._destroyLogo();
+        this._bgManagerProto._createBackgroundActor = this._createBackgroundOrig;
+        this._reloadBackgrounds();
     }
 }
 

