Skip to content

Commit 187d27a

Browse files
committed
quickshell/notifications: add actions
update colors
1 parent 5a599d9 commit 187d27a

File tree

4 files changed

+71
-13
lines changed

4 files changed

+71
-13
lines changed

home/services/quickshell/notifications/NotificationBox.qml

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
pragma ComponentBehavior: Bound
2+
13
import QtQuick
24
import QtQuick.Layouts
35
import Quickshell
6+
import Quickshell.Services.Notifications
47
import Quickshell.Widgets
58
import org.kde.kirigami
69
import "../utils/."
@@ -16,14 +19,17 @@ WrapperMouseArea {
1619
property string summary: ""
1720
property string body: ""
1821
property string icon: ""
22+
property list<NotificationAction> actions: []
1923
property int indexPopup: -1
2024
property int indexAll: -1
2125
property bool hasDismiss: true
2226
property real iconSize: 48
2327
property bool expanded: false
2428

2529
onClicked: mouse => {
26-
if (mouse.button == Qt.RightButton) {
30+
if (mouse.button == Qt.LeftButton && actions != []) {
31+
actions[0].invoke();
32+
} else if (mouse.button == Qt.RightButton) {
2733
if (indexAll != -1)
2834
NotificationState.notifDismissByAll(indexAll);
2935
else if (indexPopup != -1)
@@ -79,9 +85,9 @@ WrapperMouseArea {
7985
id: contentLayout
8086

8187
Layout.fillWidth: true
82-
Layout.margins: 15
83-
Layout.leftMargin: coverItem.visible ? 0 : 15
84-
spacing: 5
88+
Layout.margins: 8
89+
Layout.leftMargin: coverItem.visible ? 0 : 8
90+
spacing: 4
8591

8692
Text {
8793
Layout.maximumWidth: contentLayout.width - buttonLayout.width
@@ -95,9 +101,50 @@ WrapperMouseArea {
95101
Layout.fillHeight: true
96102
elide: Text.ElideRight
97103
wrapMode: Text.Wrap
98-
maximumLineCount: root.expanded ? 5 : 1
104+
maximumLineCount: root.expanded ? 5 : (root.actions.length > 1 ? 1 : 2)
99105
text: root.body
100106
}
107+
108+
RowLayout {
109+
visible: root.actions.length > 1
110+
111+
Layout.fillWidth: true
112+
implicitHeight: actionRepeater.implicitHeight
113+
114+
Repeater {
115+
id: actionRepeater
116+
model: root.actions.slice(1)
117+
118+
WrapperMouseArea {
119+
id: actionButtonMA
120+
required property NotificationAction modelData
121+
122+
hoverEnabled: true
123+
implicitHeight: actionButton.implicitHeight
124+
Layout.fillWidth: true
125+
126+
onPressed: () => {
127+
modelData.invoke();
128+
}
129+
130+
Rectangle {
131+
id: actionButton
132+
133+
radius: 16
134+
color: actionButtonMA.containsMouse ? Colors.buttonDisabledHover : Colors.buttonDisabled
135+
implicitHeight: buttonText.implicitHeight
136+
Layout.fillWidth: true
137+
138+
Text {
139+
id: buttonText
140+
141+
anchors.centerIn: parent
142+
text: actionButtonMA.modelData.text
143+
}
144+
}
145+
}
146+
}
147+
}
101148
}
102149
}
103150

@@ -108,14 +155,14 @@ WrapperMouseArea {
108155
anchors {
109156
top: parent.top
110157
right: parent.right
111-
topMargin: 13
112-
rightMargin: 12
158+
topMargin: 8
159+
rightMargin: 8
113160
}
114161

115162
WrapperMouseArea {
116163
id: expandButton
117164

118-
visible: bodyText.truncated
165+
visible: bodyText.text.length > (root.actions.length > 1 ? 50 : 100)
119166

120167
property string sourceIcon: "go-down-symbolic"
121168

@@ -130,7 +177,7 @@ WrapperMouseArea {
130177

131178
Rectangle {
132179
radius: 16
133-
color: expandButton.containsMouse ? Colors.bgBar : Colors.bgBlur
180+
color: expandButton.containsMouse ? Colors.buttonDisabledHover : Colors.buttonDisabled
134181
implicitWidth: 16
135182
implicitHeight: 16
136183

@@ -140,7 +187,7 @@ WrapperMouseArea {
140187
implicitHeight: parent.implicitHeight - 4
141188
implicitWidth: parent.implicitHeight - 4
142189
isMask: true
143-
color: 'white'
190+
color: Colors.foreground
144191
}
145192
}
146193
}
@@ -161,7 +208,7 @@ WrapperMouseArea {
161208

162209
Rectangle {
163210
radius: 16
164-
color: closeButton.containsMouse ? Qt.lighter(Qt.lighter(Qt.lighter(Colors.bgBlur))) : Qt.lighter(Qt.lighter(Colors.bgBlur))
211+
color: closeButton.containsMouse ? Colors.buttonDisabledHover : Colors.buttonDisabled
165212
implicitWidth: 16
166213
implicitHeight: 16
167214

@@ -171,7 +218,7 @@ WrapperMouseArea {
171218
implicitHeight: parent.implicitHeight - 4
172219
implicitWidth: parent.implicitHeight - 4
173220
isMask: true
174-
color: 'white'
221+
color: Colors.foreground
175222
}
176223
}
177224
}

home/services/quickshell/notifications/NotificationOverlay.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ WlrLayershell {
3535
summary: NotificationState.popupNotifs[index].summary
3636
body: NotificationState.popupNotifs[index].body
3737
icon: NotificationState.popupNotifs[index].appIcon
38+
actions: NotificationState.popupNotifs[index].actions
3839
indexPopup: index
3940
}
4041
}

home/services/quickshell/utils/Colors.qml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ Singleton {
77
property color bgBlur: Qt.rgba(0, 0, 0, 0.5)
88
property color foreground: "white"
99
property list<color> monitorColors: ["#e06c75", "#e5c07b", "#98c379", "#61afef"]
10+
11+
property color surface: Qt.rgba(255, 255, 255, 0.15)
12+
property color overlay: Qt.rgba(255, 255, 255, 0.7)
13+
14+
property color accent: "#e06c75"
15+
16+
property color buttonEnabled: accent
17+
property color buttonEnabledHover: Qt.lighter(accent, 0.9)
18+
property color buttonDisabled: surface
19+
property color buttonDisabledHover: Qt.rgba(surface.r, surface.g, surface.b, surface.a + 0.1)
1020
}

home/services/quickshell/utils/NotificationState.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Singleton {
8181
bodyMarkupSupported: true
8282
bodyHyperlinksSupported: false
8383
bodyImagesSupported: false
84-
actionsSupported: false
84+
actionsSupported: true
8585
actionIconsSupported: false
8686
imageSupported: true
8787

0 commit comments

Comments
 (0)