[gnome-shell/wip/exalm/gestures2: 6/12] workspaceAnimation: Extract WorkspaceGroup
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/exalm/gestures2: 6/12] workspaceAnimation: Extract WorkspaceGroup
- Date: Fri, 17 Jul 2020 12:13:27 +0000 (UTC)
commit de84422783aee694fa8258d0b6430eae19876636
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Thu Jul 4 22:44:15 2019 +0500
workspaceAnimation: Extract WorkspaceGroup
Simplify the code a bit. The workspace group is relatively self-contained,
so split it from the general animation. Reimplement _syncStacking().
This will help a lot later, with workspace strip and multi-monitor support.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
js/ui/workspaceAnimation.js | 184 ++++++++++++++++++++++++--------------------
1 file changed, 102 insertions(+), 82 deletions(-)
---
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index 89130c8bcf..770d5f229d 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -1,20 +1,102 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported WorkspaceAnimationController */
-const { Clutter, Meta, Shell } = imports.gi;
+const { Clutter, GObject, Meta, Shell } = imports.gi;
const Main = imports.ui.main;
const SwipeTracker = imports.ui.swipeTracker;
const WINDOW_ANIMATION_TIME = 250;
+const WorkspaceGroup = GObject.registerClass(
+class WorkspaceGroup extends Clutter.Actor {
+ _init(workspace, movingWindow) {
+ super._init();
+
+ this._workspace = workspace;
+ this._movingWindow = movingWindow;
+ this._windowRecords = [];
+
+ this._createWindows();
+
+ this.connect('destroy', this._onDestroy.bind(this));
+ this._restackedId = global.display.connect('restacked',
+ this._syncStacking.bind(this));
+ }
+
+ _shouldShowWindow(window) {
+ if (!window.showing_on_its_workspace())
+ return false;
+
+ const isSticky =
+ window.is_on_all_workspaces() || window === this._movingWindow;
+
+ // No workspace means we should show windows that are on all workspaces
+ if (!this._workspace)
+ return isSticky;
+
+ // Otherwise only show windows that are (only) on that workspace
+ return !isSticky && window.located_on_workspace(this._workspace);
+ }
+
+ _syncStacking() {
+ const windowActors = global.get_window_actors();
+ let lastSibling = null;
+
+ for (const windowActor of windowActors) {
+ this.set_child_above_sibling(windowActor, lastSibling);
+ lastSibling = windowActor;
+ }
+ }
+
+ _createWindows() {
+ const windowActors = global.get_window_actors().filter(w =>
+ this._shouldShowWindow(w.meta_window));
+
+ for (const windowActor of windowActors) {
+ const record = {
+ windowActor,
+ parent: windowActor.get_parent(),
+ };
+
+ record.parent.remove_child(windowActor);
+ this.add_child(windowActor);
+ windowActor.show();
+
+ record.windowDestroyId = windowActor.connect('destroy', () => {
+ this._windowRecords.splice(this._windowRecords.indexOf(record), 1);
+ });
+
+ this._windowRecords.push(record);
+ }
+ }
+
+ _removeWindows() {
+ for (const record of this._windowRecords) {
+ record.windowActor.disconnect(record.windowDestroyId);
+ this.remove_child(record.windowActor);
+ record.parent.add_child(record.windowActor);
+
+ // No workspace means we showed sticky windows,
+ // don't hide anything in this case
+ if (this._workspace && !this._workspace.active)
+ record.windowActor.hide();
+ }
+
+ this._windowRecords = [];
+ }
+
+ _onDestroy() {
+ global.display.disconnect(this._restackedId);
+ this._removeWindows();
+ }
+});
+
var WorkspaceAnimationController = class {
constructor() {
this._movingWindow = null;
this._switchData = null;
- global.display.connect('restacked', this._syncStacking.bind(this));
-
Main.overview.connect('showing', () => {
if (this._switchData) {
if (this._switchData.gestureActivated)
@@ -34,35 +116,6 @@ var WorkspaceAnimationController = class {
this._swipeTracker = swipeTracker;
}
- _syncStacking() {
- if (this._switchData === null)
- return;
-
- const windows = global.get_window_actors();
- let lastCurSibling = null;
- const lastDirSibling = [];
- for (let i = 0; i < windows.length; i++) {
- if (windows[i].get_parent() === this._switchData.curGroup) {
- this._switchData.curGroup.set_child_above_sibling(windows[i], lastCurSibling);
- lastCurSibling = windows[i];
- } else {
- for (const dir of Object.values(Meta.MotionDirection)) {
- const info = this._switchData.surroundings[dir];
- if (!info || windows[i].get_parent() !== info.actor)
- continue;
-
- let sibling = lastDirSibling[dir];
- if (sibling === undefined)
- sibling = null;
-
- info.actor.set_child_above_sibling(windows[i], sibling);
- lastDirSibling[dir] = windows[i];
- break;
- }
- }
- }
- }
-
_getPositionForDirection(direction, fromWs, toWs) {
let xDest = 0, yDest = 0;
@@ -100,13 +153,15 @@ var WorkspaceAnimationController = class {
return;
const wgroup = global.window_group;
- const windows = global.get_window_actors();
+ const workspaceManager = global.workspace_manager;
+ const curWs = workspaceManager.get_workspace_by_index(from);
+
const switchData = {};
this._switchData = switchData;
- switchData.curGroup = new Clutter.Actor();
+ switchData.curGroup = new WorkspaceGroup(curWs, this.movingWindow);
switchData.movingWindowBin = new Clutter.Actor();
- switchData.windows = [];
+ switchData.movingWindow = null;
switchData.surroundings = {};
switchData.gestureActivated = false;
switchData.inProgress = false;
@@ -117,9 +172,6 @@ var WorkspaceAnimationController = class {
wgroup.add_child(switchData.movingWindowBin);
wgroup.add_child(switchData.container);
- const workspaceManager = global.workspace_manager;
- const curWs = workspaceManager.get_workspace_by_index(from);
-
for (const dir of Object.values(Meta.MotionDirection)) {
let ws = null;
@@ -136,7 +188,7 @@ var WorkspaceAnimationController = class {
const [x, y] = this._getPositionForDirection(dir, curWs, ws);
const info = {
index: ws.index(),
- actor: new Clutter.Actor(),
+ actor: new WorkspaceGroup(ws, this.movingWindow),
xDest: x,
yDest: y,
};
@@ -149,51 +201,18 @@ var WorkspaceAnimationController = class {
wgroup.set_child_above_sibling(switchData.movingWindowBin, null);
- for (const windowActor of windows) {
- const window = windowActor.get_meta_window();
-
- if (!window.showing_on_its_workspace())
- continue;
+ if (this.movingWindow) {
+ const windowActor = this.movingWindow.get_compositor_private();
- if (window.is_on_all_workspaces())
- continue;
-
- const record = {
+ switchData.movingWindow = {
windowActor,
parent: windowActor.get_parent(),
};
- if (this.movingWindow && window === this.movingWindow) {
- record.parent.remove_child(windowActor);
- switchData.movingWindow = record;
- switchData.windows.push(switchData.movingWindow);
- switchData.movingWindowBin.add_child(windowActor);
- } else if (window.get_workspace().index() === from) {
- record.parent.remove_child(windowActor);
- switchData.windows.push(record);
- switchData.curGroup.add_child(windowActor);
- } else {
- let visible = false;
- for (const dir of Object.values(Meta.MotionDirection)) {
- const info = switchData.surroundings[dir];
-
- if (!info || info.index !== window.get_workspace().index())
- continue;
-
- record.parent.remove_child(windowActor);
- switchData.windows.push(record);
- info.actor.add_child(windowActor);
- visible = true;
- break;
- }
-
- windowActor.visible = visible;
- }
- }
-
- for (const record of switchData.windows) {
- record.windowDestroyId = record.windowActor.connect('destroy', () => {
- switchData.windows.splice(switchData.windows.indexOf(record), 1);
+ switchData.movingWindow.parent.remove_child(windowActor);
+ switchData.movingWindowBin.add_child(windowActor);
+ switchData.movingWindow.windowDestroyId = windowActor.connect('destroy', () => {
+ switchData.movingWindow = null;
});
}
}
@@ -201,14 +220,15 @@ var WorkspaceAnimationController = class {
_finishWorkspaceSwitch(switchData) {
this._switchData = null;
- for (const record of switchData.windows) {
+ if (switchData.movingWindow) {
+ const record = switchData.movingWindow;
record.windowActor.disconnect(record.windowDestroyId);
switchData.movingWindowBin.remove_child(record.windowActor);
record.parent.add_child(record.windowActor);
- if (!record.windowActor.get_meta_window().get_workspace().active)
- record.windowActor.hide();
+ switchData.movingWindow = null;
}
+
switchData.container.destroy();
switchData.movingWindowBin.destroy();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]