[gnome-shell/wip/fmuellner/window-preview-translucency: 475/476] workspace: Let WindowClone inherit from StWidget
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/fmuellner/window-preview-translucency: 475/476] workspace: Let WindowClone inherit from StWidget
- Date: Wed, 1 May 2019 10:03:54 +0000 (UTC)
commit fa5ea2388c99befdc80c087f4d08b82d0773b0d8
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Nov 14 19:26:33 2018 +0100
workspace: Let WindowClone inherit from StWidget
Using inheritance over delegation will give us more control over
the actor drawing.
https://gitlab.gnome.org/GNOME/gnome-shell/issues/774
js/ui/workspace.js | 167 +++++++++++++++++++++++++++--------------------------
1 file changed, 86 insertions(+), 81 deletions(-)
---
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index cf52684c0..f350763df 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -94,8 +94,18 @@ class WindowCloneLayout extends Clutter.LayoutManager {
}
});
-var WindowClone = class {
- constructor(realWindow, workspace) {
+var WindowClone = GObject.registerClass({
+ Signals: {
+ 'drag-begin': {},
+ 'drag-cancelled': {},
+ 'drag-end': {},
+ 'hide-chrome': {},
+ 'selected': { param_types: [GObject.TYPE_UINT] },
+ 'show-chrome': {},
+ 'size-changed': {}
+ },
+}, class WindowClone extends St.Widget {
+ _init(realWindow, workspace) {
this.realWindow = realWindow;
this.metaWindow = realWindow.meta_window;
this.metaWindow._delegate = this;
@@ -113,14 +123,16 @@ var WindowClone = class {
// the invisible border; this is inconvenient; rather than trying
// to compensate all over the place we insert a ClutterActor into
// the hierarchy that is sized to only the visible portion.
- this.actor = new St.Widget({ reactive: true,
- can_focus: true,
- accessible_role: Atk.Role.PUSH_BUTTON,
- layout_manager: new WindowCloneLayout() });
+ super._init({
+ reactive: true,
+ can_focus: true,
+ accessible_role: Atk.Role.PUSH_BUTTON,
+ layout_manager: new WindowCloneLayout()
+ });
- this.actor.add_child(this._windowClone);
+ this.add_child(this._windowClone);
- this.actor._delegate = this;
+ this._delegate = this;
this.slotId = 0;
this._slot = [0, 0, 0, 0];
@@ -142,23 +154,23 @@ var WindowClone = class {
this._updateAttachedDialogs();
this._computeBoundingBox();
- this.actor.x = this._boundingBox.x;
- this.actor.y = this._boundingBox.y;
+ this.x = this._boundingBox.x;
+ this.y = this._boundingBox.y;
let clickAction = new Clutter.ClickAction();
clickAction.connect('clicked', this._onClicked.bind(this));
clickAction.connect('long-press', this._onLongPress.bind(this));
- this.actor.add_action(clickAction);
- this.actor.connect('destroy', this._onDestroy.bind(this));
- this.actor.connect('key-press-event', this._onKeyPress.bind(this));
+ this.add_action(clickAction);
+ this.connect('destroy', this._onDestroy.bind(this));
+ this.connect('key-press-event', this._onKeyPress.bind(this));
- this.actor.connect('enter-event', () => { this.emit('show-chrome'); });
- this.actor.connect('key-focus-in', () => { this.emit('show-chrome'); });
+ this.connect('enter-event', () => { this.emit('show-chrome'); });
+ this.connect('key-focus-in', () => { this.emit('show-chrome'); });
- this.actor.connect('leave-event', () => { this.emit('hide-chrome'); });
- this.actor.connect('key-focus-out', () => { this.emit('hide-chrome'); });
+ this.connect('leave-event', () => { this.emit('hide-chrome'); });
+ this.connect('key-focus-out', () => { this.emit('hide-chrome'); });
- this._draggable = DND.makeDraggable(this.actor,
+ this._draggable = DND.makeDraggable(this,
{ restoreOnSuccess: true,
manualMode: true,
dragActorMaxSize: WINDOW_DND_SIZE,
@@ -185,7 +197,7 @@ var WindowClone = class {
deleteAll() {
// Delete all windows, starting from the bottom-most (most-modal) one
- let windows = this.actor.get_children();
+ let windows = this.get_children();
for (let i = windows.length - 1; i >= 1; i--) {
let realWindow = windows[i].source;
let metaWindow = realWindow.meta_window;
@@ -215,7 +227,7 @@ var WindowClone = class {
}
hasAttachedDialogs() {
- return this.actor.get_n_children() > 1;
+ return this.get_n_children() > 1;
}
_doAddAttachedDialog(metaWin, realWin) {
@@ -229,7 +241,7 @@ var WindowClone = class {
this._onMetaWindowSizeChanged();
});
- this.actor.add_child(clone);
+ this.add_child(clone);
}
_updateAttachedDialogs() {
@@ -267,7 +279,7 @@ var WindowClone = class {
_computeBoundingBox() {
let rect = this.metaWindow.get_frame_rect();
- this.actor.get_children().forEach(child => {
+ this.get_children().forEach(child => {
let realWindow;
if (child == this._windowClone)
realWindow = this.realWindow;
@@ -280,7 +292,7 @@ var WindowClone = class {
// Convert from a MetaRectangle to a native JS object
this._boundingBox = { x: rect.x, y: rect.y, width: rect.width, height: rect.height };
- this.actor.layout_manager.boundingBox = rect;
+ this.layout_manager.boundingBox = rect;
}
// Find the actor just below us, respecting reparenting done by DND code
@@ -306,17 +318,13 @@ var WindowClone = class {
let actualAbove = this.getActualStackAbove();
if (actualAbove == null)
- this.actor.lower_bottom();
+ this.lower_bottom();
else
- this.actor.raise(actualAbove);
- }
-
- destroy() {
- this.actor.destroy();
+ this.raise(actualAbove);
}
_disconnectSignals() {
- this.actor.get_children().forEach(child => {
+ this.get_children().forEach(child => {
let realWindow;
if (child == this._windowClone)
realWindow = this.realWindow;
@@ -338,14 +346,12 @@ var WindowClone = class {
this._disconnectSignals();
this.metaWindow._delegate = null;
- this.actor._delegate = null;
+ this._delegate = null;
if (this.inDrag) {
this.emit('drag-end');
this.inDrag = false;
}
-
- this.disconnectAll();
}
_activate() {
@@ -393,8 +399,8 @@ var WindowClone = class {
_onDragBegin(draggable, time) {
this._dragSlot = this._slot;
- [this.dragOrigX, this.dragOrigY] = this.actor.get_position();
- this.dragOrigScale = this.actor.scale_x;
+ [this.dragOrigX, this.dragOrigY] = this.get_position();
+ this.dragOrigScale = this.scale_x;
this.inDrag = true;
this.emit('drag-begin');
}
@@ -417,18 +423,17 @@ var WindowClone = class {
// We may not have a parent if DnD completed successfully, in
// which case our clone will shortly be destroyed and replaced
// with a new one on the target workspace.
- if (this.actor.get_parent() != null) {
+ if (this.get_parent() != null) {
if (this._stackAbove == null)
- this.actor.lower_bottom();
+ this.lower_bottom();
else
- this.actor.raise(this._stackAbove);
+ this.raise(this._stackAbove);
}
this.emit('drag-end');
}
-};
-Signals.addSignalMethods(WindowClone.prototype);
+});
/**
@@ -452,7 +457,7 @@ var WindowOverlay = class {
this.title = new St.Label({ style_class: 'window-caption',
text: this._getCaption() });
this.title.clutter_text.ellipsize = Pango.EllipsizeMode.END;
- windowClone.actor.label_actor = this.title;
+ windowClone.label_actor = this.title;
this._maxTitleWidth = -1;
@@ -467,7 +472,7 @@ var WindowOverlay = class {
this.closeButton.connect('clicked', () => this._windowClone.deleteAll());
- windowClone.actor.connect('destroy', this._onDestroy.bind(this));
+ windowClone.connect('destroy', this._onDestroy.bind(this));
windowClone.connect('show-chrome', this._onShowChrome.bind(this));
windowClone.connect('hide-chrome', this._onHideChrome.bind(this));
@@ -503,7 +508,7 @@ var WindowOverlay = class {
show() {
this._hidden = false;
- if (this._windowClone.actor['has-pointer'])
+ if (this._windowClone['has-pointer'])
this._animateVisible();
}
@@ -675,7 +680,7 @@ var WindowOverlay = class {
_idleHideOverlay() {
this._idleHideOverlayId = 0;
- if (!this._windowClone.actor['has-pointer'] &&
+ if (!this._windowClone['has-pointer'] &&
!this.closeButton['has-pointer'])
this._animateInvisible();
@@ -1297,8 +1302,8 @@ var Workspace = class {
if (clone.inDrag)
continue;
- let cloneWidth = clone.actor.width * scale;
- let cloneHeight = clone.actor.height * scale;
+ let cloneWidth = clone.width * scale;
+ let cloneHeight = clone.height * scale;
clone.slot = [x, y, cloneWidth, cloneHeight];
let cloneCenter = x + cloneWidth / 2;
@@ -1313,10 +1318,10 @@ var Workspace = class {
if (!clone.positioned) {
// This window appeared after the overview was already up
// Grow the clone from the center of the slot
- clone.actor.x = x + cloneWidth / 2;
- clone.actor.y = y + cloneHeight / 2;
- clone.actor.scale_x = 0;
- clone.actor.scale_y = 0;
+ clone.x = x + cloneWidth / 2;
+ clone.y = y + cloneHeight / 2;
+ clone.scale_x = 0;
+ clone.scale_y = 0;
clone.positioned = true;
}
@@ -1326,14 +1331,14 @@ var Workspace = class {
* therefore we need to resize them now so they
* can be scaled up later */
if (initialPositioning) {
- clone.actor.opacity = 0;
- clone.actor.scale_x = 0;
- clone.actor.scale_y = 0;
- clone.actor.x = x;
- clone.actor.y = y;
+ clone.opacity = 0;
+ clone.scale_x = 0;
+ clone.scale_y = 0;
+ clone.x = x;
+ clone.y = y;
}
- Tweener.addTween(clone.actor,
+ Tweener.addTween(clone,
{ opacity: 255,
time: Overview.ANIMATION_TIME,
transition: 'easeInQuad'
@@ -1343,10 +1348,10 @@ var Workspace = class {
this._animateClone(clone, clone.overlay, x, y, scale);
} else {
// cancel any active tweens (otherwise they might override our changes)
- Tweener.removeTweens(clone.actor);
- clone.actor.set_position(x, y);
- clone.actor.set_scale(scale, scale);
- clone.actor.set_opacity(255);
+ Tweener.removeTweens(clone);
+ clone.set_position(x, y);
+ clone.set_scale(scale, scale);
+ clone.set_opacity(255);
clone.overlay.relayout(false);
this._showWindowOverlay(clone, clone.overlay);
}
@@ -1368,13 +1373,13 @@ var Workspace = class {
clone.setStackAbove(this._dropRect);
} else {
let previousClone = clones[i - 1];
- clone.setStackAbove(previousClone.actor);
+ clone.setStackAbove(previousClone);
}
}
}
_animateClone(clone, overlay, x, y, scale) {
- Tweener.addTween(clone.actor,
+ Tweener.addTween(clone,
{ x: x,
y: y,
scale_x: scale,
@@ -1435,12 +1440,12 @@ var Workspace = class {
// destroyed; we'd like to animate this, but it's too late at
// this point.)
if (win) {
- let [stageX, stageY] = clone.actor.get_transformed_position();
- let [stageWidth, stageHeight] = clone.actor.get_transformed_size();
+ let [stageX, stageY] = clone.get_transformed_position();
+ let [stageWidth, stageHeight] = clone.get_transformed_size();
win._overviewHint = {
x: stageX,
y: stageY,
- scale: stageWidth / clone.actor.width
+ scale: stageWidth / clone.width
};
}
clone.destroy();
@@ -1520,11 +1525,11 @@ var Workspace = class {
let scale = win._overviewHint.scale;
delete win._overviewHint;
- clone.slot = [x, y, clone.actor.width * scale, clone.actor.height * scale];
+ clone.slot = [x, y, clone.width * scale, clone.height * scale];
clone.positioned = true;
- clone.actor.set_position(x, y);
- clone.actor.set_scale(scale, scale);
+ clone.set_position(x, y);
+ clone.set_scale(scale, scale);
clone.overlay.relayout(false);
}
@@ -1621,7 +1626,7 @@ var Workspace = class {
for (let i = 0; i < this._windows.length; i++) {
let clone = this._windows[i];
- Tweener.removeTweens(clone.actor);
+ Tweener.removeTweens(clone);
}
if (this._repositionWindowsId > 0) {
@@ -1680,18 +1685,18 @@ var Workspace = class {
if (clone.metaWindow.showing_on_its_workspace()) {
let [origX, origY] = clone.getOriginalPosition();
- clone.actor.scale_x = 1;
- clone.actor.scale_y = 1;
- clone.actor.x = origX;
- clone.actor.y = origY;
- Tweener.addTween(clone.actor,
+ clone.scale_x = 1;
+ clone.scale_y = 1;
+ clone.x = origX;
+ clone.y = origY;
+ Tweener.addTween(clone,
{ time: time,
opacity: opacity,
transition: 'easeOutQuad'
});
} else {
// The window is hidden
- clone.actor.opacity = 0;
+ clone.opacity = 0;
}
}
@@ -1708,7 +1713,7 @@ var Workspace = class {
for (let i = 0; i < this._windows.length; i++) {
let clone = this._windows[i];
- Tweener.removeTweens(clone.actor);
+ Tweener.removeTweens(clone);
}
if (this._repositionWindowsId > 0) {
@@ -1734,7 +1739,7 @@ var Workspace = class {
if (clone.metaWindow.showing_on_its_workspace()) {
let [origX, origY] = clone.getOriginalPosition();
- Tweener.addTween(clone.actor,
+ Tweener.addTween(clone,
{ x: origX,
y: origY,
scale_x: 1.0,
@@ -1745,7 +1750,7 @@ var Workspace = class {
});
} else {
// The window is hidden, make it shrink and fade it out
- Tweener.addTween(clone.actor,
+ Tweener.addTween(clone,
{ scale_x: 0,
scale_y: 0,
opacity: 0,
@@ -1836,16 +1841,16 @@ var Workspace = class {
clone.connect('size-changed', () => {
this._recalculateWindowPositions(WindowPositionFlags.NONE);
});
- clone.actor.connect('destroy', () => {
+ clone.connect('destroy', () => {
this._removeWindowClone(clone.metaWindow);
});
- this.actor.add_actor(clone.actor);
+ this.actor.add_actor(clone);
overlay.connect('chrome-visible', () => {
let focus = global.stage.key_focus;
if (focus == null || this.actor.contains(focus))
- clone.actor.grab_key_focus();
+ clone.grab_key_focus();
this._windowOverlays.forEach(o => {
if (o != overlay)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]