mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-27 06:52:50 -05:00
switch hto monorepo structure
This commit is contained in:
718
quickshell/Modules/Notifications/Popup/NotificationPopup.qml
Normal file
718
quickshell/Modules/Notifications/Popup/NotificationPopup.qml
Normal file
@@ -0,0 +1,718 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Effects
|
||||
import QtQuick.Shapes
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Services.Notifications
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
PanelWindow {
|
||||
id: win
|
||||
|
||||
WlrLayershell.namespace: "dms:notification-popup"
|
||||
|
||||
required property var notificationData
|
||||
required property string notificationId
|
||||
readonly property bool hasValidData: notificationData && notificationData.notification
|
||||
property int screenY: 0
|
||||
property bool exiting: false
|
||||
property bool _isDestroying: false
|
||||
property bool _finalized: false
|
||||
readonly property string clearText: I18n.tr("Dismiss")
|
||||
|
||||
signal entered
|
||||
signal exitFinished
|
||||
|
||||
function startExit() {
|
||||
if (exiting || _isDestroying) {
|
||||
return
|
||||
}
|
||||
exiting = true
|
||||
exitAnim.restart()
|
||||
exitWatchdog.restart()
|
||||
if (NotificationService.removeFromVisibleNotifications)
|
||||
NotificationService.removeFromVisibleNotifications(win.notificationData)
|
||||
}
|
||||
|
||||
function forceExit() {
|
||||
if (_isDestroying) {
|
||||
return
|
||||
}
|
||||
_isDestroying = true
|
||||
exiting = true
|
||||
visible = false
|
||||
exitWatchdog.stop()
|
||||
finalizeExit("forced")
|
||||
}
|
||||
|
||||
function finalizeExit(reason) {
|
||||
if (_finalized) {
|
||||
return
|
||||
}
|
||||
|
||||
_finalized = true
|
||||
_isDestroying = true
|
||||
exitWatchdog.stop()
|
||||
wrapperConn.enabled = false
|
||||
wrapperConn.target = null
|
||||
win.exitFinished()
|
||||
}
|
||||
|
||||
visible: hasValidData
|
||||
WlrLayershell.layer: {
|
||||
const envLayer = Quickshell.env("DMS_NOTIFICATION_LAYER")
|
||||
if (envLayer) {
|
||||
switch (envLayer) {
|
||||
case "bottom":
|
||||
return WlrLayershell.Bottom
|
||||
case "overlay":
|
||||
return WlrLayershell.Overlay
|
||||
case "background":
|
||||
return WlrLayershell.Background
|
||||
case "top":
|
||||
return WlrLayershell.Top
|
||||
}
|
||||
}
|
||||
|
||||
if (!notificationData)
|
||||
return WlrLayershell.Top
|
||||
|
||||
SettingsData.notificationOverlayEnabled
|
||||
|
||||
const shouldUseOverlay = (SettingsData.notificationOverlayEnabled) || (notificationData.urgency === NotificationUrgency.Critical)
|
||||
|
||||
return shouldUseOverlay ? WlrLayershell.Overlay : WlrLayershell.Top
|
||||
}
|
||||
WlrLayershell.exclusiveZone: -1
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||||
color: "transparent"
|
||||
implicitWidth: 400
|
||||
implicitHeight: 122
|
||||
onHasValidDataChanged: {
|
||||
if (!hasValidData && !exiting && !_isDestroying) {
|
||||
forceExit()
|
||||
}
|
||||
}
|
||||
Component.onCompleted: {
|
||||
if (hasValidData) {
|
||||
Qt.callLater(() => enterX.restart())
|
||||
} else {
|
||||
forceExit()
|
||||
}
|
||||
}
|
||||
onNotificationDataChanged: {
|
||||
if (!_isDestroying) {
|
||||
wrapperConn.target = win.notificationData || null
|
||||
notificationConn.target = (win.notificationData && win.notificationData.notification && win.notificationData.notification.Retainable) || null
|
||||
}
|
||||
}
|
||||
onEntered: {
|
||||
if (!_isDestroying) {
|
||||
enterDelay.start()
|
||||
}
|
||||
}
|
||||
Component.onDestruction: {
|
||||
_isDestroying = true
|
||||
exitWatchdog.stop()
|
||||
if (notificationData && notificationData.timer) {
|
||||
notificationData.timer.stop()
|
||||
}
|
||||
}
|
||||
|
||||
property bool isTopCenter: SettingsData.notificationPopupPosition === -1
|
||||
|
||||
anchors.top: isTopCenter || SettingsData.notificationPopupPosition === SettingsData.Position.Top || SettingsData.notificationPopupPosition === SettingsData.Position.Left
|
||||
anchors.bottom: SettingsData.notificationPopupPosition === SettingsData.Position.Bottom || SettingsData.notificationPopupPosition === SettingsData.Position.Right
|
||||
anchors.left: SettingsData.notificationPopupPosition === SettingsData.Position.Left || SettingsData.notificationPopupPosition === SettingsData.Position.Bottom
|
||||
anchors.right: SettingsData.notificationPopupPosition === SettingsData.Position.Top || SettingsData.notificationPopupPosition === SettingsData.Position.Right
|
||||
|
||||
margins {
|
||||
top: getTopMargin()
|
||||
bottom: getBottomMargin()
|
||||
left: getLeftMargin()
|
||||
right: getRightMargin()
|
||||
}
|
||||
|
||||
function getTopMargin() {
|
||||
const popupPos = SettingsData.notificationPopupPosition
|
||||
const barPos = SettingsData.dankBarPosition
|
||||
const isTop = isTopCenter || popupPos === SettingsData.Position.Top || popupPos === SettingsData.Position.Left
|
||||
|
||||
if (!isTop) return 0
|
||||
|
||||
const effectiveBarThickness = Math.max(26 + SettingsData.dankBarInnerPadding * 0.6 + SettingsData.dankBarInnerPadding + 4, Theme.barHeight - 4 - (8 - SettingsData.dankBarInnerPadding))
|
||||
const exclusiveZone = effectiveBarThickness + SettingsData.dankBarSpacing + SettingsData.dankBarBottomGap
|
||||
|
||||
let base = Theme.popupDistance
|
||||
if (barPos === SettingsData.Position.Top) {
|
||||
base = exclusiveZone
|
||||
}
|
||||
|
||||
return base + screenY
|
||||
}
|
||||
|
||||
function getBottomMargin() {
|
||||
const popupPos = SettingsData.notificationPopupPosition
|
||||
const barPos = SettingsData.dankBarPosition
|
||||
const isBottom = popupPos === SettingsData.Position.Bottom || popupPos === SettingsData.Position.Right
|
||||
|
||||
if (!isBottom) return 0
|
||||
|
||||
const effectiveBarThickness = Math.max(26 + SettingsData.dankBarInnerPadding * 0.6 + SettingsData.dankBarInnerPadding + 4, Theme.barHeight - 4 - (8 - SettingsData.dankBarInnerPadding))
|
||||
const exclusiveZone = effectiveBarThickness + SettingsData.dankBarSpacing + SettingsData.dankBarBottomGap
|
||||
|
||||
let base = Theme.popupDistance
|
||||
if (barPos === SettingsData.Position.Bottom) {
|
||||
base = exclusiveZone
|
||||
}
|
||||
|
||||
return base + screenY
|
||||
}
|
||||
|
||||
function getLeftMargin() {
|
||||
if (isTopCenter) {
|
||||
return (screen.width - implicitWidth) / 2
|
||||
}
|
||||
|
||||
const popupPos = SettingsData.notificationPopupPosition
|
||||
const barPos = SettingsData.dankBarPosition
|
||||
const isLeft = popupPos === SettingsData.Position.Left || popupPos === SettingsData.Position.Bottom
|
||||
|
||||
if (!isLeft) return 0
|
||||
|
||||
const effectiveBarThickness = Math.max(26 + SettingsData.dankBarInnerPadding * 0.6 + SettingsData.dankBarInnerPadding + 4, Theme.barHeight - 4 - (8 - SettingsData.dankBarInnerPadding))
|
||||
const exclusiveZone = effectiveBarThickness + SettingsData.dankBarSpacing + SettingsData.dankBarBottomGap
|
||||
|
||||
if (barPos === SettingsData.Position.Left) {
|
||||
return exclusiveZone
|
||||
}
|
||||
|
||||
return Theme.popupDistance
|
||||
}
|
||||
|
||||
function getRightMargin() {
|
||||
if (isTopCenter) return 0
|
||||
|
||||
const popupPos = SettingsData.notificationPopupPosition
|
||||
const barPos = SettingsData.dankBarPosition
|
||||
const isRight = popupPos === SettingsData.Position.Top || popupPos === SettingsData.Position.Right
|
||||
|
||||
if (!isRight) return 0
|
||||
|
||||
const effectiveBarThickness = Math.max(26 + SettingsData.dankBarInnerPadding * 0.6 + SettingsData.dankBarInnerPadding + 4, Theme.barHeight - 4 - (8 - SettingsData.dankBarInnerPadding))
|
||||
const exclusiveZone = effectiveBarThickness + SettingsData.dankBarSpacing + SettingsData.dankBarBottomGap
|
||||
|
||||
if (barPos === SettingsData.Position.Right) {
|
||||
return exclusiveZone
|
||||
}
|
||||
|
||||
return Theme.popupDistance
|
||||
}
|
||||
|
||||
readonly property real dpr: CompositorService.getScreenScale(win.screen)
|
||||
readonly property real alignedWidth: Theme.px(implicitWidth, dpr)
|
||||
readonly property real alignedHeight: Theme.px(implicitHeight, dpr)
|
||||
|
||||
Item {
|
||||
id: content
|
||||
|
||||
x: Theme.snap((win.width - alignedWidth) / 2, dpr)
|
||||
y: Theme.snap((win.height - alignedHeight) / 2, dpr)
|
||||
width: alignedWidth
|
||||
height: alignedHeight
|
||||
visible: win.hasValidData
|
||||
|
||||
property real shadowBlurPx: 10
|
||||
property real shadowSpreadPx: 0
|
||||
property real shadowBaseAlpha: 0.60
|
||||
readonly property real popupSurfaceAlpha: SettingsData.popupTransparency
|
||||
readonly property real effectiveShadowAlpha: Math.max(0, Math.min(1, shadowBaseAlpha * popupSurfaceAlpha))
|
||||
|
||||
Item {
|
||||
id: bgShadowLayer
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.snap(4, win.dpr)
|
||||
layer.enabled: true
|
||||
layer.smooth: false
|
||||
layer.textureSize: Qt.size(Math.round(width * win.dpr), Math.round(height * win.dpr))
|
||||
layer.textureMirroring: ShaderEffectSource.MirrorVertically
|
||||
|
||||
layer.effect: MultiEffect {
|
||||
id: shadowFx
|
||||
autoPaddingEnabled: true
|
||||
shadowEnabled: true
|
||||
blurEnabled: false
|
||||
maskEnabled: false
|
||||
property int blurMax: 64
|
||||
shadowBlur: Math.max(0, Math.min(1, content.shadowBlurPx / blurMax))
|
||||
shadowScale: 1 + (2 * content.shadowSpreadPx) / Math.max(1, Math.min(bgShadowLayer.width, bgShadowLayer.height))
|
||||
shadowColor: Qt.rgba(0, 0, 0, content.effectiveShadowAlpha)
|
||||
}
|
||||
|
||||
Shape {
|
||||
id: backgroundShape
|
||||
anchors.fill: parent
|
||||
preferredRendererType: Shape.CurveRenderer
|
||||
|
||||
readonly property real radius: Theme.cornerRadius
|
||||
readonly property color fillColor: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
||||
readonly property color strokeColor: notificationData && notificationData.urgency === NotificationUrgency.Critical ? Theme.withAlpha(Theme.primary, 0.3) : Theme.withAlpha(Theme.outline, 0.08)
|
||||
readonly property real strokeWidth: notificationData && notificationData.urgency === NotificationUrgency.Critical ? 2 : 0
|
||||
|
||||
ShapePath {
|
||||
fillColor: backgroundShape.fillColor
|
||||
strokeColor: backgroundShape.strokeColor
|
||||
strokeWidth: backgroundShape.strokeWidth
|
||||
|
||||
startX: backgroundShape.radius
|
||||
startY: 0
|
||||
|
||||
PathLine { x: backgroundShape.width - backgroundShape.radius; y: 0 }
|
||||
PathQuad { x: backgroundShape.width; y: backgroundShape.radius; controlX: backgroundShape.width; controlY: 0 }
|
||||
PathLine { x: backgroundShape.width; y: backgroundShape.height - backgroundShape.radius }
|
||||
PathQuad { x: backgroundShape.width - backgroundShape.radius; y: backgroundShape.height; controlX: backgroundShape.width; controlY: backgroundShape.height }
|
||||
PathLine { x: backgroundShape.radius; y: backgroundShape.height }
|
||||
PathQuad { x: 0; y: backgroundShape.height - backgroundShape.radius; controlX: 0; controlY: backgroundShape.height }
|
||||
PathLine { x: 0; y: backgroundShape.radius }
|
||||
PathQuad { x: backgroundShape.radius; y: 0; controlX: 0; controlY: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: backgroundShape.radius
|
||||
visible: notificationData && notificationData.urgency === NotificationUrgency.Critical
|
||||
opacity: 1
|
||||
clip: true
|
||||
|
||||
gradient: Gradient {
|
||||
orientation: Gradient.Horizontal
|
||||
|
||||
GradientStop {
|
||||
position: 0
|
||||
color: Theme.primary
|
||||
}
|
||||
|
||||
GradientStop {
|
||||
position: 0.02
|
||||
color: Theme.primary
|
||||
}
|
||||
|
||||
GradientStop {
|
||||
position: 0.021
|
||||
color: "transparent"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: backgroundContainer
|
||||
anchors.fill: parent
|
||||
anchors.margins: Theme.snap(4, win.dpr)
|
||||
clip: true
|
||||
|
||||
Item {
|
||||
id: notificationContent
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.topMargin: 12
|
||||
anchors.leftMargin: 16
|
||||
anchors.rightMargin: 56
|
||||
height: 98
|
||||
|
||||
DankCircularImage {
|
||||
id: iconContainer
|
||||
|
||||
readonly property bool hasNotificationImage: notificationData && notificationData.image && notificationData.image !== ""
|
||||
|
||||
width: 63
|
||||
height: 63
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
imageSource: {
|
||||
if (!notificationData)
|
||||
return ""
|
||||
|
||||
if (hasNotificationImage)
|
||||
return notificationData.cleanImage || ""
|
||||
|
||||
if (notificationData.appIcon) {
|
||||
const appIcon = notificationData.appIcon
|
||||
if (appIcon.startsWith("file://") || appIcon.startsWith("http://") || appIcon.startsWith("https://"))
|
||||
return appIcon
|
||||
|
||||
return Quickshell.iconPath(appIcon, true)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
hasImage: hasNotificationImage
|
||||
fallbackIcon: ""
|
||||
fallbackText: {
|
||||
const appName = notificationData?.appName || "?"
|
||||
return appName.charAt(0).toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: textContainer
|
||||
|
||||
anchors.left: iconContainer.right
|
||||
anchors.leftMargin: 12
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 0
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
color: "transparent"
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: -2
|
||||
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: 2
|
||||
|
||||
StyledText {
|
||||
width: parent.width
|
||||
text: {
|
||||
if (!notificationData)
|
||||
return ""
|
||||
|
||||
const appName = notificationData.appName || ""
|
||||
const timeStr = notificationData.timeStr || ""
|
||||
if (timeStr.length > 0)
|
||||
return appName + " • " + timeStr
|
||||
else
|
||||
return appName
|
||||
}
|
||||
color: Theme.surfaceVariantText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.weight: Font.Medium
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: notificationData ? (notificationData.summary || "") : ""
|
||||
color: Theme.surfaceText
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: Font.Medium
|
||||
width: parent.width
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
visible: text.length > 0
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: notificationData ? (notificationData.htmlBody || "") : ""
|
||||
color: Theme.surfaceVariantText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
width: parent.width
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 2
|
||||
wrapMode: Text.WordWrap
|
||||
visible: text.length > 0
|
||||
linkColor: Theme.primary
|
||||
onLinkActivated: link => {
|
||||
return Qt.openUrlExternally(link)
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.NoButton
|
||||
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DankActionButton {
|
||||
id: closeButton
|
||||
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 12
|
||||
anchors.rightMargin: 16
|
||||
iconName: "close"
|
||||
iconSize: 18
|
||||
buttonSize: 28
|
||||
z: 15
|
||||
onClicked: {
|
||||
if (notificationData && !win.exiting)
|
||||
notificationData.popup = false
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.right: clearButton.left
|
||||
anchors.rightMargin: 8
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
spacing: 8
|
||||
z: 20
|
||||
|
||||
Repeater {
|
||||
model: notificationData ? (notificationData.actions || []) : []
|
||||
|
||||
Rectangle {
|
||||
property bool isHovered: false
|
||||
|
||||
width: Math.max(actionText.implicitWidth + 12, 50)
|
||||
height: 24
|
||||
radius: 4
|
||||
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
|
||||
|
||||
StyledText {
|
||||
id: actionText
|
||||
|
||||
text: modelData.text || "View"
|
||||
color: parent.isHovered ? Theme.primary : Theme.surfaceVariantText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.weight: Font.Medium
|
||||
anchors.centerIn: parent
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onEntered: parent.isHovered = true
|
||||
onExited: parent.isHovered = false
|
||||
onClicked: {
|
||||
if (modelData && modelData.invoke)
|
||||
modelData.invoke()
|
||||
|
||||
if (notificationData && !win.exiting)
|
||||
notificationData.popup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: clearButton
|
||||
|
||||
property bool isHovered: false
|
||||
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 16
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
width: Math.max(clearTextLabel.implicitWidth + 12, 50)
|
||||
height: 24
|
||||
radius: 4
|
||||
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
|
||||
z: 20
|
||||
|
||||
StyledText {
|
||||
id: clearTextLabel
|
||||
|
||||
text: win.clearText
|
||||
color: clearButton.isHovered ? Theme.primary : Theme.surfaceVariantText
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
font.weight: Font.Medium
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onEntered: clearButton.isHovered = true
|
||||
onExited: clearButton.isHovered = false
|
||||
onClicked: {
|
||||
if (notificationData && !win.exiting)
|
||||
NotificationService.dismissNotification(notificationData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: cardHoverArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
propagateComposedEvents: true
|
||||
z: -1
|
||||
onEntered: {
|
||||
if (notificationData && notificationData.timer)
|
||||
notificationData.timer.stop()
|
||||
}
|
||||
onExited: {
|
||||
if (notificationData && notificationData.popup && notificationData.timer)
|
||||
notificationData.timer.restart()
|
||||
}
|
||||
onClicked: (mouse) => {
|
||||
if (!notificationData || win.exiting)
|
||||
return
|
||||
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
NotificationService.dismissNotification(notificationData)
|
||||
} else if (mouse.button === Qt.LeftButton) {
|
||||
if (notificationData.actions && notificationData.actions.length > 0) {
|
||||
notificationData.actions[0].invoke()
|
||||
NotificationService.dismissNotification(notificationData)
|
||||
} else {
|
||||
notificationData.popup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transform: Translate {
|
||||
id: tx
|
||||
|
||||
x: {
|
||||
if (isTopCenter) return 0
|
||||
const isLeft = SettingsData.notificationPopupPosition === SettingsData.Position.Left || SettingsData.notificationPopupPosition === SettingsData.Position.Bottom
|
||||
return isLeft ? -Anims.slidePx : Anims.slidePx
|
||||
}
|
||||
y: isTopCenter ? -Anims.slidePx : 0
|
||||
}
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
id: enterX
|
||||
|
||||
target: tx
|
||||
property: isTopCenter ? "y" : "x"
|
||||
from: {
|
||||
if (isTopCenter) return -Anims.slidePx
|
||||
const isLeft = SettingsData.notificationPopupPosition === SettingsData.Position.Left || SettingsData.notificationPopupPosition === SettingsData.Position.Bottom
|
||||
return isLeft ? -Anims.slidePx : Anims.slidePx
|
||||
}
|
||||
to: 0
|
||||
duration: Anims.durMed
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: isTopCenter ? Anims.standardDecel : Anims.emphasizedDecel
|
||||
onStopped: {
|
||||
if (!win.exiting && !win._isDestroying) {
|
||||
if (isTopCenter) {
|
||||
if (Math.abs(tx.y) < 0.5) win.entered()
|
||||
} else {
|
||||
if (Math.abs(tx.x) < 0.5) win.entered()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParallelAnimation {
|
||||
id: exitAnim
|
||||
|
||||
onStopped: finalizeExit("animStopped")
|
||||
|
||||
PropertyAnimation {
|
||||
target: tx
|
||||
property: isTopCenter ? "y" : "x"
|
||||
from: 0
|
||||
to: {
|
||||
if (isTopCenter) return -Anims.slidePx
|
||||
const isLeft = SettingsData.notificationPopupPosition === SettingsData.Position.Left || SettingsData.notificationPopupPosition === SettingsData.Position.Bottom
|
||||
return isLeft ? -Anims.slidePx : Anims.slidePx
|
||||
}
|
||||
duration: Anims.durShort
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Anims.emphasizedAccel
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
target: content
|
||||
property: "opacity"
|
||||
from: 1
|
||||
to: 0
|
||||
duration: Anims.durShort
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Anims.standardAccel
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
target: content
|
||||
property: "scale"
|
||||
from: 1
|
||||
to: 0.98
|
||||
duration: Anims.durShort
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Anims.emphasizedAccel
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: wrapperConn
|
||||
|
||||
function onPopupChanged() {
|
||||
if (!win.notificationData || win._isDestroying)
|
||||
return
|
||||
|
||||
if (!win.notificationData.popup && !win.exiting)
|
||||
startExit()
|
||||
}
|
||||
|
||||
target: win.notificationData || null
|
||||
ignoreUnknownSignals: true
|
||||
enabled: !win._isDestroying
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: notificationConn
|
||||
|
||||
function onDropped() {
|
||||
if (!win._isDestroying && !win.exiting)
|
||||
forceExit()
|
||||
}
|
||||
|
||||
target: (win.notificationData && win.notificationData.notification && win.notificationData.notification.Retainable) || null
|
||||
ignoreUnknownSignals: true
|
||||
enabled: !win._isDestroying
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: enterDelay
|
||||
|
||||
interval: 160
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (notificationData && notificationData.timer && !exiting && !_isDestroying)
|
||||
notificationData.timer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: exitWatchdog
|
||||
|
||||
interval: 600
|
||||
repeat: false
|
||||
onTriggered: finalizeExit("watchdog")
|
||||
}
|
||||
|
||||
Behavior on screenY {
|
||||
id: screenYAnim
|
||||
|
||||
enabled: !exiting && !_isDestroying
|
||||
|
||||
NumberAnimation {
|
||||
duration: Anims.durShort
|
||||
easing.type: Easing.BezierSpline
|
||||
easing.bezierCurve: Anims.standardDecel
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
|
||||
QtObject {
|
||||
id: manager
|
||||
|
||||
property var modelData
|
||||
property int topMargin: 0
|
||||
property int baseNotificationHeight: 120
|
||||
property int maxTargetNotifications: 4
|
||||
property var popupWindows: [] // strong refs to windows (live until exitFinished)
|
||||
property var destroyingWindows: new Set()
|
||||
property Component popupComponent
|
||||
|
||||
popupComponent: Component {
|
||||
NotificationPopup {
|
||||
onEntered: manager._onPopupEntered(this)
|
||||
onExitFinished: manager._onPopupExitFinished(this)
|
||||
}
|
||||
}
|
||||
|
||||
property Connections notificationConnections
|
||||
|
||||
notificationConnections: Connections {
|
||||
function onVisibleNotificationsChanged() {
|
||||
manager._sync(NotificationService.visibleNotifications)
|
||||
}
|
||||
|
||||
target: NotificationService
|
||||
}
|
||||
|
||||
property Timer sweeper
|
||||
|
||||
sweeper: Timer {
|
||||
interval: 500
|
||||
running: false
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
const toRemove = []
|
||||
for (const p of popupWindows) {
|
||||
if (!p) {
|
||||
toRemove.push(p)
|
||||
continue
|
||||
}
|
||||
const isZombie = p.status === Component.Null || (!p.visible && !p.exiting) || (!p.notificationData && !p._isDestroying) || (!p.hasValidData && !p._isDestroying)
|
||||
if (isZombie) {
|
||||
toRemove.push(p)
|
||||
if (p.forceExit) {
|
||||
p.forceExit()
|
||||
} else if (p.destroy) {
|
||||
try {
|
||||
p.destroy()
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toRemove.length) {
|
||||
popupWindows = popupWindows.filter(p => toRemove.indexOf(p) === -1)
|
||||
const survivors = _active().sort((a, b) => a.screenY - b.screenY)
|
||||
for (let k = 0; k < survivors.length; ++k) {
|
||||
survivors[k].screenY = topMargin + k * baseNotificationHeight
|
||||
}
|
||||
}
|
||||
if (popupWindows.length === 0) {
|
||||
sweeper.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _hasWindowFor(w) {
|
||||
return popupWindows.some(p => p && p.notificationData === w && !p._isDestroying && p.status !== Component.Null)
|
||||
}
|
||||
|
||||
function _isValidWindow(p) {
|
||||
return p && p.status !== Component.Null && !p._isDestroying && p.hasValidData
|
||||
}
|
||||
|
||||
function _canMakeRoomFor(wrapper) {
|
||||
const activeWindows = _active()
|
||||
if (activeWindows.length < maxTargetNotifications) {
|
||||
return true
|
||||
}
|
||||
if (!wrapper || !wrapper.notification) {
|
||||
return false
|
||||
}
|
||||
const incomingUrgency = wrapper.notification.urgency || 0
|
||||
for (const p of activeWindows) {
|
||||
if (!p.notificationData || !p.notificationData.notification) {
|
||||
continue
|
||||
}
|
||||
const existingUrgency = p.notificationData.notification.urgency || 0
|
||||
if (existingUrgency < incomingUrgency) {
|
||||
return true
|
||||
}
|
||||
if (existingUrgency === incomingUrgency) {
|
||||
const timer = p.notificationData.timer
|
||||
if (timer && !timer.running) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function _makeRoomForNew(wrapper) {
|
||||
const activeWindows = _active()
|
||||
if (activeWindows.length < maxTargetNotifications) {
|
||||
return
|
||||
}
|
||||
const toRemove = _selectPopupToRemove(activeWindows, wrapper)
|
||||
if (toRemove && !toRemove.exiting) {
|
||||
toRemove.notificationData.removedByLimit = true
|
||||
toRemove.notificationData.popup = false
|
||||
if (toRemove.notificationData.timer) {
|
||||
toRemove.notificationData.timer.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _selectPopupToRemove(activeWindows, incomingWrapper) {
|
||||
const incomingUrgency = (incomingWrapper && incomingWrapper.notification) ? incomingWrapper.notification.urgency || 0 : 0
|
||||
const sortedWindows = activeWindows.slice().sort((a, b) => {
|
||||
const aUrgency = (a.notificationData && a.notificationData.notification) ? a.notificationData.notification.urgency || 0 : 0
|
||||
const bUrgency = (b.notificationData && b.notificationData.notification) ? b.notificationData.notification.urgency || 0 : 0
|
||||
if (aUrgency !== bUrgency) {
|
||||
return aUrgency - bUrgency
|
||||
}
|
||||
const aTimer = a.notificationData && a.notificationData.timer
|
||||
const bTimer = b.notificationData && b.notificationData.timer
|
||||
const aRunning = aTimer && aTimer.running
|
||||
const bRunning = bTimer && bTimer.running
|
||||
if (aRunning !== bRunning) {
|
||||
return aRunning ? 1 : -1
|
||||
}
|
||||
return b.screenY - a.screenY
|
||||
})
|
||||
return sortedWindows[0]
|
||||
}
|
||||
|
||||
function _sync(newWrappers) {
|
||||
for (const w of newWrappers) {
|
||||
if (w && !_hasWindowFor(w)) {
|
||||
insertNewestAtTop(w)
|
||||
}
|
||||
}
|
||||
for (const p of popupWindows.slice()) {
|
||||
if (!_isValidWindow(p)) {
|
||||
continue
|
||||
}
|
||||
if (p.notificationData && newWrappers.indexOf(p.notificationData) === -1 && !p.exiting) {
|
||||
p.notificationData.removedByLimit = true
|
||||
p.notificationData.popup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function insertNewestAtTop(wrapper) {
|
||||
if (!wrapper) {
|
||||
return
|
||||
}
|
||||
for (const p of popupWindows) {
|
||||
if (!_isValidWindow(p)) {
|
||||
continue
|
||||
}
|
||||
if (p.exiting) {
|
||||
continue
|
||||
}
|
||||
p.screenY = p.screenY + baseNotificationHeight
|
||||
}
|
||||
const notificationId = wrapper && wrapper.notification ? wrapper.notification.id : ""
|
||||
const win = popupComponent.createObject(null, {
|
||||
"notificationData": wrapper,
|
||||
"notificationId": notificationId,
|
||||
"screenY": topMargin,
|
||||
"screen": manager.modelData
|
||||
})
|
||||
if (!win) {
|
||||
return
|
||||
}
|
||||
if (!win.hasValidData) {
|
||||
win.destroy()
|
||||
return
|
||||
}
|
||||
popupWindows.push(win)
|
||||
if (!sweeper.running) {
|
||||
sweeper.start()
|
||||
}
|
||||
}
|
||||
|
||||
function _active() {
|
||||
return popupWindows.filter(p => _isValidWindow(p) && p.notificationData && p.notificationData.popup && !p.exiting)
|
||||
}
|
||||
|
||||
function _bottom() {
|
||||
let b = null
|
||||
let maxY = -1
|
||||
for (const p of _active()) {
|
||||
if (p.screenY > maxY) {
|
||||
maxY = p.screenY
|
||||
b = p
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
function _onPopupEntered(p) {}
|
||||
|
||||
function _onPopupExitFinished(p) {
|
||||
if (!p) {
|
||||
return
|
||||
}
|
||||
const windowId = p.toString()
|
||||
if (destroyingWindows.has(windowId)) {
|
||||
return
|
||||
}
|
||||
destroyingWindows.add(windowId)
|
||||
const i = popupWindows.indexOf(p)
|
||||
if (i !== -1) {
|
||||
popupWindows.splice(i, 1)
|
||||
popupWindows = popupWindows.slice()
|
||||
}
|
||||
if (NotificationService.releaseWrapper && p.notificationData) {
|
||||
NotificationService.releaseWrapper(p.notificationData)
|
||||
}
|
||||
Qt.callLater(() => {
|
||||
if (p && p.destroy) {
|
||||
try {
|
||||
p.destroy()
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
Qt.callLater(() => destroyingWindows.delete(windowId))
|
||||
})
|
||||
const survivors = _active().sort((a, b) => a.screenY - b.screenY)
|
||||
for (let k = 0; k < survivors.length; ++k) {
|
||||
survivors[k].screenY = topMargin + k * baseNotificationHeight
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupAllWindows() {
|
||||
sweeper.stop()
|
||||
for (const p of popupWindows.slice()) {
|
||||
if (p) {
|
||||
try {
|
||||
if (p.forceExit) {
|
||||
p.forceExit()
|
||||
} else if (p.destroy) {
|
||||
p.destroy()
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
popupWindows = []
|
||||
destroyingWindows.clear()
|
||||
}
|
||||
|
||||
onPopupWindowsChanged: {
|
||||
if (popupWindows.length > 0 && !sweeper.running) {
|
||||
sweeper.start()
|
||||
} else if (popupWindows.length === 0 && sweeper.running) {
|
||||
sweeper.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user