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:

committed by
Florian Müllner

parent
f67b409fc1
commit
c4c5c4fd5c
@ -41,22 +41,25 @@ class OsdWindowConstraint extends Clutter.Constraint {
|
||||
}
|
||||
});
|
||||
|
||||
var OsdWindow = class {
|
||||
constructor(monitorIndex) {
|
||||
this.actor = new St.Widget({ x_expand: true,
|
||||
y_expand: true,
|
||||
x_align: Clutter.ActorAlign.CENTER,
|
||||
y_align: Clutter.ActorAlign.CENTER });
|
||||
var OsdWindow = GObject.registerClass(
|
||||
class OsdWindow extends St.Widget {
|
||||
_init(monitorIndex) {
|
||||
super._init({
|
||||
x_expand: true,
|
||||
y_expand: true,
|
||||
x_align: Clutter.ActorAlign.CENTER,
|
||||
y_align: Clutter.ActorAlign.CENTER
|
||||
});
|
||||
|
||||
this._monitorIndex = monitorIndex;
|
||||
let constraint = new Layout.MonitorConstraint({ index: monitorIndex });
|
||||
this.actor.add_constraint(constraint);
|
||||
this.add_constraint(constraint);
|
||||
|
||||
this._boxConstraint = new OsdWindowConstraint();
|
||||
this._box = new St.BoxLayout({ style_class: 'osd-window',
|
||||
vertical: true });
|
||||
this._box.add_constraint(this._boxConstraint);
|
||||
this.actor.add_actor(this._box);
|
||||
this.add_actor(this._box);
|
||||
|
||||
this._icon = new St.Icon();
|
||||
this._box.add(this._icon, { expand: true });
|
||||
@ -73,7 +76,7 @@ var OsdWindow = class {
|
||||
this._hideTimeoutId = 0;
|
||||
this._reset();
|
||||
|
||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
|
||||
this._monitorsChangedId =
|
||||
Main.layoutManager.connect('monitors-changed',
|
||||
@ -83,7 +86,7 @@ var OsdWindow = class {
|
||||
themeContext.connect('notify::scale-factor',
|
||||
this._relayout.bind(this));
|
||||
this._relayout();
|
||||
Main.uiGroup.add_child(this.actor);
|
||||
Main.uiGroup.add_child(this);
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
@ -110,7 +113,7 @@ var OsdWindow = class {
|
||||
setLevel(value) {
|
||||
this._level.visible = (value != undefined);
|
||||
if (value != undefined) {
|
||||
if (this.actor.visible)
|
||||
if (this.visible)
|
||||
this._level.ease_property('value', value, {
|
||||
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
||||
duration: LEVEL_ANIMATION_TIME
|
||||
@ -128,13 +131,13 @@ var OsdWindow = class {
|
||||
if (!this._icon.gicon)
|
||||
return;
|
||||
|
||||
if (!this.actor.visible) {
|
||||
if (!this.visible) {
|
||||
Meta.disable_unredirect_for_display(global.display);
|
||||
this.actor.show();
|
||||
this.actor.opacity = 0;
|
||||
this.actor.get_parent().set_child_above_sibling(this.actor, null);
|
||||
super.show();
|
||||
this.opacity = 0;
|
||||
this.get_parent().set_child_above_sibling(this, null);
|
||||
|
||||
this.actor.ease({
|
||||
this.ease({
|
||||
opacity: 255,
|
||||
duration: FADE_TIME,
|
||||
mode: Clutter.AnimationMode.EASE_OUT_QUAD
|
||||
@ -158,7 +161,7 @@ var OsdWindow = class {
|
||||
|
||||
_hide() {
|
||||
this._hideTimeoutId = 0;
|
||||
this.actor.ease({
|
||||
this.ease({
|
||||
opacity: 0,
|
||||
duration: FADE_TIME,
|
||||
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
||||
@ -171,7 +174,7 @@ var OsdWindow = class {
|
||||
}
|
||||
|
||||
_reset() {
|
||||
this.actor.hide();
|
||||
super.hide();
|
||||
this.setLabel(null);
|
||||
this.setMaxLevel(null);
|
||||
this.setLevel(null);
|
||||
@ -193,7 +196,7 @@ var OsdWindow = class {
|
||||
this._box.translation_y = Math.round(monitor.height / 4);
|
||||
this._boxConstraint.minSize = popupSize;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var OsdWindowManager = class {
|
||||
constructor() {
|
||||
@ -210,7 +213,7 @@ var OsdWindowManager = class {
|
||||
}
|
||||
|
||||
for (let i = Main.layoutManager.monitors.length; i < this._osdWindows.length; i++) {
|
||||
this._osdWindows[i].actor.destroy();
|
||||
this._osdWindows[i].destroy();
|
||||
this._osdWindows[i] = null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user