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
@ -93,6 +93,7 @@ class WindowCloneLayout extends Clutter.LayoutManager {
|
||||
});
|
||||
|
||||
var WindowClone = GObject.registerClass({
|
||||
GTypeName: 'Workspace_WindowClone',
|
||||
Signals: {
|
||||
'drag-begin': {},
|
||||
'drag-cancelled': {},
|
||||
@ -102,7 +103,7 @@ var WindowClone = GObject.registerClass({
|
||||
'show-chrome': {},
|
||||
'size-changed': {}
|
||||
},
|
||||
}, class WorkspaceWindowClone extends St.Widget {
|
||||
}, class WindowClone extends St.Widget {
|
||||
_init(realWindow, workspace) {
|
||||
this.realWindow = realWindow;
|
||||
this.metaWindow = realWindow.meta_window;
|
||||
@ -1094,23 +1095,14 @@ function rectEqual(one, two) {
|
||||
one.height == two.height);
|
||||
}
|
||||
|
||||
const WorkspaceActor = GObject.registerClass(
|
||||
class WorkspaceActor extends St.Widget {
|
||||
vfunc_get_focus_chain() {
|
||||
return this.get_children().filter(c => c.visible).sort((a, b) => {
|
||||
if (a instanceof WindowClone && b instanceof WindowClone)
|
||||
return a.slotId - b.slotId;
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @metaWorkspace: a #Meta.Workspace, or null
|
||||
*/
|
||||
var Workspace = class {
|
||||
constructor(metaWorkspace, monitorIndex) {
|
||||
var Workspace = GObject.registerClass(
|
||||
class Workspace extends St.Widget {
|
||||
_init(metaWorkspace, monitorIndex) {
|
||||
super._init({ style_class: 'window-picker' });
|
||||
|
||||
// When dragging a window, we use this slot for reserve space.
|
||||
this._reservedSlot = null;
|
||||
this._reservedSlotWindow = null;
|
||||
@ -1136,18 +1128,17 @@ var Workspace = class {
|
||||
// Without this the drop area will be overlapped.
|
||||
this._windowOverlaysGroup.set_size(0, 0);
|
||||
|
||||
this.actor = new WorkspaceActor({ style_class: 'window-picker' });
|
||||
if (monitorIndex != Main.layoutManager.primaryIndex)
|
||||
this.actor.add_style_class_name('external-monitor');
|
||||
this.actor.set_size(0, 0);
|
||||
this.add_style_class_name('external-monitor');
|
||||
this.set_size(0, 0);
|
||||
|
||||
this._dropRect = new Clutter.Actor({ opacity: 0 });
|
||||
this._dropRect._delegate = this;
|
||||
|
||||
this.actor.add_actor(this._dropRect);
|
||||
this.actor.add_actor(this._windowOverlaysGroup);
|
||||
this.add_actor(this._dropRect);
|
||||
this.add_actor(this._windowOverlaysGroup);
|
||||
|
||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
||||
this.connect('destroy', this._onDestroy.bind(this));
|
||||
|
||||
let windows = global.get_window_actors().filter(this._isMyWindow, this);
|
||||
|
||||
@ -1178,19 +1169,28 @@ var Workspace = class {
|
||||
this._positionWindowsFlags = 0;
|
||||
this._positionWindowsId = 0;
|
||||
|
||||
this.actor.connect('notify::mapped', () => {
|
||||
if (this.actor.mapped)
|
||||
this.connect('notify::mapped', () => {
|
||||
if (this.mapped)
|
||||
this._syncActualGeometry();
|
||||
});
|
||||
}
|
||||
|
||||
vfunc_get_focus_chain() {
|
||||
return this.get_children().filter(c => c.visible).sort((a, b) => {
|
||||
if (a instanceof WindowClone && b instanceof WindowClone)
|
||||
return a.slotId - b.slotId;
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
setFullGeometry(geom) {
|
||||
if (rectEqual(this._fullGeometry, geom))
|
||||
return;
|
||||
|
||||
this._fullGeometry = geom;
|
||||
|
||||
if (this.actor.mapped)
|
||||
if (this.mapped)
|
||||
this._recalculateWindowPositions(WindowPositionFlags.NONE);
|
||||
}
|
||||
|
||||
@ -1201,7 +1201,7 @@ var Workspace = class {
|
||||
this._actualGeometry = geom;
|
||||
this._actualGeometryDirty = true;
|
||||
|
||||
if (this.actor.mapped)
|
||||
if (this.mapped)
|
||||
this._syncActualGeometry();
|
||||
}
|
||||
|
||||
@ -1213,7 +1213,7 @@ var Workspace = class {
|
||||
|
||||
this._actualGeometryLater = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
||||
this._actualGeometryLater = 0;
|
||||
if (!this.actor.mapped)
|
||||
if (!this.mapped)
|
||||
return false;
|
||||
|
||||
let geom = this._actualGeometry;
|
||||
@ -1504,8 +1504,7 @@ var Workspace = class {
|
||||
// Newly-created windows are added to a workspace before
|
||||
// the compositor finds out about them...
|
||||
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||
if (this.actor &&
|
||||
metaWin.get_compositor_private() &&
|
||||
if (metaWin.get_compositor_private() &&
|
||||
metaWin.get_workspace() == this.metaWorkspace)
|
||||
this._doAddWindow(metaWin);
|
||||
return GLib.SOURCE_REMOVE;
|
||||
@ -1541,8 +1540,8 @@ var Workspace = class {
|
||||
let [clone, overlay_] = this._addWindowClone(win, false);
|
||||
|
||||
if (win._overviewHint) {
|
||||
let x = win._overviewHint.x - this.actor.x;
|
||||
let y = win._overviewHint.y - this.actor.y;
|
||||
let x = win._overviewHint.x - this.x;
|
||||
let y = win._overviewHint.y - this.y;
|
||||
let scale = win._overviewHint.scale;
|
||||
delete win._overviewHint;
|
||||
|
||||
@ -1777,10 +1776,6 @@ var Workspace = class {
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.actor.destroy();
|
||||
}
|
||||
|
||||
_onDestroy() {
|
||||
if (this._overviewHiddenId) {
|
||||
Main.overview.disconnect(this._overviewHiddenId);
|
||||
@ -1861,11 +1856,11 @@ var Workspace = class {
|
||||
this._removeWindowClone(clone.metaWindow);
|
||||
});
|
||||
|
||||
this.actor.add_actor(clone);
|
||||
this.add_actor(clone);
|
||||
|
||||
overlay.connect('chrome-visible', () => {
|
||||
let focus = global.stage.key_focus;
|
||||
if (focus == null || this.actor.contains(focus))
|
||||
if (focus == null || this.contains(focus))
|
||||
clone.grab_key_focus();
|
||||
|
||||
this._windowOverlays.forEach(o => {
|
||||
@ -1949,7 +1944,7 @@ var Workspace = class {
|
||||
}
|
||||
|
||||
_getSpacingAndPadding() {
|
||||
let node = this.actor.get_theme_node();
|
||||
let node = this.get_theme_node();
|
||||
|
||||
// Window grid spacing
|
||||
let columnSpacing = node.get_length('-horizontal-spacing');
|
||||
@ -2047,5 +2042,4 @@ var Workspace = class {
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Signals.addSignalMethods(Workspace.prototype);
|
||||
});
|
||||
|
Reference in New Issue
Block a user