From 7923ab665e3c3ef688e504eac1fa5327b463240b Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 30 2017 16:54:07 +0000 Subject: [PATCH 1/2] Keep track of logo file This is mostly done in preparation of updating the logo on file content changes, though it allows us a minor optimization when the 'logo-file' setting doesn't actually change (either a stray signal or a symlink to the current logo). https://pagure.io/background-logo-extension/issue/2 --- diff --git a/extension.js b/extension.js index 9bd47a5..d11f271 100644 --- a/extension.js +++ b/extension.js @@ -34,6 +34,8 @@ const BackgroundLogo = new Lang.Class({ _init: function(bgManager) { this._bgManager = bgManager; + this._logoFile = null; + this._settings = Convenience.getSettings(); this._settings.connect('changed::logo-file', @@ -80,16 +82,21 @@ const BackgroundLogo = new Lang.Class({ }, _updateLogo: function() { + let filename = this._settings.get_string('logo-file'); + let file = Gio.File.new_for_commandline_arg(filename); + if (this._logoFile && this._logoFile.equal(file)) + return; + + this._logoFile = file; + if (this._icon) this._icon.destroy(); - let filename = this._settings.get_string('logo-file'); - let file = Gio.File.new_for_commandline_arg(filename); let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; if (this._textureCache.load_file_async) { // > 3.14 - this._icon = this._textureCache.load_file_async(file, -1, -1, scaleFactor); + this._icon = this._textureCache.load_file_async(this._logoFile, -1, -1, scaleFactor); } else { // <= 3.14 - this._icon = this._textureCache.load_uri_async(file.get_uri(), -1, -1, scaleFactor); + this._icon = this._textureCache.load_uri_async(this._logoFile.get_uri(), -1, -1, scaleFactor); } this._icon.connect('allocation-changed', Lang.bind(this, this._updateScale)); @@ -189,6 +196,8 @@ const BackgroundLogo = new Lang.Class({ this._bgChangedId = 0; this._bgManager = null; + + this._logoFile = null; } }); From 926eea48a5ba22243d2b437b6ce84fb6c9ea03a4 Mon Sep 17 00:00:00 2001 From: Florian Müllner Date: Mar 30 2017 16:54:18 +0000 Subject: [PATCH 2/2] Update logo on texture file changes While it is generally more common to change the configured logo file than updating the used file's contents, it's still useful for the logo artist to see changes in real time - as the texture cache already sets up a file monitor for us, all we have to do to support this case is recreating the icon texture itself. https://pagure.io/background-logo-extension/issue/2 --- diff --git a/extension.js b/extension.js index d11f271..13ae308 100644 --- a/extension.js +++ b/extension.js @@ -50,6 +50,12 @@ const BackgroundLogo = new Lang.Class({ Lang.bind(this, this._updateVisibility)); this._textureCache = St.TextureCache.get_default(); + this._textureCache.connect('texture-file-changed', Lang.bind(this, + function(cache, file) { + if (!this._logoFile || !this._logoFile.equal(file)) + return; + this._updateLogoTexture(); + })); this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(), opacity: 0 }); @@ -89,6 +95,10 @@ const BackgroundLogo = new Lang.Class({ this._logoFile = file; + this._updateLogoTexture(); + }, + + _updateLogoTexture: function() { if (this._icon) this._icon.destroy();