smoother animations

This commit is contained in:
ari committed 2026-09-23 16:57:18 -04:00
1 parent bcf70106e2
commit f67d7f1c55
6 files changed
+357 -156

No files matched your search

+127 -128
View File
@@ -12,7 +12,7 @@ Item {
required property int workspaceId
// Shown and taking input. Fades and grows in when this turns on.
required property bool expanded
// Shown on the top edge of the front window, "" for none.
// Shown under the front window, "" for none.
required property string exitHint
// A window was focused.
@@ -25,56 +25,36 @@ Item {
}
readonly property int count: root.windows.length
// Angle between two neighbours on the loop.
readonly property real angleStep: root.count > 0 ? 2 * Math.PI / root.count : 0
// The loop is as long as the cards side by side, within limits.
readonly property real radius: {
const natural = root.count * (root.theme.loopCardWidth + root.theme.loopCardGap) / (2 * Math.PI);
const widest = root.width * root.theme.loopMaxRadiusShare;
return Math.max(root.theme.loopMinRadius, Math.min(natural, widest));
}
// About how far the loop reaches sideways from its center, card edges
// included. Sampled over the front half so it stays still while turning.
readonly property real reachX: {
const half = root.theme.loopCardWidth / 2;
if (root.count <= 1)
return half;
const focal = root.theme.loopFocalLength;
let widest = half;
for (let i = 1; i <= 16; i++) {
const angle = i / 16 * Math.PI / 2;
const depthScale = focal / (focal + root.radius * (1 - Math.cos(angle)));
const faceWidth = Math.abs(Math.cos(root.faceTurn(angle) * Math.PI / 180));
const edge = (root.radius * Math.sin(angle) + half * faceWidth) * depthScale;
widest = Math.max(widest, edge);
}
return widest;
}
// included.
readonly property real reachX: ring.reachX
// Top and bottom edges of the front window, from the middle of the view.
readonly property real frontTop: root.theme.loopBackLift / 2 - root.theme.loopCardHeight / 2
readonly property real frontBottom: root.theme.loopBackLift / 2 + root.theme.loopCardHeight / 2
// Where round the loop, in degrees, cards turn edge-on. Halfway between
// two cards, so none rests edge-on.
readonly property real flipAngle: {
if (root.count <= 1)
return 90;
const stepDegrees = 360 / root.count;
const flip = (Math.floor(root.theme.loopFlipAngle / stepDegrees) + 0.5) * stepDegrees;
return Math.min(flip, 180);
}
// Selected step. It is not wrapped, so the loop can keep turning the
// same way. Use selectedIndex for the position in the window list.
property int targetStep: 0
// Follows targetStep smoothly and drives every card position.
property real turn: 0
property bool animate: false
// Offset and fade of the loop while it slides in after a workspace switch.
// Offset, fade and fold of the loop while it opens after a workspace switch.
property real slideY: 0
property real switchFade: 1
property real gather: 0
// The old windows, kept while they fold away after a workspace switch.
// From parsed JSON, so this stays untyped.
property var leavingWindows: []
property real leavingTurn: 0
property int leavingIndex: 0
property real leavingY: 0
property real leavingFade: 0
property real leavingGather: 0
// Where the old windows slide to as they fold.
property real leavingTo: 0
readonly property int selectedIndex: root.wrapIndex(root.targetStep)
@@ -105,18 +85,56 @@ Item {
ParallelAnimation {
id: switchAnim
// The old windows fold into a box, which slides away and fades.
NumberAnimation {
target: root
property: "slideY"
to: 0
duration: root.theme.loopSwitchDuration
property: "leavingGather"
to: 1
duration: root.theme.loopCollapseDuration
easing.type: Easing.OutCubic
}
NumberAnimation {
target: root
property: "switchFade"
to: 1
duration: root.theme.loopSwitchDuration
property: "leavingY"
to: root.leavingTo
duration: root.theme.loopCollapseDuration
easing.type: Easing.InCubic
}
NumberAnimation {
target: root
property: "leavingFade"
to: 0
duration: root.theme.loopCollapseDuration
easing.type: Easing.InQuad
}
// A little later, the new windows slide in as a box and open out.
SequentialAnimation {
PauseAnimation {
duration: root.theme.loopExpandDelay
}
ParallelAnimation {
NumberAnimation {
target: root
property: "slideY"
to: 0
duration: root.theme.loopSwitchDuration
easing.type: Easing.OutCubic
}
NumberAnimation {
target: root
property: "switchFade"
to: 1
duration: root.theme.loopSwitchDuration
}
NumberAnimation {
target: root
property: "gather"
to: 0
duration: root.theme.loopSwitchDuration
easing.type: Easing.InOutCubic
}
}
}
}
@@ -126,31 +144,6 @@ Item {
return ((step % root.count) + root.count) % root.count;
}
// Angle of a card from the front, in radians, between -pi and pi.
function angleOf(index: int): real {
if (root.count === 0)
return 0;
let steps = (index - root.turn) % root.count;
if (steps < 0)
steps += root.count;
if (steps > root.count / 2)
steps -= root.count;
return steps * root.angleStep;
}
// How far a card at this angle (radians) turns, in degrees. It turns
// from facing the viewer at the front to edge-on at flipAngle, then on
// round to face the viewer again at the back, showing its inner face.
function faceTurn(angle: real): real {
const degrees = Math.abs(angle) * 180 / Math.PI;
const side = angle < 0 ? -1 : 1;
const flip = root.flipAngle;
if (degrees <= flip || flip >= 180)
return -side * 90 * degrees / flip;
const turn = 90 + 90 * (degrees - flip) / (180 - flip);
return -side * (turn - 180);
}
// Select the focused window, or the first one, and turn into place.
function seed(): void {
const list = root.windows;
@@ -164,12 +157,27 @@ Item {
root.compositor.takeScreenshots(list.map(w => w.key));
}
// Keep the shown windows, as they are now, so they can fold away.
// Call just before the workspace changes.
function holdLeaving(): void {
switchAnim.stop();
root.leavingWindows = root.windows;
root.leavingTurn = root.turn;
root.leavingIndex = root.selectedIndex;
root.leavingY = root.slideY;
root.leavingFade = root.switchFade;
root.leavingGather = root.gather;
}
// Show another workspace. The new windows slide in from below when
// direction is positive, from above when negative.
// direction is positive, from above when negative, and the old ones
// slide out the other way.
function switchIn(direction: int): void {
switchAnim.stop();
root.leavingTo = -direction * root.theme.loopSwitchOffset;
root.slideY = direction * root.theme.loopSwitchOffset;
root.switchFade = 0;
root.gather = 1;
root.seed();
switchAnim.start();
}
@@ -209,70 +217,61 @@ Item {
Item {
id: stage
anchors.centerIn: parent
anchors.verticalCenterOffset: root.theme.loopBackLift / 2 + root.slideY
opacity: root.switchFade
anchors.verticalCenterOffset: root.theme.loopBackLift / 2
Repeater {
model: root.windows
WindowCard {
id: card
required property var modelData
required property int index
readonly property real angle: root.angleOf(card.index)
readonly property real cosA: Math.cos(card.angle)
// 0 at the front, 1 at the very back.
readonly property real back: (1 - card.cosA) / 2
// Simple perspective: cards farther away get smaller.
readonly property real depthScale: root.theme.loopFocalLength / (root.theme.loopFocalLength + 2 * root.radius * card.back)
// Turn so each card roughly lies along the loop, less so
// at the sides, so they can still be seen.
readonly property real faceAngle: root.faceTurn(card.angle)
theme: root.theme
title: card.modelData.title
app: card.modelData.app
selected: card.index === root.selectedIndex
current: card.modelData.focused === true
shade: card.back
live: root.expanded
toplevel: root.compositor.toplevelFor(card.modelData.key)
previewFile: card.modelData.preview
previewVersion: root.compositor.previewVersion
enabled: root.expanded
x: root.radius * Math.sin(card.angle) * card.depthScale - card.width / 2
y: -root.theme.loopBackLift * card.back - card.height / 2
z: card.cosA
scale: card.depthScale
opacity: 1 - (1 - root.theme.loopBackOpacity) * card.back
transform: Rotation {
origin.x: card.width / 2
origin.y: card.height / 2
axis {
x: 0
y: 1
z: 0
}
angle: card.faceAngle
}
onActivated: root.activateAt(card.index)
}
// The old workspace, folding away.
WindowRing {
id: leavingRing
y: root.leavingY
z: 0
opacity: root.leavingFade
visible: leavingRing.opacity > 0
enabled: false
compositor: root.compositor
theme: root.theme
windows: root.leavingWindows
maxRadius: root.width * root.theme.loopMaxRadiusShare
turn: root.leavingTurn
selectedIndex: root.leavingIndex
live: root.expanded
// Its previews are already out, so they should not grow again.
growPreview: false
gather: root.leavingGather
}
// Under the front window. Cards stay below z 1.
KeyHint {
id: exitHintText
x: root.theme.loopCardWidth / 2 - exitHintText.width
y: root.theme.loopCardHeight / 2 + root.theme.hintGap
z: 2
WindowRing {
id: ring
y: root.slideY
z: 1
opacity: root.switchFade
enabled: root.expanded
compositor: root.compositor
theme: root.theme
hint: root.exitHint
shown: root.count > 0
windows: root.windows
maxRadius: root.width * root.theme.loopMaxRadiusShare
turn: root.turn
selectedIndex: root.selectedIndex
live: root.expanded
growPreview: true
gather: root.gather
onActivated: index => root.activateAt(index)
}
// Under the front window, above both rings.
Item {
y: root.slideY
z: 2
opacity: root.switchFade
KeyHint {
id: exitHintText
x: root.theme.loopCardWidth / 2 - exitHintText.width
y: root.theme.loopCardHeight / 2 + root.theme.hintGap
theme: root.theme
hint: root.exitHint
shown: root.count > 0
}
}
}
}