Files
skygqts/workspace-manager/WorkspaceCard.qml
T
2026-09-23 10:17:06 -04:00

131 lines
4.0 KiB
QML

import QtQuick
import Quickshell
import QtQuick.Layouts
Rectangle {
id: root
required property Theme theme
required property string workspaceName
required property int workspaceIndex
required property bool selected
required property bool current
required property bool animateMoves
required property var windows
signal activated
// Windows that fit before the "+N more" overflow.
readonly property var displayWindows: root.windows.slice(0, root.theme.maxWindowRows)
readonly property int hiddenCount: Math.max(0, root.windows.length - root.theme.maxWindowRows)
width: root.theme.cardWidth
height: root.theme.cardHeight
radius: root.theme.cardRadius
color: root.theme.fieldBg
border.width: root.selected ? 3 : 1
border.color: root.selected ? root.theme.fieldBorder : root.theme.barBorder
clip: true
Behavior on anchors.horizontalCenterOffset {
enabled: root.animateMoves
NumberAnimation {
duration: root.theme.carouselDuration
easing.type: Easing.OutCubic
}
}
Behavior on opacity {
enabled: root.animateMoves
NumberAnimation {
duration: root.theme.carouselDuration
}
}
Behavior on scale {
enabled: root.animateMoves
NumberAnimation {
duration: root.theme.carouselDuration
}
}
Column {
anchors.fill: parent
anchors.margins: root.theme.fieldPadding
spacing: 6
// Top row: workspace name + index + current badge
RowLayout {
width: parent.width
spacing: 6
Text {
Layout.fillWidth: true
elide: Text.ElideRight
color: root.theme.textColor
font.pixelSize: root.theme.fontSize
text: root.workspaceName.length > 0 ? root.workspaceName : String(root.workspaceIndex)
}
Text {
visible: root.workspaceName.length > 0
color: root.theme.labelColor
font.pixelSize: root.theme.monitorLabelSize
text: String(root.workspaceIndex)
}
Text {
visible: root.current
color: root.theme.fieldBorder
font.pixelSize: root.theme.monitorLabelSize
text: "current"
}
}
// Window bubbles
Column {
width: parent.width
spacing: root.theme.windowRowSpacing
Repeater {
model: root.displayWindows
Row {
width: parent.width
spacing: 6
Image {
width: root.theme.windowIconSize
height: root.theme.windowIconSize
source: Quickshell.iconPath(modelData.app.length > 0 ? modelData.app : "window")
sourceSize.width: root.theme.windowIconSize * 2
sourceSize.height: root.theme.windowIconSize * 2
fillMode: Image.PreserveAspectFit
smooth: true
}
Text {
width: parent.width - root.theme.windowIconSize - parent.spacing
height: root.theme.windowIconSize
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
color: root.theme.labelColor
font.pixelSize: root.theme.windowFontSize
text: modelData.title.length > 0 ? modelData.title : "Untitled"
}
}
}
Text {
visible: root.hiddenCount > 0
color: root.theme.labelColor
font.pixelSize: root.theme.windowFontSize
text: "+" + root.hiddenCount + " more"
}
}
}
MouseArea {
anchors.fill: parent
onClicked: root.activated()
}
}