notifications: copy button

This commit is contained in:
end-4
2025-04-20 17:53:11 +02:00
parent ab334c7a94
commit e66c942790
2 changed files with 59 additions and 5 deletions
@@ -127,10 +127,10 @@ Singleton {
property color colPrimaryContainerActive: mix(m3colors.m3primaryContainer, colLayer1Active, 0.6)
property color colSecondaryHover: mix(m3colors.m3secondary, colLayer1Hover, 0.85)
property color colSecondaryActive: mix(m3colors.m3secondary, colLayer1Active, 0.4)
property color colSecondaryContainerHover: mix(m3colors.m3secondaryContainer, colLayer1Hover, 0.67)
property color colSecondaryContainerActive: mix(m3colors.m3secondaryContainer, colLayer1Active, 0.6)
property color colSurfaceContainerHighestHover: mix(m3colors.m3surfaceContainerHighest, m3colors.m3onSurface, 0.9)
property color colSurfaceContainerHighestActive: mix(m3colors.m3surfaceContainerHighest, m3colors.m3onSurface, 0.82)
property color colSecondaryContainerHover: mix(m3colors.m3secondaryContainer, colLayer1Hover, 0.6)
property color colSecondaryContainerActive: mix(m3colors.m3secondaryContainer, colLayer1Active, 0.54)
property color colSurfaceContainerHighestHover: mix(m3colors.m3surfaceContainerHighest, m3colors.m3onSurface, 0.95)
property color colSurfaceContainerHighestActive: mix(m3colors.m3surfaceContainerHighest, m3colors.m3onSurface, 0.85)
property color colTooltip: m3colors.m3inverseSurface
property color colOnTooltip: m3colors.m3inverseOnSurface
property color colScrim: transparentize(m3colors.m3scrim, 0.5)
@@ -26,6 +26,11 @@ Item {
command: ["bash", "-c", `qs ipc call sidebarRight close`]
}
Process {
id: copyNotificationBody
command: ["bash", "-c", `wl-copy "${notificationObject.body}"`]
}
implicitHeight: ready ? notificationColumnLayout.implicitHeight + notificationListSpacing : 0
Behavior on implicitHeight {
enabled: enableAnimation
@@ -110,6 +115,13 @@ Item {
startX = mouse.x
}
}
onPressAndHold: (mouse) => {
if (mouse.button === Qt.LeftButton) {
copyNotificationBody.running = true
notificationSummaryText.text = `${notificationObject.summary} (copied)`
console.log(notificationSummaryText.text)
}
}
onDragStartedChanged: () => {
// Prevent drag focus being shifted to parent flickable
root.parent.parent.parent.interactive = !dragStarted
@@ -306,6 +318,7 @@ Item {
Layout.fillWidth: true
StyledText { // Summary
id: notificationSummaryText
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignBottom
@@ -473,15 +486,56 @@ Item {
}
}
NotificationActionButton {
Layout.fillWidth: true
urgency: notificationObject.urgency
implicitWidth: (notificationObject.actions.length == 0) ? (actionsFlickable.width / 2) :
(contentItem.implicitWidth + leftPadding + rightPadding)
onClicked: {
copyNotificationBody.running = true
copyIcon.text = "inventory"
copyIconTimer.stop()
copyIconTimer.start()
}
Timer {
id: copyIconTimer
interval: 1500
repeat: false
onTriggered: {
copyIcon.text = "content_copy"
}
}
contentItem: MaterialSymbol {
id: copyIcon
font.pixelSize: Appearance.font.pixelSize.large
horizontalAlignment: Text.AlignHCenter
color: (notificationObject.urgency == NotificationUrgency.Critical) ?
Appearance.m3colors.m3onSurfaceVariant : Appearance.m3colors.m3onSurface
text: "content_copy"
}
}
NotificationActionButton {
Layout.fillWidth: true
buttonText: "Close"
urgency: notificationObject.urgency
implicitWidth: (notificationObject.actions.length == 0) ? (actionsFlickable.width) :
implicitWidth: (notificationObject.actions.length == 0) ? (actionsFlickable.width / 2) :
(contentItem.implicitWidth + leftPadding + rightPadding)
onClicked: {
Notifications.discardNotification(notificationObject.id);
}
contentItem: MaterialSymbol {
font.pixelSize: Appearance.font.pixelSize.large
horizontalAlignment: Text.AlignHCenter
color: (notificationObject.urgency == NotificationUrgency.Critical) ?
Appearance.m3colors.m3onSurfaceVariant : Appearance.m3colors.m3onSurface
text: "close"
}
}
}