import QtQuick // The windows of one workspace orbit a small planet on a strip bent into a // closed loop, seen from a little above. The front half shows the outside // of the strip, the back half shows the inside, so the far windows wrap // around behind and face the viewer too. With only a few windows they sit // flat, side by side. The loop sits right of the middle, beside the globe, // with small moons above and below for the workspaces next to this one. Item { id: root required property Compositor compositor required property Theme theme required property int workspaceId // Shown and taking input. Fades and grows in when this turns on. required property bool expanded // Shown under the front window, "" for none. required property string exitHint // Workspaces shown as moons above and below, from parsed JSON, so // these stay untyped. null for none. required property var aboveWorkspace required property var belowWorkspace // A window was focused. signal windowChosen // A moon was clicked: -1 for the one above, 1 for the one below. signal neighbourChosen(int delta) // Windows of the shown workspace, from parsed JSON, so this stays untyped. readonly property var windows: { const ws = root.compositor.workspaceById(root.workspaceId); return ws ? (ws.windows ?? []) : []; } readonly property int count: root.windows.length // About how far the loop reaches sideways from its center, card edges // included. readonly property real reachX: ring.reachX // How far right of the middle the loop sits while open, so its right // edge stays loopScreenGap from the screen edge. It starts in the // middle, where the selected workspace was. property real shiftX: root.expanded ? Math.max(0, root.width / 2 - root.reachX - root.theme.loopScreenGap) : 0 // 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, 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) // Size of the planet, which pops out as the loop opens. property real planetPop: 1 opacity: root.expanded ? 1 : 0 scale: root.expanded ? 1 : root.theme.loopStartScale visible: root.opacity > 0 Behavior on opacity { NumberAnimation { duration: root.theme.loopExpandDuration easing.type: Easing.OutCubic } } Behavior on scale { NumberAnimation { duration: root.theme.loopExpandDuration easing.type: Easing.OutCubic } } Behavior on shiftX { NumberAnimation { duration: root.theme.loopExpandDuration easing.type: Easing.OutCubic } } Behavior on turn { enabled: root.animate NumberAnimation { duration: root.theme.loopTurnDuration easing.type: Easing.OutCubic } } onExpandedChanged: { if (root.expanded) popAnim.restart(); } NumberAnimation { id: popAnim target: root property: "planetPop" from: root.theme.loopStartScale to: 1 duration: root.theme.planetPopDuration easing.type: Easing.OutBack } ParallelAnimation { id: switchAnim // The old windows fold into a box, which slides away and fades. NumberAnimation { target: root property: "leavingGather" to: 1 duration: root.theme.loopCollapseDuration easing.type: Easing.OutCubic } NumberAnimation { target: root 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 } } } } function wrapIndex(step: int): int { if (root.count === 0) return 0; return ((step % root.count) + root.count) % root.count; } // Select the focused window, or the first one, and turn into place. function seed(): void { const list = root.windows; const focused = list.findIndex(w => w.focused); root.animate = false; root.targetStep = focused >= 0 ? focused : 0; // Start one step back so the loop turns in as it appears. root.turn = root.targetStep - (root.count > 1 ? 1 : 0); root.animate = true; root.turn = root.targetStep; 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, 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(); } function step(delta: int): void { if (root.count === 0) return; root.animate = true; root.targetStep += delta; root.turn = root.targetStep; } // Turn to the window at this list index, the short way round. function selectIndex(index: int): void { if (root.count === 0 || index < 0 || index >= root.count) return; let delta = index - root.selectedIndex; if (delta > root.count / 2) delta -= root.count; else if (delta < -root.count / 2) delta += root.count; root.step(delta); } function activateAt(index: int): void { const list = root.windows; if (index < 0 || index >= list.length) return; root.compositor.focusWindow(list[index].key); root.windowChosen(); } function activateSelected(): void { root.activateAt(root.selectedIndex); } // Moved sideways by shiftX. Item { id: content width: root.width height: root.height x: root.shiftX Text { anchors.centerIn: parent anchors.verticalCenterOffset: root.slideY opacity: root.switchFade visible: root.count === 0 color: root.theme.labelColor font.pixelSize: root.theme.loopEmptySize text: "No windows on this workspace" } // The workspaces next to this one, as moons. Each moon's middle // sits moonDistance from the loop's middle; its name hangs below. WorkspaceMoon { id: aboveMoon anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: -root.theme.moonDistance + (aboveMoon.height - root.theme.moonSize) / 2 z: 3 opacity: root.switchFade enabled: root.expanded theme: root.theme workspace: root.aboveWorkspace onActivated: root.neighbourChosen(-1) } WorkspaceMoon { id: belowMoon anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: root.theme.moonDistance + (belowMoon.height - root.theme.moonSize) / 2 z: 3 opacity: root.switchFade enabled: root.expanded theme: root.theme workspace: root.belowWorkspace onActivated: root.neighbourChosen(1) } // Zero sized point in the middle. Each ring is pushed down by half // the lift, unless flat, so it sits in the middle as a whole. Item { id: stage anchors.centerIn: parent // The old workspace, folding away. WindowRing { id: leavingRing y: root.leavingY + (leavingRing.flat ? 0 : root.theme.loopBackLift / 2) 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 planetGrow: 1 } WindowRing { id: ring y: root.slideY + (ring.flat ? 0 : root.theme.loopBackLift / 2) z: 1 opacity: root.switchFade enabled: root.expanded compositor: root.compositor theme: root.theme windows: root.windows maxRadius: root.width * root.theme.loopMaxRadiusShare turn: root.turn selectedIndex: root.selectedIndex live: root.expanded growPreview: true gather: root.gather planetGrow: root.planetPop onActivated: index => root.activateAt(index) } // Under the front window, or under the middle of a flat row, // above both rings. Item { y: ring.y z: 2 opacity: root.switchFade KeyHint { id: exitHintText x: ring.flat ? -exitHintText.width / 2 : root.theme.loopCardWidth / 2 - exitHintText.width y: root.theme.loopCardHeight / 2 + root.theme.hintGap theme: root.theme hint: root.exitHint shown: root.count > 0 } } } } }