#27 Adjust to 3.37 changes
Merged 3 years ago by fmuellner. Opened 3 years ago by fmuellner.
fmuellner/background-logo-extension 3-37-adjustments  into  master

Adjust to background changes
Florian Müllner • 3 years ago  
Adjust to changed resource scale API
Florian Müllner • 3 years ago  
file modified
+28 -88
@@ -46,22 +46,11 @@ 

      }

  });

  

- 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 @@ 

              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({
@@ -106,19 +95,13 @@ 

  

          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();

          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 @@ 

      }

  

      _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() {
@@ -152,15 +137,12 @@ 

              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',
@@ -208,7 +190,7 @@ 

      }

  

      _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());

  
@@ -227,32 +209,10 @@ 

          });

      }

  

-     _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;

      }

  });
@@ -260,49 +220,29 @@ 

  

  class Extension {

      constructor() {

-         this._monitorsChangedId = 0;

-         this._startupPreparedId = 0;

-         this._logos = new Set();

-     }

- 

-     _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);

-         });

+         this._bgManagerProto = Background.BackgroundManager.prototype;

+         this._createBackgroundOrig = this._bgManagerProto._createBackgroundActor;

      }

  

-     _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();

      }

  }

  

There was a minor change to the resource scale API, and a major change to backgrounds (which unsurprisingly broke us badly).

This should get us back on track, hopefully.

Fixes #26

2 new commits added

  • Adjust to background changes
  • Adjust to changed resource scale API
3 years ago

I'll try and test this on Monday. I can't really review it, my javascript isn't good enough :P

This has been reported to fix the 3.37.3 issues, so landing.

Pull-Request has been merged by fmuellner

3 years ago
Metadata