138 lines
4.1 KiB
QML
138 lines
4.1 KiB
QML
pragma ComponentBehavior: Bound
|
||
|
||
import qs.components
|
||
import qs.services
|
||
import qs.utils
|
||
import qs.config
|
||
import QtQuick
|
||
|
||
Item {
|
||
id: root
|
||
|
||
required property var bar
|
||
required property Brightness.Monitor monitor
|
||
property color colour: Colours.palette.m3primary
|
||
|
||
readonly property string windowTitle: {
|
||
const title = Hypr.activeToplevel?.title;
|
||
if (!title)
|
||
return qsTr("Desktop");
|
||
if (Config.bar.activeWindow.compact) {
|
||
// " - " (standard hyphen), " — " (em dash), " – " (en dash)
|
||
const parts = root.windowTitle.split(/\s+[\-\u2013\u2014]\s+/);
|
||
if (parts.length > 1)
|
||
return parts[parts.length - 1].trim();
|
||
}
|
||
return title;
|
||
}
|
||
|
||
readonly property int maxHeight: {
|
||
const otherModules = bar.children.filter(c => c.id && c.item !== this && c.id !== "spacer");
|
||
const otherHeight = otherModules.reduce((acc, curr) => acc + (curr.item.nonAnimHeight ?? curr.height), 0);
|
||
// Length - 2 cause repeater counts as a child
|
||
return bar.height - otherHeight - bar.spacing * (bar.children.length - 1) - bar.vPadding * 2;
|
||
}
|
||
property Title current: text1
|
||
|
||
clip: true
|
||
implicitWidth: Math.max(icon.implicitWidth, current.implicitHeight)
|
||
implicitHeight: icon.implicitHeight + current.implicitWidth + current.anchors.topMargin
|
||
|
||
Loader {
|
||
anchors.fill: parent
|
||
active: !Config.bar.activeWindow.showOnHover
|
||
|
||
sourceComponent: MouseArea {
|
||
cursorShape: Qt.PointingHandCursor
|
||
hoverEnabled: true
|
||
onPositionChanged: {
|
||
const popouts = root.bar.popouts;
|
||
if (popouts.hasCurrent && popouts.currentName !== "activewindow")
|
||
popouts.hasCurrent = false;
|
||
}
|
||
onClicked: {
|
||
const popouts = root.bar.popouts;
|
||
if (popouts.hasCurrent) {
|
||
popouts.hasCurrent = false;
|
||
} else {
|
||
popouts.currentName = "activewindow";
|
||
popouts.currentCenter = root.mapToItem(root.bar, 0, root.implicitHeight / 2).y;
|
||
popouts.hasCurrent = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
MaterialIcon {
|
||
id: icon
|
||
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
|
||
animate: true
|
||
text: Icons.getAppCategoryIcon(Hypr.activeToplevel?.lastIpcObject.class, "desktop_windows")
|
||
color: root.colour
|
||
}
|
||
|
||
Title {
|
||
id: text1
|
||
}
|
||
|
||
Title {
|
||
id: text2
|
||
}
|
||
|
||
TextMetrics {
|
||
id: metrics
|
||
|
||
text: root.windowTitle
|
||
font.pointSize: Appearance.font.size.smaller
|
||
font.family: Appearance.font.family.mono
|
||
elide: Qt.ElideRight
|
||
elideWidth: root.maxHeight - icon.height
|
||
|
||
onTextChanged: {
|
||
const next = root.current === text1 ? text2 : text1;
|
||
next.text = elidedText;
|
||
root.current = next;
|
||
}
|
||
onElideWidthChanged: root.current.text = elidedText
|
||
}
|
||
|
||
Behavior on implicitHeight {
|
||
Anim {
|
||
duration: Appearance.anim.durations.expressiveDefaultSpatial
|
||
easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial
|
||
}
|
||
}
|
||
|
||
component Title: StyledText {
|
||
id: text
|
||
|
||
anchors.horizontalCenter: icon.horizontalCenter
|
||
anchors.top: icon.bottom
|
||
anchors.topMargin: Appearance.spacing.small
|
||
|
||
font.pointSize: metrics.font.pointSize
|
||
font.family: metrics.font.family
|
||
color: root.colour
|
||
opacity: root.current === this ? 1 : 0
|
||
|
||
transform: [
|
||
Translate {
|
||
x: Config.bar.activeWindow.inverted ? -text.implicitWidth + text.implicitHeight : 0
|
||
},
|
||
Rotation {
|
||
angle: Config.bar.activeWindow.inverted ? 270 : 90
|
||
origin.x: text.implicitHeight / 2
|
||
origin.y: text.implicitHeight / 2
|
||
}
|
||
]
|
||
|
||
width: implicitHeight
|
||
height: implicitWidth
|
||
|
||
Behavior on opacity {
|
||
Anim {}
|
||
}
|
||
}
|
||
}
|