Files
skygqts/workspace-manager/WorkspaceMoon.qml
T
2026-10-27 13:35:31 -04:00

95 lines
3.0 KiB
QML

import QtQuick
import Quickshell
// A small preview of a nearby workspace: a little glass moon with the icons
// of its windows on it and its name underneath. Click it to go there.
Item {
id: root
required property Theme theme
// A workspace from parsed JSON, so this stays untyped. null for none.
required property var workspace
signal activated
readonly property var windows: root.workspace ? (root.workspace.windows ?? []) : []
readonly property var shownWindows: root.windows.slice(0, root.theme.moonMaxIcons)
readonly property int hiddenCount: Math.max(0, root.windows.length - root.theme.moonMaxIcons)
width: root.theme.moonSize
height: root.theme.moonSize + label.implicitHeight + root.theme.hintGap
visible: root.workspace !== null
Globe {
id: moon
width: root.theme.moonSize
height: root.theme.moonSize
theme: root.theme
yaw: 0
pitch: root.theme.planetPitch
lonStep: root.theme.planetLatStep
latStep: root.theme.planetLatStep
focalLength: root.theme.loopFocalLength
}
// Window icons, two to a row, on the face of the moon.
Column {
anchors.centerIn: moon
spacing: 2
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2
spacing: 4
Repeater {
model: root.shownWindows
Image {
required property var modelData
width: root.theme.moonIconSize
height: root.theme.moonIconSize
source: Quickshell.iconPath(modelData.app.length > 0 ? modelData.app : "window")
sourceSize.width: root.theme.moonIconSize * 2
sourceSize.height: root.theme.moonIconSize * 2
fillMode: Image.PreserveAspectFit
smooth: true
}
}
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
visible: root.hiddenCount > 0 || root.windows.length === 0
color: root.theme.labelColor
font.pixelSize: root.theme.moonLabelSize - 2
text: root.windows.length === 0 ? "empty" : "+" + root.hiddenCount
}
}
Text {
id: label
anchors.top: moon.bottom
anchors.topMargin: root.theme.hintGap
anchors.horizontalCenter: moon.horizontalCenter
width: root.theme.moonSize * 2
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
color: root.theme.labelColor
font.pixelSize: root.theme.moonLabelSize
text: {
if (!root.workspace)
return "";
const name = root.workspace.name ?? "";
return name.length > 0 ? name : String(root.workspace.idx);
}
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.activated()
}
}