| |
@@ -14,10 +14,7 @@
|
| |
* You should have received a copy of the GNU General Public License
|
| |
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
| |
*/
|
| |
- const Clutter = imports.gi.Clutter;
|
| |
- const Gio = imports.gi.Gio;
|
| |
- const Lang = imports.lang;
|
| |
- const St = imports.gi.St;
|
| |
+ const { Clutter, Gio, St } = imports.gi;
|
| |
|
| |
const Background = imports.ui.background;
|
| |
const Layout = imports.ui.layout;
|
| |
@@ -28,10 +25,8 @@
|
| |
const Me = ExtensionUtils.getCurrentExtension();
|
| |
const Convenience = Me.imports.convenience;
|
| |
|
| |
- const BackgroundLogo = new Lang.Class({
|
| |
- Name: 'BackgroundLogo',
|
| |
-
|
| |
- _init: function(bgManager) {
|
| |
+ class BackgroundLogo {
|
| |
+ constructor(bgManager) {
|
| |
this._bgManager = bgManager;
|
| |
|
| |
this._logoFile = null;
|
| |
@@ -39,29 +34,28 @@
|
| |
this._settings = Convenience.getSettings();
|
| |
|
| |
this._settings.connect('changed::logo-file',
|
| |
- Lang.bind(this, this._updateLogo));
|
| |
+ this._updateLogo.bind(this));
|
| |
this._settings.connect('changed::logo-size',
|
| |
- Lang.bind(this, this._updateScale));
|
| |
+ this._updateScale.bind(this));
|
| |
this._settings.connect('changed::logo-position',
|
| |
- Lang.bind(this, this._updatePosition));
|
| |
+ this._updatePosition.bind(this));
|
| |
this._settings.connect('changed::logo-border',
|
| |
- Lang.bind(this, this._updateBorder));
|
| |
+ this._updateBorder.bind(this));
|
| |
this._settings.connect('changed::logo-always-visible',
|
| |
- Lang.bind(this, this._updateVisibility));
|
| |
+ this._updateVisibility.bind(this));
|
| |
|
| |
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._textureCache.connect('texture-file-changed', (cache, file) => {
|
| |
+ if (!this._logoFile || !this._logoFile.equal(file))
|
| |
+ return;
|
| |
+ this._updateLogoTexture();
|
| |
+ });
|
| |
|
| |
this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(),
|
| |
opacity: 0 });
|
| |
bgManager._container.add_actor(this.actor);
|
| |
|
| |
- this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
| |
+ this.actor.connect('destroy', this._onDestroy.bind(this));
|
| |
|
| |
let monitorIndex = bgManager._monitorIndex;
|
| |
let constraint = new Layout.MonitorConstraint({ index: monitorIndex,
|
| |
@@ -80,14 +74,14 @@
|
| |
|
| |
this._bgDestroyedId =
|
| |
bgManager.backgroundActor.connect('destroy',
|
| |
- Lang.bind(this, this._backgroundDestroyed));
|
| |
+ this._backgroundDestroyed.bind(this));
|
| |
|
| |
this._bgChangedId =
|
| |
- bgManager.connect('changed', Lang.bind(this, this._updateVisibility));
|
| |
+ bgManager.connect('changed', this._updateVisibility.bind(this));
|
| |
this._updateVisibility();
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updateLogo: function() {
|
| |
+ _updateLogo() {
|
| |
let filename = this._settings.get_string('logo-file');
|
| |
let file = Gio.File.new_for_commandline_arg(filename);
|
| |
if (this._logoFile && this._logoFile.equal(file))
|
| |
@@ -96,24 +90,20 @@
|
| |
this._logoFile = file;
|
| |
|
| |
this._updateLogoTexture();
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updateLogoTexture: function() {
|
| |
+ _updateLogoTexture() {
|
| |
if (this._icon)
|
| |
this._icon.destroy();
|
| |
|
| |
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(this._logoFile, -1, -1, scaleFactor);
|
| |
- } else { // <= 3.14
|
| |
- this._icon = this._textureCache.load_uri_async(this._logoFile.get_uri(), -1, -1, scaleFactor);
|
| |
- }
|
| |
+ this._icon = this._textureCache.load_file_async(this._logoFile, -1, -1, scaleFactor);
|
| |
this._icon.connect('allocation-changed',
|
| |
- Lang.bind(this, this._updateScale));
|
| |
+ this._updateScale.bind(this));
|
| |
this._bin.add_actor(this._icon);
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updateScale: function() {
|
| |
+ _updateScale() {
|
| |
if (this._icon.width == 0)
|
| |
return;
|
| |
|
| |
@@ -129,9 +119,9 @@
|
| |
return;
|
| |
}
|
| |
this._icon.set_size(width, height);
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updatePosition: function() {
|
| |
+ _updatePosition() {
|
| |
let xAlign, yAlign;
|
| |
switch (this._settings.get_string('logo-position')) {
|
| |
case 'center':
|
| |
@@ -153,14 +143,14 @@
|
| |
}
|
| |
this._bin.x_align = xAlign;
|
| |
this._bin.y_align = yAlign;
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updateBorder: function() {
|
| |
+ _updateBorder() {
|
| |
let border = this._settings.get_uint('logo-border');
|
| |
this.actor.style = 'padding: %dpx;'.format(border);
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _updateVisibility: function() {
|
| |
+ _updateVisibility() {
|
| |
let background = this._bgManager.backgroundActor.background._delegate;
|
| |
let defaultUri = background._settings.get_default_value('picture-uri');
|
| |
let file = Gio.File.new_for_commandline_arg(defaultUri.deep_unpack());
|
| |
@@ -180,20 +170,20 @@
|
| |
time: Background.FADE_ANIMATION_TIME,
|
| |
transition: 'easeOutQuad'
|
| |
});
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _backgroundDestroyed: function() {
|
| |
+ _backgroundDestroyed() {
|
| |
this._bgDestroyedId = 0;
|
| |
|
| |
if (this._bgManager._backgroundSource) // background swapped
|
| |
this._bgDestroyedId =
|
| |
this._bgManager.backgroundActor.connect('destroy',
|
| |
- Lang.bind(this, this._backgroundDestroyed));
|
| |
+ this._backgroundDestroyed.bind(this));
|
| |
else // bgManager destroyed
|
| |
this.actor.destroy();
|
| |
- },
|
| |
+ }
|
| |
|
| |
- _onDestroy: function() {
|
| |
+ _onDestroy() {
|
| |
this._settings.run_dispose();
|
| |
this._settings = null;
|
| |
|
| |
@@ -209,48 +199,54 @@
|
| |
|
| |
this._logoFile = null;
|
| |
}
|
| |
- });
|
| |
-
|
| |
+ }
|
| |
|
| |
- let monitorsChangedId = 0;
|
| |
- let startupPreparedId = 0;
|
| |
- let logos = [];
|
| |
|
| |
- function forEachBackgroundManager(func) {
|
| |
- Main.overview._bgManagers.forEach(func);
|
| |
- Main.layoutManager._bgManagers.forEach(func);
|
| |
- }
|
| |
+ class Extension {
|
| |
+ constructor() {
|
| |
+ this._monitorsChangedId = 0;
|
| |
+ this._startupPreparedId = 0;
|
| |
+ this._logos = [];
|
| |
+ }
|
| |
|
| |
- function addLogo() {
|
| |
- destroyLogo();
|
| |
- forEachBackgroundManager(function(bgManager) {
|
| |
- logos.push(new BackgroundLogo(bgManager));
|
| |
- });
|
| |
- }
|
| |
+ _forEachBackgroundManager(func) {
|
| |
+ Main.overview._bgManagers.forEach(func);
|
| |
+ Main.layoutManager._bgManagers.forEach(func);
|
| |
+ }
|
| |
|
| |
- function destroyLogo() {
|
| |
- logos.forEach(function(l) { l.actor.destroy(); });
|
| |
- logos = [];
|
| |
- }
|
| |
+ _addLogo() {
|
| |
+ this._destroyLogo();
|
| |
+ this._forEachBackgroundManager(bgManager => {
|
| |
+ this._logos.push(new BackgroundLogo(bgManager));
|
| |
+ });
|
| |
+ }
|
| |
|
| |
- function init() {
|
| |
- }
|
| |
+ _destroyLogo() {
|
| |
+ this._logos.forEach(l => { l.actor.destroy(); });
|
| |
+ this._logos = [];
|
| |
+ }
|
| |
|
| |
- function enable() {
|
| |
+ 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();
|
| |
+ }
|
| |
|
| |
- monitorsChangedId = Main.layoutManager.connect('monitors-changed', addLogo);
|
| |
- startupPreparedId = Main.layoutManager.connect('startup-prepared', addLogo);
|
| |
- addLogo();
|
| |
- }
|
| |
+ disable() {
|
| |
+ if (this._monitorsChangedId)
|
| |
+ Main.layoutManager.disconnect(this._monitorsChangedId);
|
| |
+ this._monitorsChangedId = 0;
|
| |
|
| |
- function disable() {
|
| |
- if (monitorsChangedId)
|
| |
- Main.layoutManager.disconnect(monitorsChangedId);
|
| |
- monitorsChangedId = 0;
|
| |
+ if (this._startupPreparedId)
|
| |
+ Main.layoutManager.disconnect(this._startupPreparedId);
|
| |
+ this._startupPreparedId = 0;
|
| |
|
| |
- if (startupPreparedId)
|
| |
- Main.layoutManager.disconnect(startupPreparedId);
|
| |
- startupPreparedId = 0;
|
| |
+ this._destroyLogo();
|
| |
+ }
|
| |
+ }
|
| |
|
| |
- destroyLogo();
|
| |
+ function init() {
|
| |
+ return new Extension();
|
| |
}
|
| |
Move the code to ES6