import QtQuick // The windows of one workspace sit 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. 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 // A window was focused. signal windowChosen // 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 // 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 // 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) 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 turn { enabled: root.animate NumberAnimation { duration: root.theme.loopTurnDuration easing.type: Easing.OutCubic } } 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); } 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" } // Zero sized point at the loop center. Pushed down by half the lift // so the loop as a whole sits in the middle. Item { id: stage anchors.centerIn: parent anchors.verticalCenterOffset: root.theme.loopBackLift / 2 // 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 } WindowRing { id: ring y: root.slideY 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 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 } } } }