[gnome-shell/wip/exalm/gestures2: 7/7] workspaceAnimation: Support multiple screens
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/exalm/gestures2: 7/7] workspaceAnimation: Support multiple screens
- Date: Wed, 15 Jul 2020 17:10:03 +0000 (UTC)
commit d7d9c6dc6a5a59740a150c5d5e26b288fa8226f4
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Jun 21 00:43:06 2020 +0500
workspaceAnimation: Support multiple screens
Currently, there's one animation for the whole canvas. While it looks fine
with just one screen, it causes windows to move between screens when
switching workspaces. Instead, have a separate animation on each screen,
and sync their progress so that at any given time the progress "fraction"
is the same between all screens. Clip all animations to their screens so
that the windows don't leak to other screens.
If a window is placed between every screen, can end up in multiple
animations, in that case each part is still animated separately.
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1213
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
js/ui/workspaceAnimation.js | 288 ++++++++++++++++++++++++++++----------------
1 file changed, 185 insertions(+), 103 deletions(-)
---
diff --git a/js/ui/workspaceAnimation.js b/js/ui/workspaceAnimation.js
index 23e5eb0863..9a43ee82f8 100644
--- a/js/ui/workspaceAnimation.js
+++ b/js/ui/workspaceAnimation.js
@@ -4,16 +4,18 @@
const { Clutter, GObject, Meta, Shell } = imports.gi;
const Main = imports.ui.main;
+const Layout = imports.ui.layout;
const SwipeTracker = imports.ui.swipeTracker;
const WINDOW_ANIMATION_TIME = 250;
const WorkspaceGroup = GObject.registerClass(
class WorkspaceGroup extends Clutter.Actor {
- _init(workspace, movingWindow) {
+ _init(workspace, monitor, movingWindow) {
super._init();
this._workspace = workspace;
+ this._monitor = monitor;
this._movingWindow = movingWindow;
this._windowRecords = [];
@@ -28,6 +30,11 @@ class WorkspaceGroup extends Clutter.Actor {
if (!window.showing_on_its_workspace())
return false;
+ const geometry = global.display.get_monitor_geometry(this._monitor.index);
+ const [intersects, intersection_] = window.get_frame_rect().intersect(geometry);
+ if (!intersects)
+ return false;
+
const isSticky =
window.is_on_all_workspaces() || window === this._movingWindow;
@@ -65,8 +72,8 @@ class WorkspaceGroup extends Clutter.Actor {
for (const windowActor of windowActors) {
const clone = new Clutter.Clone({
source: windowActor,
- x: windowActor.x,
- y: windowActor.y,
+ x: windowActor.x - this._monitor.x,
+ y: windowActor.y - this._monitor.y,
});
this.add_child(clone);
@@ -141,19 +148,11 @@ var WorkspaceAnimationController = class {
const switchData = {};
this._switchData = switchData;
- switchData.stickyGroup = new WorkspaceGroup(null, this.movingWindow);
- switchData.workspaces = [];
+ switchData.monitors = {};
+
switchData.gestureActivated = false;
switchData.inProgress = false;
- switchData.container = new Clutter.Actor();
-
- wgroup.add_child(switchData.stickyGroup);
- wgroup.add_child(switchData.container);
-
- let x = 0;
- let y = 0;
-
if (!workspaces) {
workspaces = [];
@@ -161,58 +160,91 @@ var WorkspaceAnimationController = class {
workspaces.push(i);
}
- for (const i of workspaces) {
- const ws = workspaceManager.get_workspace_by_index(i);
- const fullscreen = ws.list_windows().some(w => w.is_fullscreen());
+ for (const monitor of Main.layoutManager.monitors) {
+ if (Meta.prefs_get_workspaces_only_on_primary() &&
+ monitor.index !== Main.layoutManager.primaryIndex)
+ continue;
+
+ const record = {
+ index: monitor.index,
+ actor: new Clutter.Actor({
+ x_expand: true,
+ y_expand: true,
+ clip_to_allocation: true,
+ }),
+ container: new Clutter.Actor(),
+ stickyGroup: new WorkspaceGroup(null, monitor, this.movingWindow),
+ workspaces: [],
+ };
- if (y > 0 && vertical && !fullscreen) {
- // We have to shift windows up or down by the height of the panel to prevent having a
- // visible gap between the windows while switching workspaces. Since fullscreen windows
- // hide the panel, they don't need to be shifted up or down.
- y -= Main.panel.height;
+ const constraint = new Layout.MonitorConstraint({ index: monitor.index });
+ record.actor.add_constraint(constraint);
+
+ record.actor.add_child(record.container);
+ record.actor.add_child(record.stickyGroup);
+
+ wgroup.add_child(record.actor);
+
+ let x = 0;
+ let y = 0;
+
+ for (const i of workspaces) {
+ const ws = workspaceManager.get_workspace_by_index(i);
+ const fullscreen = ws.list_windows().some(w => w.get_monitor() === record.index &&
w.is_fullscreen());
+
+ if (i > 0 && vertical && !fullscreen && record.index === Main.layoutManager.primaryIndex) {
+ // We have to shift windows up or down by the height of the panel to prevent having a
+ // visible gap between the windows while switching workspaces. Since fullscreen windows
+ // hide the panel, they don't need to be shifted up or down.
+ y -= Main.panel.height;
+ }
+
+ const info = {
+ ws,
+ actor: new WorkspaceGroup(ws, monitor, this.movingWindow),
+ fullscreen,
+ x,
+ y,
+ };
+
+ record.workspaces[i] = info;
+ record.container.add_child(info.actor);
+ record.container.set_child_above_sibling(info.actor, null);
+ info.actor.set_position(x, y);
+
+ if (vertical)
+ y += monitor.height;
+ else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
+ x -= monitor.width;
+ else
+ x += monitor.width;
}
- const info = {
- ws,
- actor: new WorkspaceGroup(ws, this.movingWindow),
- fullscreen,
- x,
- y,
- };
+ record.actor.set_child_above_sibling(record.stickyGroup, null);
- switchData.workspaces[i] = info;
- switchData.container.add_child(info.actor);
- switchData.container.set_child_above_sibling(info.actor, null);
- info.actor.set_position(x, y);
+ switchData.monitors[monitor.index] = record;
if (vertical)
- y += global.screen_height;
- else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
- x -= global.screen_width;
+ record.container.y = -record.workspaces[activeWorkspaceIndex].y;
else
- x += global.screen_width;
+ record.container.x = -record.workspaces[activeWorkspaceIndex].x;
}
-
- if (vertical)
- switchData.container.y = -switchData.workspaces[activeWorkspaceIndex].y;
- else
- switchData.container.x = -switchData.workspaces[activeWorkspaceIndex].x;
-
- wgroup.set_child_above_sibling(switchData.stickyGroup, null);
}
_finishWorkspaceSwitch(switchData) {
this._switchData = null;
- switchData.container.destroy();
- switchData.stickyGroup.destroy();
+ for (const monitorInfo of Object.values(switchData.monitors))
+ monitorInfo.actor.destroy();
this.movingWindow = null;
}
animateSwitch(from, to, direction, onComplete) {
- if (this._switchData)
- this._switchData.container.remove_all_transitions();
+ if (this._switchData) {
+ for (const monitorInfo of Object.values(this._switchData.monitors))
+ monitorInfo.container.remove_all_transitions();
+ }
let workspaces = [];
@@ -240,40 +272,49 @@ var WorkspaceAnimationController = class {
this._prepareWorkspaceSwitch(workspaces);
this._switchData.inProgress = true;
- const fromWs = this._switchData.workspaces[from];
- const toWs = this._switchData.workspaces[to];
-
- this._switchData.container.x = -fromWs.x;
- this._switchData.container.y = -fromWs.y;
-
- this._switchData.container.ease({
- x: -toWs.x,
- y: -toWs.y,
- duration: WINDOW_ANIMATION_TIME,
- mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
- onComplete: () => {
- this._finishWorkspaceSwitch(this._switchData);
- onComplete();
- },
- });
+ for (const monitorInfo of Object.values(this._switchData.monitors)) {
+ const fromWs = monitorInfo.workspaces[from];
+ const toWs = monitorInfo.workspaces[to];
+
+ monitorInfo.container.x = -fromWs.x;
+ monitorInfo.container.y = -fromWs.y;
+
+ const params = {
+ x: -toWs.x,
+ y: -toWs.y,
+ duration: WINDOW_ANIMATION_TIME,
+ mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
+ };
+
+ if (monitorInfo.index === Main.layoutManager.primaryIndex) {
+ params.onComplete = () => {
+ this._finishWorkspaceSwitch(this._switchData);
+ onComplete();
+ };
+ }
+
+ monitorInfo.container.ease(params);
+ }
}
- _getProgressForWorkspace(workspaceInfo) {
+ _getProgressForWorkspace(workspaceInfo, monitorIndex) {
+ const geometry = Main.layoutManager.monitors[monitorIndex];
+
if (global.workspace_manager.layout_rows === -1)
- return workspaceInfo.y / global.screen_height;
+ return workspaceInfo.y / geometry.height;
else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
- return -workspaceInfo.x / global.screen_width;
+ return -workspaceInfo.x / geometry.width;
else
- return workspaceInfo.x / global.screen_width;
+ return workspaceInfo.x / geometry.width;
}
- _findClosestWorkspace(progress) {
- const distances = this._switchData.workspaces.map(ws => {
- const workspaceProgress = this._getProgressForWorkspace(ws);
+ _findClosestWorkspaceIndex(progress) {
+ const index = Main.layoutManager.primaryIndex;
+ const distances = this._switchData.monitors[index].workspaces.map(ws => {
+ const workspaceProgress = this._getProgressForWorkspace(ws, index);
return Math.abs(workspaceProgress - progress);
});
- const index = distances.indexOf(Math.min(...distances));
- return this._switchData.workspaces[index];
+ return distances.indexOf(Math.min(...distances));
}
_switchWorkspaceBegin(tracker, monitor) {
@@ -287,72 +328,113 @@ var WorkspaceAnimationController = class {
? Clutter.Orientation.HORIZONTAL
: Clutter.Orientation.VERTICAL;
- const baseDistance = horiz ? global.screen_width : global.screen_height;
+ const geometry = Main.layoutManager.monitors[monitor];
+ const baseDistance = horiz ? geometry.width : geometry.height;
let progress;
let cancelProgress;
if (this._switchData && this._switchData.gestureActivated) {
- this._switchData.container.remove_all_transitions();
+ for (const monitorInfo of Object.values(this._switchData.monitors))
+ monitorInfo.container.remove_all_transitions();
+
+ const record = this._switchData.monitors[monitor];
+
if (!horiz)
- progress = -this._switchData.container.y / baseDistance;
+ progress = -record.container.y / baseDistance;
else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
- progress = this._switchData.container.x / baseDistance;
+ progress = record.container.x / baseDistance;
else
- progress = -this._switchData.container.x / baseDistance;
+ progress = -record.container.x / baseDistance;
- const ws = this._findClosestWorkspace(progress);
- cancelProgress = this._getProgressForWorkspace(ws);
+ const ws = record.workspaces[this._findClosestWorkspaceIndex(progress)];
+ cancelProgress = this._getProgressForWorkspace(ws, monitor);
} else {
this._prepareWorkspaceSwitch();
const activeIndex = workspaceManager.get_active_workspace_index();
- const ws = this._switchData.workspaces[activeIndex];
+ const ws = this._switchData.monitors[monitor].workspaces[activeIndex];
- progress = cancelProgress = this._getProgressForWorkspace(ws);
+ progress = cancelProgress = this._getProgressForWorkspace(ws, monitor);
}
- const points = this._switchData.workspaces.map(this._getProgressForWorkspace);
+ const points = this._switchData.monitors[monitor].workspaces.map(ws =>
this._getProgressForWorkspace(ws, monitor));
+
+ this._switchData.baseMonitor = monitor;
tracker.confirmSwipe(baseDistance, points, progress, cancelProgress);
}
+ _interpolateProgress(progress, monitor) {
+ const monitor1 = this._switchData.monitors[this._switchData.baseMonitor];
+ const monitor2 = monitor;
+
+ const points1 = monitor1.workspaces.map(ws => this._getProgressForWorkspace(ws, monitor1.index));
+ const points2 = monitor2.workspaces.map(ws => this._getProgressForWorkspace(ws, monitor2.index));
+
+ const upper = points1.indexOf(points1.find(p => p >= progress));
+ const lower = points1.indexOf(points1.slice().reverse().find(p => p <= progress));
+
+ if (points1[upper] === points1[lower])
+ return points2[upper];
+
+ const t = (progress - points1[lower]) / (points1[upper] - points1[lower]);
+
+ return points2[lower] + (points2[upper] - points2[lower]) * t;
+ }
+
_switchWorkspaceUpdate(tracker, progress) {
if (!this._switchData)
return;
- let xPos = 0;
- let yPos = 0;
+ for (const monitorInfo of Object.values(this._switchData.monitors)) {
+ let xPos = 0;
+ let yPos = 0;
- if (global.workspace_manager.layout_rows === -1)
- yPos = -Math.round(progress * global.screen_height);
- else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
- xPos = Math.round(progress * global.screen_width);
- else
- xPos = -Math.round(progress * global.screen_width);
+ const geometry = Main.layoutManager.monitors[monitorInfo.index];
+
+ const p = this._interpolateProgress(progress, monitorInfo);
- this._switchData.container.set_position(xPos, yPos);
+ if (global.workspace_manager.layout_rows === -1)
+ yPos = -Math.round(p * geometry.height);
+ else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
+ xPos = Math.round(p * geometry.width);
+ else
+ xPos = -Math.round(p * geometry.width);
+
+ monitorInfo.container.set_position(xPos, yPos);
+ }
}
_switchWorkspaceEnd(tracker, duration, endProgress) {
if (!this._switchData)
return;
- const newWs = this._findClosestWorkspace(endProgress);
const switchData = this._switchData;
switchData.gestureActivated = true;
- this._switchData.container.ease({
- x: -newWs.x,
- y: -newWs.y,
- duration,
- mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
- onComplete: () => {
- if (!newWs.ws.active)
- newWs.ws.activate(global.get_current_time());
- this._finishWorkspaceSwitch(switchData);
- },
- });
+ const index = this._findClosestWorkspaceIndex(endProgress);
+
+ for (const monitorInfo of Object.values(this._switchData.monitors)) {
+ const newWs = monitorInfo.workspaces[index];
+
+ const params = {
+ x: -newWs.x,
+ y: -newWs.y,
+ duration,
+ mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
+ };
+
+ if (monitorInfo.index === Main.layoutManager.primaryIndex) {
+ params.onComplete = () => {
+ if (!newWs.ws.active)
+ newWs.ws.activate(global.get_current_time());
+ this._finishWorkspaceSwitch(switchData);
+ };
+ }
+
+ monitorInfo.container.ease(params);
+ }
}
get gestureActive() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]