cleanup: Use inheritance for Actor classes instead of composition

Remove the `this.actor = ...` and `this.actor._delegate = this` patterns in most
of classes, by inheriting all the actor container classes.

Uses interfaces when needed for making sure that multiple classes will implement
some required methods or to avoid redefining the same code multiple times.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/559
This commit is contained in:
Marco Trevisan (Treviño)
2019-07-16 11:24:13 +02:00
committed by Florian Müllner
parent f67b409fc1
commit c4c5c4fd5c
58 changed files with 2000 additions and 1757 deletions

View File

@ -1,4 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported SystemBackground */
// READ THIS FIRST
// Background handling is a maze of objects, both objects in this file, and
@ -93,7 +94,7 @@
// MetaBackgroundImage MetaBackgroundImage
// MetaBackgroundImage MetaBackgroundImage
const { Clutter, GDesktopEnums, Gio, GLib, GnomeDesktop, Meta } = imports.gi;
const { Clutter, GDesktopEnums, Gio, GLib, GObject, GnomeDesktop, Meta } = imports.gi;
const Signals = imports.signals;
const LoginManager = imports.misc.loginManager;
@ -220,16 +221,17 @@ function getBackgroundCache() {
return _backgroundCache;
}
var Background = class Background {
constructor(params) {
var Background = GObject.registerClass({
Signals: { 'loaded': {}, 'bg-changed': {} }
}, class Background extends Meta.Background {
_init(params) {
params = Params.parse(params, { monitorIndex: 0,
layoutManager: Main.layoutManager,
settings: null,
file: null,
style: null });
this.background = new Meta.Background({ meta_display: global.display });
this.background._delegate = this;
super._init({ meta_display: global.display });
this._settings = params.settings;
this._file = params.file;
@ -262,8 +264,6 @@ var Background = class Background {
}
destroy() {
this.background = null;
this._cancellable.cancel();
this._removeAnimationTimeout();
@ -330,7 +330,7 @@ var Background = class Background {
this.emit('loaded');
return GLib.SOURCE_REMOVE;
});
GLib.Source.set_name_by_id(id, '[gnome-shell] this.emit');
GLib.Source.set_name_by_id(id, '[gnome-shell] Background._setLoaded Idle');
}
_loadPattern() {
@ -344,9 +344,9 @@ var Background = class Background {
let shadingType = this._settings.get_enum(COLOR_SHADING_TYPE_KEY);
if (shadingType == GDesktopEnums.BackgroundShading.SOLID)
this.background.set_color(color);
this.set_color(color);
else
this.background.set_gradient(shadingType, color, secondColor);
this.set_gradient(shadingType, color, secondColor);
}
_watchFile(file) {
@ -382,13 +382,13 @@ var Background = class Background {
let finish = () => {
this._setLoaded();
if (files.length > 1) {
this.background.set_blend(files[0], files[1],
this._animation.transitionProgress,
this._style);
this.set_blend(files[0], files[1],
this._animation.transitionProgress,
this._style);
} else if (files.length > 0) {
this.background.set_file(files[0], this._style);
this.set_file(files[0], this._style);
} else {
this.background.set_file(null, this._style);
this.set_file(null, this._style);
}
this._queueUpdateAnimation();
};
@ -461,7 +461,7 @@ var Background = class Background {
}
_loadImage(file) {
this.background.set_file(file, this._style);
this.set_file(file, this._style);
this._watchFile(file);
let cache = Meta.BackgroundImageCache.get_default();
@ -495,13 +495,14 @@ var Background = class Background {
this._loadFile(this._file);
}
};
Signals.addSignalMethods(Background.prototype);
});
let _systemBackground;
var SystemBackground = class SystemBackground {
constructor() {
var SystemBackground = GObject.registerClass({
Signals: { 'loaded': {} }
}, class SystemBackground extends Meta.BackgroundActor {
_init() {
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/noise-texture.png');
if (_systemBackground == null) {
@ -510,9 +511,11 @@ var SystemBackground = class SystemBackground {
_systemBackground.set_file(file, GDesktopEnums.BackgroundStyle.WALLPAPER);
}
this.actor = new Meta.BackgroundActor({ meta_display: global.display,
monitor: 0,
background: _systemBackground });
super._init({
meta_display: global.display,
monitor: 0,
background: _systemBackground
});
let cache = Meta.BackgroundImageCache.get_default();
let image = cache.load(file);
@ -531,8 +534,7 @@ var SystemBackground = class SystemBackground {
});
}
}
};
Signals.addSignalMethods(SystemBackground.prototype);
});
var BackgroundSource = class BackgroundSource {
constructor(layoutManager, settingsSchema) {
@ -734,7 +736,7 @@ var BackgroundManager = class BackgroundManager {
this._newBackgroundActor = newBackgroundActor;
let background = newBackgroundActor.background._delegate;
let background = newBackgroundActor.background;
if (background.isLoaded) {
this._swapBackgroundActor();
@ -754,7 +756,7 @@ var BackgroundManager = class BackgroundManager {
let backgroundActor = new Meta.BackgroundActor({
meta_display: global.display,
monitor: this._monitorIndex,
background: background.background,
background,
vignette: this._vignette,
vignette_sharpness: 0.5,
brightness: 0.5,