Compare commits

...

9 Commits

Author SHA1 Message Date
Alexander Mikhaylenko
c3aa25e4e3 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
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
cfd792fe86 workspaceAnimation: Group sticky windows and moving window
Since the transitions consists of window clones now, all the clones appear
above sticky windows. Clone sticky windows as well, and treat them same as
moving window instead.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
7bdcc503cb workspaceAnimation: Use a workspace strip
Currently, the workspace swipe transition only has one workspace in each
direction. This works until you try to do multiple swipes in quick
succession. The second swipe would continue the existing transition, which
only has 2 or 3 workspaces in it, and will hit a wall.

To prevent this, take all workspaces and arrange them into a column or row,
depending on the layout, and use that as a transition.

For the transition that happens when focusing a window on another workspace
(for example, via Alt+Tab), still use only two workspaces instead of all of
them.

Since we don't support layouts other than single rows/columns anymore,
diagonal transitions aren't supported anymore, and will be shown as
horizontal or vertical instead.

Since nw alt-tab and gesture transitions are different, don't allow to do
both at once, that is, disable swipe tracker when a programmatic transition
is going. This will also conveniently cancel a gesture transition if a
programmatic one is initiated while a gesture is in progress.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2612

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
856a4d27e0 workspaceAnimation: Use window clones
Instead of reparenting windows, clone them. This will allow to properly
support multi-monitor setups in subsequent commits.

Block window mapping animation while the animation is running to prevent
new windows appearing during the animation from being visible at the same
time as their clones.

Fixes https://gitlab.gnome.org/GNOME/mutter/issues/929

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
9d1fe27221 workspaceAnimation: Add a background
In future we will need to use window clones to better support multiple
monitors. To avoid having to hide every window, show wallpapers behind
the workspace transition: one per monitor.

Put the wallpaper into a separate class right away, later it will be
useful to make the animation per-monitor.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
407abeb178 workspaceAnimation: Add to uiGroup insead of window_group
This will allow to hide window group completely in the following commits.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
95fc8021d2 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
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
060cbb65f6 workspaceAnimation: Stop depending on shellwm
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:46 +00:00
Alexander Mikhaylenko
1759e27ef7 workspaceAnimation: Split from WindowManager
It's already too complex, and will get more complex in future, split it
out. Update the code style.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1326
2020-07-21 12:51:45 +00:00
3 changed files with 495 additions and 387 deletions

View File

@ -112,6 +112,7 @@
<file>ui/windowManager.js</file> <file>ui/windowManager.js</file>
<file>ui/windowPreview.js</file> <file>ui/windowPreview.js</file>
<file>ui/workspace.js</file> <file>ui/workspace.js</file>
<file>ui/workspaceAnimation.js</file>
<file>ui/workspaceSwitcherPopup.js</file> <file>ui/workspaceSwitcherPopup.js</file>
<file>ui/workspaceThumbnail.js</file> <file>ui/workspaceThumbnail.js</file>
<file>ui/workspacesView.js</file> <file>ui/workspacesView.js</file>

View File

@ -14,9 +14,9 @@ const WindowMenu = imports.ui.windowMenu;
const PadOsd = imports.ui.padOsd; const PadOsd = imports.ui.padOsd;
const EdgeDragAction = imports.ui.edgeDragAction; const EdgeDragAction = imports.ui.edgeDragAction;
const CloseDialog = imports.ui.closeDialog; const CloseDialog = imports.ui.closeDialog;
const SwipeTracker = imports.ui.swipeTracker;
const SwitchMonitor = imports.ui.switchMonitor; const SwitchMonitor = imports.ui.switchMonitor;
const IBusManager = imports.misc.ibusManager; const IBusManager = imports.misc.ibusManager;
const WorkspaceAnimation = imports.ui.workspaceAnimation;
const { loadInterfaceXML } = imports.misc.fileUtils; const { loadInterfaceXML } = imports.misc.fileUtils;
@ -561,7 +561,6 @@ var WindowManager = class {
this._resizing = new Set(); this._resizing = new Set();
this._resizePending = new Set(); this._resizePending = new Set();
this._destroying = new Set(); this._destroying = new Set();
this._movingWindow = null;
this._dimmedWindows = []; this._dimmedWindows = [];
@ -571,15 +570,6 @@ var WindowManager = class {
this._isWorkspacePrepended = false; this._isWorkspacePrepended = false;
this._switchData = null;
this._shellwm.connect('kill-switch-workspace', shellwm => {
if (this._switchData) {
if (this._switchData.inProgress)
this._switchWorkspaceDone(shellwm);
else if (!this._switchData.gestureActivated)
this._finishWorkspaceSwitch(this._switchData);
}
});
this._shellwm.connect('kill-window-effects', (shellwm, actor) => { this._shellwm.connect('kill-window-effects', (shellwm, actor) => {
this._minimizeWindowDone(shellwm, actor); this._minimizeWindowDone(shellwm, actor);
this._mapWindowDone(shellwm, actor); this._mapWindowDone(shellwm, actor);
@ -601,7 +591,6 @@ var WindowManager = class {
this._shellwm.connect('confirm-display-change', this._confirmDisplayChange.bind(this)); this._shellwm.connect('confirm-display-change', this._confirmDisplayChange.bind(this));
this._shellwm.connect('create-close-dialog', this._createCloseDialog.bind(this)); this._shellwm.connect('create-close-dialog', this._createCloseDialog.bind(this));
this._shellwm.connect('create-inhibit-shortcuts-dialog', this._createInhibitShortcutsDialog.bind(this)); this._shellwm.connect('create-inhibit-shortcuts-dialog', this._createInhibitShortcutsDialog.bind(this));
global.display.connect('restacked', this._syncStacking.bind(this));
this._workspaceSwitcherPopup = null; this._workspaceSwitcherPopup = null;
this._tilePreview = null; this._tilePreview = null;
@ -947,17 +936,10 @@ var WindowManager = class {
Main.overview.connect('showing', () => { Main.overview.connect('showing', () => {
for (let i = 0; i < this._dimmedWindows.length; i++) for (let i = 0; i < this._dimmedWindows.length; i++)
this._undimWindow(this._dimmedWindows[i]); this._undimWindow(this._dimmedWindows[i]);
if (this._switchData) {
if (this._switchData.gestureActivated)
this._switchWorkspaceStop();
this._swipeTracker.enabled = false;
}
}); });
Main.overview.connect('hiding', () => { Main.overview.connect('hiding', () => {
for (let i = 0; i < this._dimmedWindows.length; i++) for (let i = 0; i < this._dimmedWindows.length; i++)
this._dimWindow(this._dimmedWindows[i]); this._dimWindow(this._dimmedWindows[i]);
this._swipeTracker.enabled = true;
}); });
this._windowMenuManager = new WindowMenu.WindowMenuManager(); this._windowMenuManager = new WindowMenu.WindowMenuManager();
@ -968,13 +950,6 @@ var WindowManager = class {
global.workspace_manager.override_workspace_layout(Meta.DisplayCorner.TOPLEFT, global.workspace_manager.override_workspace_layout(Meta.DisplayCorner.TOPLEFT,
false, -1, 1); false, -1, 1);
let swipeTracker = new SwipeTracker.SwipeTracker(global.stage,
Shell.ActionMode.NORMAL, { allowDrag: false, allowScroll: false });
swipeTracker.connect('begin', this._switchWorkspaceBegin.bind(this));
swipeTracker.connect('update', this._switchWorkspaceUpdate.bind(this));
swipeTracker.connect('end', this._switchWorkspaceEnd.bind(this));
this._swipeTracker = swipeTracker;
let appSwitchAction = new AppSwitchAction(); let appSwitchAction = new AppSwitchAction();
appSwitchAction.connect('activated', this._switchApp.bind(this)); appSwitchAction.connect('activated', this._switchApp.bind(this));
global.stage.add_action(appSwitchAction); global.stage.add_action(appSwitchAction);
@ -1006,6 +981,14 @@ var WindowManager = class {
global.display.connect('in-fullscreen-changed', updateUnfullscreenGesture); global.display.connect('in-fullscreen-changed', updateUnfullscreenGesture);
global.stage.add_action(topDragAction); global.stage.add_action(topDragAction);
this._workspaceAnimation =
new WorkspaceAnimation.WorkspaceAnimationController();
this._shellwm.connect('kill-switch-workspace', () => {
this._workspaceAnimation.cancelSwitchAnimation();
this._switchWorkspaceDone();
});
} }
_showPadOsd(display, device, settings, imagePath, editionMode, monitorIndex) { _showPadOsd(display, device, settings, imagePath, editionMode, monitorIndex) {
@ -1128,8 +1111,7 @@ var WindowManager = class {
} }
_shouldAnimate() { _shouldAnimate() {
return !(Main.overview.visible || return !(Main.overview.visible || this._workspaceAnimation.gestureActive);
(this._switchData && this._switchData.gestureActivated));
} }
_shouldAnimateActor(actor, types) { _shouldAnimateActor(actor, types) {
@ -1625,376 +1607,26 @@ var WindowManager = class {
return !(this._allowedKeybindings[binding.get_name()] & Main.actionMode); return !(this._allowedKeybindings[binding.get_name()] & Main.actionMode);
} }
_syncStacking() {
if (this._switchData == null)
return;
let windows = global.get_window_actors();
let lastCurSibling = null;
let 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 (let dir of Object.values(Meta.MotionDirection)) {
let 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;
let oldWsIsFullscreen = fromWs.list_windows().some(w => w.is_fullscreen());
let newWsIsFullscreen = toWs.list_windows().some(w => w.is_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.
let shiftHeight = Main.panel.height;
if (direction == Meta.MotionDirection.UP ||
direction == Meta.MotionDirection.UP_LEFT ||
direction == Meta.MotionDirection.UP_RIGHT)
yDest = -global.screen_height + (oldWsIsFullscreen ? 0 : shiftHeight);
else if (direction == Meta.MotionDirection.DOWN ||
direction == Meta.MotionDirection.DOWN_LEFT ||
direction == Meta.MotionDirection.DOWN_RIGHT)
yDest = global.screen_height - (newWsIsFullscreen ? 0 : shiftHeight);
if (direction == Meta.MotionDirection.LEFT ||
direction == Meta.MotionDirection.UP_LEFT ||
direction == Meta.MotionDirection.DOWN_LEFT)
xDest = -global.screen_width;
else if (direction == Meta.MotionDirection.RIGHT ||
direction == Meta.MotionDirection.UP_RIGHT ||
direction == Meta.MotionDirection.DOWN_RIGHT)
xDest = global.screen_width;
return [xDest, yDest];
}
_prepareWorkspaceSwitch(from, to, direction) {
if (this._switchData)
return;
let wgroup = global.window_group;
let windows = global.get_window_actors();
let switchData = {};
this._switchData = switchData;
switchData.curGroup = new Clutter.Actor();
switchData.movingWindowBin = new Clutter.Actor();
switchData.windows = [];
switchData.surroundings = {};
switchData.gestureActivated = false;
switchData.inProgress = false;
switchData.container = new Clutter.Actor();
switchData.container.add_actor(switchData.curGroup);
wgroup.add_actor(switchData.movingWindowBin);
wgroup.add_actor(switchData.container);
let workspaceManager = global.workspace_manager;
let curWs = workspaceManager.get_workspace_by_index(from);
for (let dir of Object.values(Meta.MotionDirection)) {
let ws = null;
if (to < 0)
ws = curWs.get_neighbor(dir);
else if (dir == direction)
ws = workspaceManager.get_workspace_by_index(to);
if (ws == null || ws == curWs) {
switchData.surroundings[dir] = null;
continue;
}
let [x, y] = this._getPositionForDirection(dir, curWs, ws);
let info = {
index: ws.index(),
actor: new Clutter.Actor(),
xDest: x,
yDest: y,
};
switchData.surroundings[dir] = info;
switchData.container.add_actor(info.actor);
switchData.container.set_child_above_sibling(info.actor, null);
info.actor.set_position(x, y);
}
wgroup.set_child_above_sibling(switchData.movingWindowBin, null);
for (let i = 0; i < windows.length; i++) {
let actor = windows[i];
let window = actor.get_meta_window();
if (!window.showing_on_its_workspace())
continue;
if (window.is_on_all_workspaces())
continue;
let record = { window: actor,
parent: actor.get_parent() };
if (this._movingWindow && window == this._movingWindow) {
record.parent.remove_child(actor);
switchData.movingWindow = record;
switchData.windows.push(switchData.movingWindow);
switchData.movingWindowBin.add_child(actor);
} else if (window.get_workspace().index() == from) {
record.parent.remove_child(actor);
switchData.windows.push(record);
switchData.curGroup.add_child(actor);
} else {
let visible = false;
for (let dir of Object.values(Meta.MotionDirection)) {
let info = switchData.surroundings[dir];
if (!info || info.index != window.get_workspace().index())
continue;
record.parent.remove_child(actor);
switchData.windows.push(record);
info.actor.add_child(actor);
visible = true;
break;
}
actor.visible = visible;
}
}
for (let i = 0; i < switchData.windows.length; i++) {
let w = switchData.windows[i];
w.windowDestroyId = w.window.connect('destroy', () => {
switchData.windows.splice(switchData.windows.indexOf(w), 1);
});
}
}
_finishWorkspaceSwitch(switchData) {
this._switchData = null;
for (let i = 0; i < switchData.windows.length; i++) {
let w = switchData.windows[i];
w.window.disconnect(w.windowDestroyId);
w.window.get_parent().remove_child(w.window);
w.parent.add_child(w.window);
if (!w.window.get_meta_window().get_workspace().active)
w.window.hide();
}
switchData.container.destroy();
switchData.movingWindowBin.destroy();
this._movingWindow = null;
}
_switchWorkspace(shellwm, from, to, direction) { _switchWorkspace(shellwm, from, to, direction) {
if (!Main.sessionMode.hasWorkspaces || !this._shouldAnimate()) { if (!Main.sessionMode.hasWorkspaces || !this._shouldAnimate()) {
shellwm.completed_switch_workspace(); shellwm.completed_switch_workspace();
return; return;
} }
this._prepareWorkspaceSwitch(from, to, direction); this._switchInProgress = true;
this._switchData.inProgress = true;
let workspaceManager = global.workspace_manager; this._workspaceAnimation.animateSwitch(from, to, direction, () => {
let fromWs = workspaceManager.get_workspace_by_index(from); this._shellwm.completed_switch_workspace();
let toWs = workspaceManager.get_workspace_by_index(to); this._switchInProgress = false;
let [xDest, yDest] = this._getPositionForDirection(direction, fromWs, toWs);
/* @direction is the direction that the "camera" moves, so the
* screen contents have to move one screen's worth in the
* opposite direction.
*/
xDest = -xDest;
yDest = -yDest;
this._switchData.container.ease({
x: xDest,
y: yDest,
duration: WINDOW_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
onComplete: () => this._switchWorkspaceDone(shellwm),
}); });
} }
_switchWorkspaceDone(shellwm) { _switchWorkspaceDone() {
this._finishWorkspaceSwitch(this._switchData); if (!this._switchInProgress)
shellwm.completed_switch_workspace();
}
_directionForProgress(progress) {
if (global.workspace_manager.layout_rows === -1) {
return progress > 0
? Meta.MotionDirection.DOWN
: Meta.MotionDirection.UP;
} else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL) {
return progress > 0
? Meta.MotionDirection.LEFT
: Meta.MotionDirection.RIGHT;
} else {
return progress > 0
? Meta.MotionDirection.RIGHT
: Meta.MotionDirection.LEFT;
}
}
_getProgressRange() {
if (!this._switchData)
return [0, 0];
let lower = 0;
let upper = 0;
let horiz = global.workspace_manager.layout_rows !== -1;
let baseDistance;
if (horiz)
baseDistance = global.screen_width;
else
baseDistance = global.screen_height;
let direction = this._directionForProgress(-1);
let info = this._switchData.surroundings[direction];
if (info !== null) {
let distance = horiz ? info.xDest : info.yDest;
lower = -Math.abs(distance) / baseDistance;
}
direction = this._directionForProgress(1);
info = this._switchData.surroundings[direction];
if (info !== null) {
let distance = horiz ? info.xDest : info.yDest;
upper = Math.abs(distance) / baseDistance;
}
return [lower, upper];
}
_switchWorkspaceBegin(tracker, monitor) {
if (Meta.prefs_get_workspaces_only_on_primary() &&
monitor !== Main.layoutManager.primaryIndex)
return; return;
let workspaceManager = global.workspace_manager; this._shellwm.completed_switch_workspace();
let horiz = workspaceManager.layout_rows !== -1; this._switchInProgress = false;
tracker.orientation = horiz
? Clutter.Orientation.HORIZONTAL
: Clutter.Orientation.VERTICAL;
let activeWorkspace = workspaceManager.get_active_workspace();
let baseDistance;
if (horiz)
baseDistance = global.screen_width;
else
baseDistance = global.screen_height;
let progress;
if (this._switchData && this._switchData.gestureActivated) {
this._switchData.container.remove_all_transitions();
if (!horiz)
progress = -this._switchData.container.y / baseDistance;
else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
progress = this._switchData.container.x / baseDistance;
else
progress = -this._switchData.container.x / baseDistance;
} else {
this._prepareWorkspaceSwitch(activeWorkspace.index(), -1);
progress = 0;
}
let points = [];
let [lower, upper] = this._getProgressRange();
if (lower !== 0)
points.push(lower);
points.push(0);
if (upper !== 0)
points.push(upper);
tracker.confirmSwipe(baseDistance, points, progress, 0);
}
_switchWorkspaceUpdate(tracker, progress) {
if (!this._switchData)
return;
let direction = this._directionForProgress(progress);
let info = this._switchData.surroundings[direction];
let xPos = 0;
let yPos = 0;
if (info) {
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);
}
this._switchData.container.set_position(xPos, yPos);
}
_switchWorkspaceEnd(tracker, duration, endProgress) {
if (!this._switchData)
return;
let workspaceManager = global.workspace_manager;
let activeWorkspace = workspaceManager.get_active_workspace();
let newWs = activeWorkspace;
let xDest = 0;
let yDest = 0;
if (endProgress !== 0) {
let direction = this._directionForProgress(endProgress);
newWs = activeWorkspace.get_neighbor(direction);
xDest = -this._switchData.surroundings[direction].xDest;
yDest = -this._switchData.surroundings[direction].yDest;
}
let switchData = this._switchData;
switchData.gestureActivated = true;
this._switchData.container.ease({
x: xDest,
y: yDest,
duration,
mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
onComplete: () => {
if (!newWs.active)
this.actionMoveWorkspace(newWs);
this._finishWorkspaceSwitch(switchData);
},
});
}
_switchWorkspaceStop() {
this._switchData.container.x = 0;
this._switchData.container.y = 0;
this._finishWorkspaceSwitch(this._switchData);
} }
_showTilePreview(shellwm, window, tileRect, monitorIndex) { _showTilePreview(shellwm, window, tileRect, monitorIndex) {
@ -2196,7 +1828,7 @@ var WindowManager = class {
// This won't have any effect for "always sticky" windows // This won't have any effect for "always sticky" windows
// (like desktop windows or docks) // (like desktop windows or docks)
this._movingWindow = window; this._workspaceAnimation.movingWindow = window;
window.change_workspace(workspace); window.change_workspace(workspace);
global.display.clear_mouse_mode(); global.display.clear_mouse_mode();

475
js/ui/workspaceAnimation.js Normal file
View File

@ -0,0 +1,475 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported WorkspaceAnimationController */
const { Clutter, GObject, Meta, Shell } = imports.gi;
const Background = imports.ui.background;
const Layout = imports.ui.layout;
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, monitor, movingWindow) {
super._init();
this._workspace = workspace;
this._monitor = monitor;
this._movingWindow = movingWindow;
this._windowRecords = [];
this._createWindows();
this.connect('destroy', this._onDestroy.bind(this));
this._restackedId = global.display.connect('restacked',
this._syncStacking.bind(this));
}
get workspace() {
return this._workspace;
}
_shouldShowWindow(window) {
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;
// 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().filter(w =>
this._shouldShowWindow(w.meta_window));
let lastRecord;
for (const windowActor of windowActors) {
const record = this._windowRecords.find(r => r.windowActor === windowActor);
this.set_child_above_sibling(record.clone, lastRecord ? lastRecord.clone : null);
lastRecord = record;
}
}
_createWindows() {
const windowActors = global.get_window_actors().filter(w =>
this._shouldShowWindow(w.meta_window));
for (const windowActor of windowActors) {
const clone = new Clutter.Clone({
source: windowActor,
x: windowActor.x - this._monitor.x,
y: windowActor.y - this._monitor.y,
});
this.add_child(clone);
const record = { windowActor, clone };
record.windowDestroyId = windowActor.connect('destroy', () => {
clone.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);
record.clone.destroy();
}
this._windowRecords = [];
}
_onDestroy() {
global.display.disconnect(this._restackedId);
this._removeWindows();
}
});
const MonitorGroup = GObject.registerClass({
Properties: {
'progress': GObject.ParamSpec.double(
'progress', 'progress', 'progress',
GObject.ParamFlags.READWRITE,
-Infinity, Infinity, 0),
},
}, class MonitorGroup extends Clutter.Actor {
_init(monitor, workspaceIndices, movingWindow) {
super._init({
clip_to_allocation: true,
});
this._monitor = monitor;
const constraint = new Layout.MonitorConstraint({ index: monitor.index });
this.add_constraint(constraint);
const background = new Meta.BackgroundGroup();
this.add_child(background);
this._container = new Clutter.Actor();
this.add_child(this._container);
const stickyGroup = new WorkspaceGroup(null, monitor, movingWindow);
this.add_child(stickyGroup);
this._workspaceGroups = [];
const workspaceManager = global.workspace_manager;
const vertical = workspaceManager.layout_rows === -1;
const activeWorkspace = workspaceManager.get_active_workspace();
let x = 0;
let y = 0;
for (const i of workspaceIndices) {
const ws = workspaceManager.get_workspace_by_index(i);
const fullscreen = ws.list_windows().some(w => w.get_monitor() === monitor.index && w.is_fullscreen());
if (i > 0 && vertical && !fullscreen && monitor.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 group = new WorkspaceGroup(ws, monitor, movingWindow);
this._workspaceGroups.push(group);
this._container.add_child(group);
group.set_position(x, y);
if (vertical)
y += this.baseDistance;
else if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL)
x -= this.baseDistance;
else
x += this.baseDistance;
}
this.progress = this.getWorkspaceProgress(activeWorkspace);
this._bgManager = new Background.BackgroundManager({
container: background,
monitorIndex: monitor.index,
controlPosition: false,
});
this.connect('destroy', this._onDestroy.bind(this));
}
_onDestroy() {
this._bgManager.destroy();
}
get baseDistance() {
if (global.workspace_manager.layout_rows === -1)
return this._monitor.height;
else
return this._monitor.width;
}
get progress() {
if (global.workspace_manager.layout_rows === -1)
return -this._container.y / this.baseDistance;
else if (this.get_text_direction() === Clutter.TextDirection.RTL)
return this._container.x / this.baseDistance;
else
return -this._container.x / this.baseDistance;
}
set progress(p) {
if (global.workspace_manager.layout_rows === -1)
this._container.y = -Math.round(p * this.baseDistance);
else if (this.get_text_direction() === Clutter.TextDirection.RTL)
this._container.x = Math.round(p * this.baseDistance);
else
this._container.x = -Math.round(p * this.baseDistance);
}
get index() {
return this._monitor.index;
}
getWorkspaceProgress(workspace) {
const group = this._workspaceGroups.find(g =>
g.workspace.index() === workspace.index());
return this._getWorkspaceGroupProgress(group);
}
_getWorkspaceGroupProgress(group) {
if (global.workspace_manager.layout_rows === -1)
return group.y / this.baseDistance;
else if (this.get_text_direction() === Clutter.TextDirection.RTL)
return -group.x / this.baseDistance;
else
return group.x / this.baseDistance;
}
getSnapPoints() {
return this._workspaceGroups.map(g =>
this._getWorkspaceGroupProgress(g));
}
findClosestWorkspace(progress) {
const distances = this.getSnapPoints().map(p =>
Math.abs(p - progress));
const index = distances.indexOf(Math.min(...distances));
return this._workspaceGroups[index].workspace;
}
_interpolateProgress(progress, monitorGroup) {
if (this.index === monitorGroup.index)
return progress;
const points1 = monitorGroup.getSnapPoints();
const points2 = this.getSnapPoints();
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;
}
updateSwipeForMonitor(progress, monitorGroup) {
this.progress = this._interpolateProgress(progress, monitorGroup);
}
});
var WorkspaceAnimationController = class {
constructor() {
this._movingWindow = null;
this._switchData = null;
Main.overview.connect('showing', () => {
if (this._switchData) {
if (this._switchData.gestureActivated)
this._finishWorkspaceSwitch(this._switchData);
this._swipeTracker.enabled = false;
}
});
Main.overview.connect('hiding', () => {
this._swipeTracker.enabled = true;
});
let swipeTracker = new SwipeTracker.SwipeTracker(global.stage,
Shell.ActionMode.NORMAL, { allowDrag: false, allowScroll: false });
swipeTracker.connect('begin', this._switchWorkspaceBegin.bind(this));
swipeTracker.connect('update', this._switchWorkspaceUpdate.bind(this));
swipeTracker.connect('end', this._switchWorkspaceEnd.bind(this));
this._swipeTracker = swipeTracker;
}
_prepareWorkspaceSwitch(workspaceIndices) {
if (this._switchData)
return;
const workspaceManager = global.workspace_manager;
const nWorkspaces = workspaceManager.get_n_workspaces();
const switchData = {};
this._switchData = switchData;
switchData.monitors = [];
switchData.gestureActivated = false;
switchData.inProgress = false;
if (!workspaceIndices)
workspaceIndices = [...Array(nWorkspaces).keys()];
const monitors = Meta.prefs_get_workspaces_only_on_primary()
? [Main.layoutManager.primaryMonitor] : Main.layoutManager.monitors;
for (const monitor of monitors) {
if (Meta.prefs_get_workspaces_only_on_primary() &&
monitor.index !== Main.layoutManager.primaryIndex)
continue;
const group = new MonitorGroup(monitor, workspaceIndices, this.movingWindow);
Main.uiGroup.insert_child_above(group, global.window_group);
switchData.monitors.push(group);
}
}
_finishWorkspaceSwitch(switchData) {
this._switchData = null;
switchData.monitors.forEach(m => m.destroy());
this.movingWindow = null;
}
animateSwitch(from, to, direction, onComplete) {
this._swipeTracker.enabled = false;
let workspaceIndices = [];
switch (direction) {
case Meta.MotionDirection.UP:
case Meta.MotionDirection.LEFT:
case Meta.MotionDirection.UP_LEFT:
case Meta.MotionDirection.UP_RIGHT:
workspaceIndices = [to, from];
break;
case Meta.MotionDirection.DOWN:
case Meta.MotionDirection.RIGHT:
case Meta.MotionDirection.DOWN_LEFT:
case Meta.MotionDirection.DOWN_RIGHT:
workspaceIndices = [from, to];
break;
}
if (Clutter.get_default_text_direction() === Clutter.TextDirection.RTL &&
direction !== Meta.MotionDirection.UP &&
direction !== Meta.MotionDirection.DOWN)
workspaceIndices.reverse();
this._prepareWorkspaceSwitch(workspaceIndices);
this._switchData.inProgress = true;
const fromWs = global.workspace_manager.get_workspace_by_index(from);
const toWs = global.workspace_manager.get_workspace_by_index(to);
for (const monitorGroup of this._switchData.monitors) {
monitorGroup.progress = monitorGroup.getWorkspaceProgress(fromWs);
const progress = monitorGroup.getWorkspaceProgress(toWs);
const params = {
duration: WINDOW_ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
};
if (monitorGroup.index === Main.layoutManager.primaryIndex) {
params.onComplete = () => {
this._finishWorkspaceSwitch(this._switchData);
onComplete();
this._swipeTracker.enabled = true;
};
}
monitorGroup.ease_property('progress', progress, params);
}
}
_findMonitorGroup(monitorIndex) {
return this._switchData.monitors.find(m => m.index === monitorIndex);
}
_switchWorkspaceBegin(tracker, monitor) {
if (Meta.prefs_get_workspaces_only_on_primary() &&
monitor !== Main.layoutManager.primaryIndex)
return;
const workspaceManager = global.workspace_manager;
const horiz = workspaceManager.layout_rows !== -1;
tracker.orientation = horiz
? Clutter.Orientation.HORIZONTAL
: Clutter.Orientation.VERTICAL;
if (this._switchData && this._switchData.gestureActivated) {
for (const group of this._switchData.monitors)
group.remove_all_transitions();
} else {
this._prepareWorkspaceSwitch();
}
const monitorGroup = this._findMonitorGroup(monitor);
const baseDistance = monitorGroup.baseDistance;
const progress = monitorGroup.progress;
const closestWs = monitorGroup.findClosestWorkspace(progress);
const cancelProgress = monitorGroup.getWorkspaceProgress(closestWs);
const points = monitorGroup.getSnapPoints();
this._switchData.baseMonitorGroup = monitorGroup;
tracker.confirmSwipe(baseDistance, points, progress, cancelProgress);
}
_switchWorkspaceUpdate(tracker, progress) {
if (!this._switchData)
return;
for (const monitorGroup of this._switchData.monitors)
monitorGroup.updateSwipeForMonitor(progress, this._switchData.baseMonitorGroup);
}
_switchWorkspaceEnd(tracker, duration, endProgress) {
if (!this._switchData)
return;
const switchData = this._switchData;
switchData.gestureActivated = true;
const newWs = switchData.baseMonitorGroup.findClosestWorkspace(endProgress);
for (const monitorGroup of this._switchData.monitors) {
const progress = monitorGroup.getWorkspaceProgress(newWs);
const params = {
duration,
mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
};
if (monitorGroup.index === Main.layoutManager.primaryIndex) {
params.onComplete = () => {
if (!newWs.active)
newWs.activate(global.get_current_time());
this._finishWorkspaceSwitch(switchData);
};
}
monitorGroup.ease_property('progress', progress, params);
}
}
get gestureActive() {
return this._switchData !== null && this._switchData.gestureActivated;
}
cancelSwitchAnimation() {
if (!this._switchData)
return;
if (this._switchData.gestureActivated)
return;
this._finishWorkspaceSwitch(this._switchData);
}
set movingWindow(movingWindow) {
this._movingWindow = movingWindow;
}
get movingWindow() {
return this._movingWindow;
}
};