From e66c942790e14f5aa238ebb8979d8adc49dac7e6 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sun, 20 Apr 2025 17:53:11 +0200 Subject: [PATCH] notifications: copy button --- .../quickshell/modules/common/Appearance.qml | 8 +-- .../common/widgets/NotificationWidget.qml | 56 ++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.config/quickshell/modules/common/Appearance.qml b/.config/quickshell/modules/common/Appearance.qml index 05c3f059c..70eb0e726 100644 --- a/.config/quickshell/modules/common/Appearance.qml +++ b/.config/quickshell/modules/common/Appearance.qml @@ -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) diff --git a/.config/quickshell/modules/common/widgets/NotificationWidget.qml b/.config/quickshell/modules/common/widgets/NotificationWidget.qml index 204208df0..d52bec6d0 100644 --- a/.config/quickshell/modules/common/widgets/NotificationWidget.qml +++ b/.config/quickshell/modules/common/widgets/NotificationWidget.qml @@ -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" + } } }