Files
skygqts/workspace-manager/WindowRing.qml
T
2026-09-23 16:57:18 -04:00

145 lines
5.7 KiB
QML

import QtQuick
// One set of window cards on the loop. While Up/Down switch workspaces the
// loop shows two of these: the old one folding away and the new one opening.
// Zero sized, placed at the loop center.
Item {
id: root
required property Compositor compositor
required property Theme theme
// Windows to show, from parsed JSON, so this stays untyped.
required property var windows
// Widest the loop may be on each side of its center.
required property real maxRadius
// Drives every card position. Not wrapped.
required property real turn
required property int selectedIndex
// Stream the Hyprland previews.
required property bool live
// Previews grow out from the icon once they are ready.
required property bool growPreview
// 0 for the open loop, 1 with every card folded into one small box.
required property real gather
// A card was clicked.
signal activated(int index)
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);
return Math.max(root.theme.loopMinRadius, Math.min(natural, root.maxRadius));
}
// 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;
}
// 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);
}
// 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);
}
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)
// 1 when open, 0 when folded into the box.
readonly property real open: 1 - root.gather
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.live
growPreview: root.growPreview
toplevel: root.compositor.toplevelFor(card.modelData.key)
previewFile: card.modelData.preview
previewVersion: root.compositor.previewVersion
// Folding pulls every card into the middle, facing front.
x: root.radius * card.open * Math.sin(card.angle) * card.depthScale - card.width / 2
y: -root.theme.loopBackLift * card.back * card.open - card.height / 2
z: card.cosA
scale: card.depthScale + (root.theme.loopBoxScale - card.depthScale) * root.gather
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 * card.open
}
onActivated: root.activated(card.index)
}
}
}