203 lines
6.9 KiB
QML
203 lines
6.9 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
|
|
// One window on the window loop: a preview with the icon, title and app below.
|
|
Item {
|
|
id: root
|
|
|
|
required property Theme theme
|
|
required property string title
|
|
required property string app
|
|
required property bool selected
|
|
required property bool current
|
|
// 0 at the front of the loop, 1 at the very back.
|
|
required property real shade
|
|
// Stream the Hyprland preview. Off while the loop is hidden.
|
|
required property bool live
|
|
// Live capture source on Hyprland, null elsewhere.
|
|
required property Toplevel toplevel
|
|
// Screenshot file on niri, "" elsewhere.
|
|
required property string previewFile
|
|
// Changes whenever the screenshot files are rewritten.
|
|
required property int previewVersion
|
|
// Grow the preview out from the icon once it is ready.
|
|
required property bool growPreview
|
|
|
|
signal activated
|
|
|
|
readonly property string iconSource: Quickshell.iconPath(root.app, "application-x-executable")
|
|
readonly property bool hasLive: root.toplevel !== null && liveView.hasContent
|
|
readonly property bool hasShot: shotView.status === Image.Ready
|
|
// A picture is showing, live or still.
|
|
readonly property bool hasPicture: root.hasLive || root.hasShot
|
|
|
|
width: root.theme.loopCardWidth
|
|
height: root.theme.loopCardHeight
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.loopCardRadius
|
|
tint: root.theme.loopCardBg
|
|
selected: root.selected
|
|
shadow: true
|
|
}
|
|
|
|
Rectangle {
|
|
id: previewArea
|
|
anchors.top: parent.top
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: infoRow.top
|
|
anchors.margins: root.theme.loopCardPadding
|
|
radius: root.theme.loopPreviewRadius
|
|
color: root.theme.loopPreviewBg
|
|
// A faint edge, so it reads as a pane set into the glass.
|
|
border.width: 1
|
|
border.color: root.theme.glassRimBottom
|
|
clip: true
|
|
|
|
// Holds the live view and the snapshot. Once a picture is ready it
|
|
// grows out from the icon's size to fill the preview area.
|
|
Item {
|
|
id: picture
|
|
|
|
// Size of the icon next to the full preview area.
|
|
readonly property real startScale: previewArea.width > 0 ? Math.min(1, root.theme.loopIconSize / previewArea.width) : 1
|
|
|
|
anchors.fill: parent
|
|
scale: root.hasPicture ? 1 : picture.startScale
|
|
opacity: root.hasPicture ? 1 : 0
|
|
|
|
Behavior on scale {
|
|
enabled: root.growPreview
|
|
NumberAnimation {
|
|
duration: root.theme.loopPreviewGrowDuration
|
|
easing.type: Easing.InOutCubic
|
|
}
|
|
}
|
|
Behavior on opacity {
|
|
enabled: root.growPreview
|
|
NumberAnimation {
|
|
duration: root.theme.loopPreviewGrowDuration
|
|
easing.type: Easing.InOutCubic
|
|
}
|
|
}
|
|
|
|
ScreencopyView {
|
|
id: liveView
|
|
|
|
// Keeps the window's own shape inside the preview area.
|
|
readonly property real aspect: liveView.sourceSize.height > 0 ? liveView.sourceSize.width / liveView.sourceSize.height : 16 / 9
|
|
|
|
anchors.centerIn: parent
|
|
width: Math.min(parent.width, parent.height * liveView.aspect)
|
|
height: liveView.width / liveView.aspect
|
|
captureSource: root.live ? root.toplevel : null
|
|
live: true
|
|
visible: root.hasLive
|
|
}
|
|
|
|
Image {
|
|
id: shotView
|
|
anchors.fill: parent
|
|
source: root.previewFile.length > 0 ? "file://" + root.previewFile + "?v=" + root.previewVersion : ""
|
|
// The file is rewritten in place, so never reuse an old copy.
|
|
cache: false
|
|
asynchronous: true
|
|
sourceSize.width: root.theme.loopCardWidth * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
visible: root.hasShot
|
|
}
|
|
}
|
|
|
|
Image {
|
|
id: previewIcon
|
|
anchors.centerIn: parent
|
|
width: root.theme.loopIconSize
|
|
height: root.theme.loopIconSize
|
|
source: root.iconSource
|
|
sourceSize.width: root.theme.loopIconSize * 2
|
|
sourceSize.height: root.theme.loopIconSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
// Fades out as the picture grows in.
|
|
opacity: root.hasPicture ? 0 : 1
|
|
visible: previewIcon.opacity > 0
|
|
|
|
Behavior on opacity {
|
|
enabled: root.growPreview
|
|
NumberAnimation {
|
|
duration: root.theme.loopPreviewGrowDuration
|
|
easing.type: Easing.InOutCubic
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: infoRow
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
anchors.leftMargin: root.theme.loopCardPadding
|
|
anchors.rightMargin: root.theme.loopCardPadding
|
|
anchors.bottomMargin: root.theme.loopCardPadding
|
|
height: root.theme.loopRowHeight
|
|
spacing: 10
|
|
|
|
Image {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: root.theme.loopRowIconSize
|
|
height: root.theme.loopRowIconSize
|
|
source: root.iconSource
|
|
sourceSize.width: root.theme.loopRowIconSize * 2
|
|
sourceSize.height: root.theme.loopRowIconSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
}
|
|
|
|
Column {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: parent.width - root.theme.loopRowIconSize - parent.spacing
|
|
|
|
Text {
|
|
width: parent.width
|
|
elide: Text.ElideRight
|
|
color: root.theme.textColor
|
|
font.pixelSize: root.theme.loopTitleSize
|
|
text: root.title.length > 0 ? root.title : "Untitled"
|
|
}
|
|
|
|
Text {
|
|
width: parent.width
|
|
elide: Text.ElideRight
|
|
color: root.current ? root.theme.accentColor : root.theme.labelColor
|
|
font.pixelSize: root.theme.loopAppSize
|
|
text: {
|
|
const name = root.app.length > 0 ? root.app : "unknown app";
|
|
return root.current ? name + " · focused" : name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Darkens cards toward the back of the loop.
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
radius: root.theme.loopCardRadius
|
|
color: root.theme.loopBackShadeColor
|
|
opacity: root.shade * root.theme.loopBackShade
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: root.activated()
|
|
}
|
|
}
|