From e107e5d8be8e2347d8dbb63809ddbc470ada7d83 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Jul 09 2020 01:38:04 +0000 Subject: 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(); } }