extract NotifApplet, fold NotifCenter into NotificationsModule with hover+pin
This commit is contained in:
parent
472b4e62ab
commit
c1588ceb5e
5 changed files with 106 additions and 123 deletions
|
|
@ -3,21 +3,32 @@ import Quickshell
|
|||
import Quickshell.Services.Notifications
|
||||
import "." as M
|
||||
import "../services" as S
|
||||
import "../applets" as C
|
||||
|
||||
M.BarSection {
|
||||
id: root
|
||||
spacing: S.Theme.moduleSpacing
|
||||
tooltip: {
|
||||
const parts = [S.NotifService.count + " notification" + (S.NotifService.count !== 1 ? "s" : "")];
|
||||
if (S.NotifService.dnd)
|
||||
parts.push("Do not disturb");
|
||||
return parts.join("\n");
|
||||
}
|
||||
|
||||
required property var bar
|
||||
tooltip: ""
|
||||
|
||||
readonly property bool hasUrgent: S.NotifService.list.some(n => n.urgency === NotificationUrgency.Critical && n.state !== "dismissed")
|
||||
|
||||
property bool _pinned: false
|
||||
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
|
||||
readonly property bool _showPanel: _anyHover || _pinned
|
||||
|
||||
on_AnyHoverChanged: {
|
||||
if (_anyHover)
|
||||
_unpinTimer.stop();
|
||||
else if (_pinned)
|
||||
_unpinTimer.start();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: _unpinTimer
|
||||
interval: 500
|
||||
onTriggered: root._pinned = false
|
||||
}
|
||||
|
||||
M.BarIcon {
|
||||
icon: {
|
||||
if (S.NotifService.dnd)
|
||||
|
|
@ -26,12 +37,18 @@ M.BarSection {
|
|||
}
|
||||
color: S.NotifService.dnd ? S.Theme.base04 : root.accentColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
TapHandler {
|
||||
onTapped: root._pinned = !root._pinned
|
||||
}
|
||||
}
|
||||
M.BarLabel {
|
||||
id: countLabel
|
||||
label: S.NotifService.count > 0 ? String(S.NotifService.count) + (root.hasUrgent ? "!" : "") : ""
|
||||
color: root.hasUrgent ? S.Theme.base08 : root.accentColor
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
TapHandler {
|
||||
onTapped: root._pinned = !root._pinned
|
||||
}
|
||||
|
||||
transform: Scale {
|
||||
id: countScale
|
||||
|
|
@ -68,26 +85,66 @@ M.BarSection {
|
|||
}
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onTapped: {
|
||||
centerLoader.active = !centerLoader.active;
|
||||
M.FlyoutState.visible = false;
|
||||
}
|
||||
}
|
||||
// Right-click DND quick toggle
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
onTapped: S.NotifService.toggleDnd()
|
||||
}
|
||||
|
||||
LazyLoader {
|
||||
id: centerLoader
|
||||
active: false
|
||||
M.NotifCenter {
|
||||
M.HoverPanel {
|
||||
id: hoverPanel
|
||||
showPanel: root._showPanel
|
||||
screen: QsWindow.window?.screen ?? null
|
||||
anchorItem: root
|
||||
accentColor: root.accentColor
|
||||
panelNamespace: "nova-notifications"
|
||||
panelTitle: "Notifications"
|
||||
contentWidth: 350
|
||||
titleActionsComponent: Component {
|
||||
Row {
|
||||
spacing: 8
|
||||
|
||||
// DND toggle
|
||||
Text {
|
||||
text: S.NotifService.dnd ? "\uDB82\uDE93" : "\uDB80\uDC9C"
|
||||
color: S.NotifService.dnd ? S.Theme.base09 : S.Theme.base04
|
||||
font.pixelSize: S.Theme.fontSize
|
||||
font.family: S.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
HoverHandler {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
}
|
||||
TapHandler {
|
||||
onTapped: S.NotifService.toggleDnd()
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all
|
||||
Text {
|
||||
text: "\uF1F8"
|
||||
color: _clearHover.hovered ? S.Theme.base08 : S.Theme.base04
|
||||
font.pixelSize: S.Theme.fontSize
|
||||
font.family: S.Theme.iconFontFamily
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: S.NotifService.count > 0
|
||||
|
||||
HoverHandler {
|
||||
id: _clearHover
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
}
|
||||
TapHandler {
|
||||
onTapped: _notifApplet.cascadeDismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.NotifApplet {
|
||||
id: _notifApplet
|
||||
width: hoverPanel.contentWidth
|
||||
contentWidth: hoverPanel.contentWidth
|
||||
accentColor: root.accentColor
|
||||
screen: root.bar.screen
|
||||
anchorX: root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0)
|
||||
onDismissed: centerLoader.active = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue