The collapsed notch grows sideways for a new notification: the clock and media stay at the left end and the banner fills the right, in the notch's own fill. Left click runs the default action, right click moves it to the notch's list, hover holds it. The drop-down banners stay off in notch mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
293 lines
11 KiB
QML
293 lines
11 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Widgets
|
|
import "../components"
|
|
import "../core"
|
|
import "../services"
|
|
import "../theme"
|
|
|
|
// The collapsed notch: a glass island hanging from the screen's top edge with
|
|
// concave ears, showing the time, plus cover art and a small visualizer while
|
|
// audio plays. Clicking it opens the notch panel. A new notification widens
|
|
// it: the clock and media keep the left end, the banner takes the right.
|
|
Item {
|
|
id: root
|
|
property var barScreen
|
|
readonly property bool playing: MediaService.playing
|
|
// Newest banner, shown on the screen that was active when it arrived.
|
|
readonly property var latest: ShellState.notchMode && !ShellState.notchOpen && NotificationService.active ? NotificationService.popups[0] || null : null
|
|
property bool owner: false
|
|
property bool hadLatest: false
|
|
onLatestChanged: {
|
|
if (latest && !hadLatest)
|
|
owner = ScreenService.active === barScreen;
|
|
hadLatest = !!latest;
|
|
if (latest)
|
|
notice = latest;
|
|
}
|
|
readonly property bool showing: !!latest && owner && visible
|
|
// Holds the last banner while the notch closes around it.
|
|
property var notice: null
|
|
readonly property int noticeWidth: 340
|
|
readonly property real bodyWidth: ShellState.notchPillWidth + (showing ? noticeWidth : 0)
|
|
implicitWidth: bodyWidth + 2 * BarDrawers.ear
|
|
implicitHeight: BarDrawers.bottom
|
|
Behavior on implicitWidth {
|
|
NumberAnimation {
|
|
duration: Theme.notchDuration * 1.6
|
|
easing.type: Easing.BezierSpline
|
|
easing.bezierCurve: [0.2, 0, 0, 1, 1, 1]
|
|
}
|
|
}
|
|
SystemClock {
|
|
id: clock
|
|
precision: SystemClock.Minutes
|
|
}
|
|
Demand {
|
|
service: CavaService
|
|
counter: "widgetConsumers"
|
|
active: root.visible && root.playing
|
|
}
|
|
DrawerShape {
|
|
bodyWidth: root.width - 2 * BarDrawers.ear
|
|
bodyHeight: root.height
|
|
ear: BarDrawers.ear
|
|
radius: Math.min(Theme.radius, root.height / 2)
|
|
fillColor: Theme.notchFill
|
|
}
|
|
// The pill's own width at the left end; its contents stay centred there.
|
|
Item {
|
|
id: lead
|
|
x: BarDrawers.ear
|
|
width: ShellState.notchPillWidth
|
|
height: root.height
|
|
}
|
|
Row {
|
|
id: content
|
|
anchors.centerIn: lead
|
|
spacing: 10
|
|
ClippingRectangle {
|
|
visible: root.playing
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 22
|
|
height: 22
|
|
radius: 6
|
|
color: Theme.fill
|
|
Image {
|
|
anchors.fill: parent
|
|
source: MediaService.artwork
|
|
sourceSize: Qt.size(44, 44)
|
|
fillMode: Image.PreserveAspectCrop
|
|
asynchronous: true
|
|
}
|
|
}
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: Qt.formatDateTime(clock.date, ConfigService.ready && !ConfigService.data.bar.clock.use24Hour ? "h:mm" : "HH:mm")
|
|
color: Theme.text
|
|
font.pixelSize: 14
|
|
font.weight: Font.DemiBold
|
|
font.features: {
|
|
"tnum": 1
|
|
}
|
|
}
|
|
Row {
|
|
visible: root.playing
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
height: 16
|
|
spacing: 2
|
|
Repeater {
|
|
model: 8
|
|
Rectangle {
|
|
required property int index
|
|
// Every third Cava band, so the eight span the spectrum.
|
|
readonly property real level: CavaService.bars[index * 3] || 0
|
|
width: 3
|
|
height: Math.max(3, 16 * level)
|
|
y: 16 - height
|
|
radius: 1.5
|
|
color: Theme.accent
|
|
}
|
|
}
|
|
}
|
|
}
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: BarDrawers.ear
|
|
anchors.rightMargin: BarDrawers.ear
|
|
cursorShape: Qt.PointingHandCursor
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
onClicked: mouse => {
|
|
if (mouse.button === Qt.RightButton)
|
|
MediaService.toggle();
|
|
else
|
|
ShellState.toggleNotch();
|
|
}
|
|
// Wheel changes the volume, as on pocket-dots.
|
|
onWheel: wheel => {
|
|
const audio = AudioService.sink ? AudioService.sink.audio : null;
|
|
const step = ConfigService.ready ? ConfigService.data.osd.step : 5;
|
|
if (audio && wheel.angleDelta.y !== 0)
|
|
AudioService.volume(false, audio.volume + (wheel.angleDelta.y > 0 ? 1 : -1) * step / 100);
|
|
}
|
|
}
|
|
Item {
|
|
id: banner
|
|
objectName: "notchNotice"
|
|
x: lead.x + lead.width
|
|
width: Math.max(0, root.width - BarDrawers.ear - x)
|
|
height: root.height
|
|
clip: true
|
|
visible: width > 1
|
|
opacity: root.showing ? 1 : 0
|
|
Behavior on opacity {
|
|
NumberAnimation {
|
|
duration: root.showing ? Theme.notchDuration * 1.6 : Theme.notchDuration * 0.6
|
|
easing.type: Easing.OutCubic
|
|
}
|
|
}
|
|
readonly property var n: root.notice
|
|
readonly property int more: Math.max(0, NotificationService.popups.length - 1)
|
|
Accessible.role: Accessible.Button
|
|
Accessible.name: n ? NotificationService.appLabel(n) + ": " + n.summary : ""
|
|
HoverHandler {
|
|
id: bannerHover
|
|
}
|
|
Rectangle {
|
|
anchors.left: parent.left
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 1
|
|
height: parent.height * 0.5
|
|
color: Theme.hairline
|
|
}
|
|
// Laid out at full width so text does not reflow while the notch grows.
|
|
Row {
|
|
x: 14
|
|
width: root.noticeWidth - 26
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
spacing: 10
|
|
Rectangle {
|
|
id: badge
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 30
|
|
height: 30
|
|
radius: 8
|
|
color: noticeIcon.status === Image.Ready ? Theme.transparent : Theme.surfaceVariant
|
|
border.width: banner.n && NotificationService.critical(banner.n) ? 1.5 : 0
|
|
border.color: Theme.urgent
|
|
Text {
|
|
anchors.centerIn: parent
|
|
visible: noticeIcon.status !== Image.Ready
|
|
text: Icons.available ? "" : "!"
|
|
font.family: Icons.available ? Icons.family : ""
|
|
color: Theme.text
|
|
font.pixelSize: 15
|
|
}
|
|
Image {
|
|
id: noticeIcon
|
|
anchors.fill: parent
|
|
source: banner.n ? NotificationService.iconFor(banner.n) || NotificationService.imageFor(banner.n) : ""
|
|
sourceSize: Qt.size(60, 60)
|
|
fillMode: Image.PreserveAspectFit
|
|
asynchronous: true
|
|
smooth: true
|
|
mipmap: true
|
|
}
|
|
}
|
|
Column {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: parent.width - badge.width - parent.spacing - (count.visible ? count.width + parent.spacing : 0)
|
|
spacing: 1
|
|
Text {
|
|
objectName: "notchNoticeSummary"
|
|
width: parent.width
|
|
text: banner.n ? banner.n.summary || NotificationService.appLabel(banner.n) : ""
|
|
color: Theme.text
|
|
font.pixelSize: 13
|
|
font.weight: Font.DemiBold
|
|
elide: Text.ElideRight
|
|
maximumLineCount: 1
|
|
}
|
|
Text {
|
|
width: parent.width
|
|
visible: text !== ""
|
|
// Bodies may carry markup and line breaks; one plain line fits here.
|
|
text: banner.n ? (banner.n.body || NotificationService.appLabel(banner.n)).replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim() : ""
|
|
color: Theme.textSecondary
|
|
font.pixelSize: 12
|
|
elide: Text.ElideRight
|
|
maximumLineCount: 1
|
|
textFormat: Text.PlainText
|
|
}
|
|
}
|
|
Rectangle {
|
|
id: count
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
visible: banner.more > 0
|
|
width: Math.max(22, moreText.implicitWidth + 12)
|
|
height: 20
|
|
radius: 10
|
|
color: Theme.surfaceVariant
|
|
Text {
|
|
id: moreText
|
|
anchors.centerIn: parent
|
|
text: "+" + banner.more
|
|
color: Theme.textSecondary
|
|
font.pixelSize: 11
|
|
font.weight: Font.Medium
|
|
}
|
|
}
|
|
}
|
|
// Left click runs the default action; right or middle click sends it to
|
|
// the notch's list.
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
enabled: root.showing
|
|
cursorShape: Qt.PointingHandCursor
|
|
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
|
|
onClicked: mouse => {
|
|
if (mouse.button === Qt.LeftButton)
|
|
NotificationService.activate(banner.n);
|
|
else
|
|
NotificationService.hidePopup(banner.n);
|
|
}
|
|
}
|
|
}
|
|
// 0 (critical) stays until dismissed. Each banner's time counts from its
|
|
// arrival, so older ones revealed by an expiry leave on schedule; hovering
|
|
// restarts the full time.
|
|
readonly property int lifetime: notice ? NotificationService.timeoutFor(notice) : 0
|
|
property int budget: 1
|
|
function arm(full) {
|
|
if (!showing || lifetime <= 0 || bannerHover.hovered)
|
|
return;
|
|
const at = NotificationService.times[notice.id];
|
|
budget = Math.max(400, full || at === undefined ? lifetime : lifetime - (Date.now() - at));
|
|
life.restart();
|
|
}
|
|
Timer {
|
|
id: life
|
|
interval: root.budget
|
|
running: root.showing && root.lifetime > 0 && !bannerHover.hovered
|
|
onTriggered: if (root.showing)
|
|
NotificationService.hidePopup(root.notice)
|
|
}
|
|
onNoticeChanged: arm(false)
|
|
onShowingChanged: arm(false)
|
|
Connections {
|
|
target: bannerHover
|
|
function onHoveredChanged() {
|
|
if (!bannerHover.hovered)
|
|
root.arm(true);
|
|
}
|
|
}
|
|
Connections {
|
|
target: NotificationService
|
|
function onPopupShown(n) {
|
|
if (n === root.notice)
|
|
root.arm(true);
|
|
}
|
|
}
|
|
}
|