Skip to content

Commit 579c158

Browse files
committed
quickshell/sidebar: add notification center
1 parent 2cebf04 commit 579c158

File tree

6 files changed

+110
-36
lines changed

6 files changed

+110
-36
lines changed

home/services/quickshell/bar/Clock.qml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import "../components"
55
import "../utils/."
66

77
WrapperMouseArea {
8-
onClicked: () => Config.showSidebar = !Config.showSidebar
8+
onClicked: () => {
9+
NotificationState.notifOverlayOpen = false;
10+
Config.showSidebar = !Config.showSidebar;
11+
}
912

1013
Text {
1114
SystemClock {

home/services/quickshell/notifications/NotificationBox.qml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ WrapperMouseArea {
1919
property int elapsed: 0
2020
property string image: (n.image == "" && n.appIcon != "") ? n.appIcon : n.image
2121
property bool hasAppIcon: !(n.image == "" && n.appIcon != "")
22-
property int indexPopup: -1
23-
property int indexAll: -1
2422
property real iconSize: 48
2523

2624
property bool showTime: false
2725
property bool expanded: false
2826

27+
property bool dismissOnClose: true
28+
2929
onClicked: mouse => {
30-
if (mouse.button == Qt.LeftButton && root.n.actions != []) {
31-
root.n.actions[0].invoke();
30+
if (mouse.button == Qt.LeftButton && root.n?.actions != []) {
31+
root.n?.actions[0].invoke();
3232
} else if (mouse.button == Qt.RightButton) {
33-
if (indexAll != -1)
34-
NotificationState.notifDismissByAll(indexAll);
35-
else if (indexPopup != -1)
36-
NotificationState.notifDismissByPopup(indexPopup);
37-
} else if (mouse.button == Qt.MiddleButton) {
33+
if (dismissOnClose) {
34+
NotificationState.notifDismissByNotif(n);
35+
} else {
36+
NotificationState.notifCloseByNotif(n);
37+
}
38+
} else if (mouse.button == Qt.MiddleButton && dismissOnClose) {
3839
NotificationState.dismissAll();
40+
} else if (mouse.button == Qt.MiddleButton) {
41+
NotificationState.closeAll();
3942
}
4043
}
4144

@@ -104,7 +107,7 @@ WrapperMouseArea {
104107

105108
IconImage {
106109
implicitSize: 16
107-
source: Utils.getImage(root.n.appIcon)
110+
source: Utils.getImage(root.n?.appIcon)
108111
}
109112
}
110113
}
@@ -122,18 +125,18 @@ WrapperMouseArea {
122125
Layout.fillWidth: false
123126

124127
Text {
125-
text: root.n.summary
128+
text: root.n?.summary
126129
elide: Text.ElideRight
127130
font.weight: Font.Bold
128131
}
129132

130133
Text {
131-
visible: root.showTime
134+
visible: root?.showTime
132135
text: "·"
133136
}
134137

135138
Text {
136-
visible: root.showTime
139+
visible: root?.showTime
137140
text: Utils.humanTime(root.elapsed)
138141
}
139142
}
@@ -144,19 +147,19 @@ WrapperMouseArea {
144147
elide: Text.ElideRight
145148
wrapMode: Text.Wrap
146149
font.weight: Font.Medium
147-
maximumLineCount: root.expanded ? 5 : (root.n.actions.length > 1 ? 1 : 2)
148-
text: root.n.body
150+
maximumLineCount: root.expanded ? 5 : (root.n?.actions.length > 1 ? 1 : 2)
151+
text: root.n?.body
149152
}
150153

151154
RowLayout {
152-
visible: root.n.actions.length > 1
155+
visible: root.n?.actions.length > 1
153156

154157
Layout.fillWidth: true
155158
implicitHeight: actionRepeater.implicitHeight
156159

157160
Repeater {
158161
id: actionRepeater
159-
model: root.n.actions.slice(1)
162+
model: root.n?.actions.slice(1)
160163

161164
WrapperMouseArea {
162165
id: actionButtonMA
@@ -206,7 +209,7 @@ WrapperMouseArea {
206209
WrapperMouseArea {
207210
id: expandButton
208211

209-
visible: bodyText.text.length > (root.n.actions.length > 1 ? 50 : 100)
212+
visible: bodyText.text.length > (root.n?.actions.length > 1 ? 50 : 100)
210213

211214
property string sourceIcon: root.expanded ? "go-up-symbolic" : "go-down-symbolic"
212215

@@ -241,10 +244,7 @@ WrapperMouseArea {
241244
implicitWidth: 16
242245

243246
onPressed: () => {
244-
if (root.indexAll != -1)
245-
NotificationState.notifCloseByAll(root.indexAll);
246-
else if (root.indexPopup != -1)
247-
NotificationState.notifCloseByPopup(root.indexPopup);
247+
NotificationState.notifCloseByNotif(root.n);
248248
}
249249

250250
Rectangle {

home/services/quickshell/notifications/NotificationOverlay.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import "../utils/."
22
import QtQuick
33
import QtQuick.Layouts
44
import Quickshell
5+
import Quickshell.Services.Notifications
56
import Quickshell.Wayland
67

78
PanelWindow {
89
id: root
910

1011
screen: Config.preferredMonitor
11-
visible: NotificationState.notifOverlayOpen
12+
visible: NotificationState.notifOverlayOpen && !Config.showSidebar
1213

1314
WlrLayershell.namespace: "quickshell:notifications:overlay"
1415
WlrLayershell.layer: WlrLayer.Top
@@ -35,9 +36,8 @@ PanelWindow {
3536

3637
NotificationBox {
3738
id: notifBox
38-
required property int index
39-
n: NotificationState.popupNotifs[index]
40-
indexPopup: index
39+
required property Notification modelData
40+
n: modelData
4141

4242
Timer {
4343
running: true
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import "../utils/."
2+
import "../notifications"
3+
import QtQuick
4+
import QtQuick.Layouts
5+
import Quickshell
6+
import Quickshell.Widgets
7+
import Quickshell.Services.Notifications
8+
import org.kde.kirigami
9+
import "../components"
10+
11+
ColumnLayout {
12+
id: root
13+
Layout.fillWidth: true
14+
15+
WrapperRectangle {
16+
id: wrapper
17+
Layout.fillWidth: true
18+
margin: 4
19+
radius: 16
20+
color: Colors.bgBlur
21+
22+
RowLayout {
23+
WrapperRectangle {
24+
margin: 4
25+
color: "transparent"
26+
Text {
27+
text: "No notifications"
28+
}
29+
}
30+
31+
WrapperMouseArea {
32+
id: closeButton
33+
Layout.alignment: Qt.AlignRight
34+
35+
hoverEnabled: true
36+
Layout.fillHeight: true
37+
implicitWidth: height
38+
39+
onPressed: () => {
40+
NotificationState.closeAll();
41+
}
42+
43+
Rectangle {
44+
radius: closeButton.implicitWidth
45+
color: closeButton.containsMouse ? Colors.buttonDisabledHover : Colors.buttonDisabled
46+
implicitWidth: radius
47+
implicitHeight: radius
48+
49+
Icon {
50+
source: Quickshell.iconPath("process-stop-symbolic")
51+
anchors.centerIn: parent
52+
implicitHeight: parent.implicitHeight - 4
53+
implicitWidth: parent.implicitHeight - 4
54+
isMask: true
55+
color: Colors.foreground
56+
}
57+
}
58+
}
59+
}
60+
}
61+
62+
ColumnLayout {
63+
id: notifs
64+
65+
Repeater {
66+
id: notifRepeater
67+
model: NotificationState.allNotifs
68+
69+
NotificationBox {
70+
id: notifBox
71+
required property Notification modelData
72+
n: modelData
73+
showTime: true
74+
dismissOnClose: false
75+
}
76+
}
77+
}
78+
}

home/services/quickshell/sidebar/Sidebar.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ LazyLoader {
3434
anchors.fill: parent
3535

3636
Calendar {}
37+
NotificationCenter {}
3738
}
3839
}
3940
}

home/services/quickshell/utils/NotificationState.qml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ Singleton {
99
property var allNotifs: []
1010
property var defaultNotifTimeout: 5000
1111
property bool notifOverlayOpen: false
12-
property bool notifPanelOpen: false
13-
14-
function togglePanel() {
15-
if (notifOverlayOpen && !notifPanelOpen)
16-
notifOverlayOpen = false;
17-
18-
notifPanelOpen = !notifPanelOpen;
19-
}
2012

2113
function onNewNotif(notif) {
2214
allNotifs = [notif, ...allNotifs];
@@ -26,7 +18,7 @@ Singleton {
2618

2719
popupNotifs = [notif, ...popupNotifs];
2820

29-
if (!notifPanelOpen)
21+
if (!Config.showSidebar)
3022
notifOverlayOpen = true;
3123
}
3224

0 commit comments

Comments
 (0)