Skip to content

Commit e6f3f6e

Browse files
committed
quickshell/notifications: add appIcon
fix warnings, center text column properly
1 parent 56196d3 commit e6f3f6e

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

home/services/quickshell/notifications/NotificationBox.qml

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@ WrapperMouseArea {
1414

1515
acceptedButtons: Qt.AllButtons
1616

17-
property string appIcon: ""
18-
property string app: ""
19-
property string summary: ""
20-
property string body: ""
21-
property string icon: ""
22-
property list<NotificationAction> actions: []
17+
property Notification n
18+
property string image: (n.image == "" && n.appIcon != "") ? n.appIcon : n.image
19+
property bool hasAppIcon: !(n.image == "" && n.appIcon != "")
2320
property int indexPopup: -1
2421
property int indexAll: -1
25-
property bool hasDismiss: true
2622
property real iconSize: 48
2723
property bool expanded: false
2824

25+
function getImage(image: string): string {
26+
if (image.search(/:\/\//) != -1)
27+
return Qt.resolvedUrl(image);
28+
return Quickshell.iconPath(image);
29+
}
30+
2931
onClicked: mouse => {
30-
if (mouse.button == Qt.LeftButton && actions != []) {
31-
actions[0].invoke();
32+
if (mouse.button == Qt.LeftButton && root.n.actions != []) {
33+
root.n.actions[0].invoke();
3234
} else if (mouse.button == Qt.RightButton) {
3335
if (indexAll != -1)
3436
NotificationState.notifDismissByAll(indexAll);
@@ -59,23 +61,41 @@ WrapperMouseArea {
5961
Item {
6062
id: coverItem
6163

62-
visible: root.icon != ""
64+
visible: root.image != ""
6365

6466
Layout.alignment: Qt.AlignTop
6567
implicitWidth: root.iconSize
6668
implicitHeight: root.iconSize
67-
Layout.margins: 8
69+
Layout.margins: 12
6870
Layout.rightMargin: 0
6971

7072
ClippingWrapperRectangle {
71-
visible: root.icon != ""
7273
anchors.centerIn: parent
7374
radius: 8
7475
color: "transparent"
7576

7677
IconImage {
7778
implicitSize: coverItem.height
78-
source: Quickshell.iconPath(root.icon)
79+
source: root.getImage(root.image)
80+
}
81+
}
82+
83+
ClippingWrapperRectangle {
84+
visible: root.hasAppIcon
85+
86+
anchors {
87+
horizontalCenter: coverItem.right
88+
verticalCenter: coverItem.bottom
89+
horizontalCenterOffset: -4
90+
verticalCenterOffset: -4
91+
}
92+
93+
radius: 2
94+
color: "transparent"
95+
96+
IconImage {
97+
implicitSize: 16
98+
source: root.getImage(root.n.appIcon)
7999
}
80100
}
81101
}
@@ -84,44 +104,36 @@ WrapperMouseArea {
84104
id: contentLayout
85105

86106
Layout.fillWidth: true
87-
Layout.fillHeight: true
88-
Layout.margins: 8
89-
Layout.leftMargin: coverItem.visible ? 0 : 8
107+
Layout.margins: 12
108+
Layout.leftMargin: coverItem.visible ? 4 : 12
90109
spacing: 4
91110

92-
// HACK: gives the illusion that 2-row text is centered (when bodyText is only one
93-
// row, and no action buttons are present)
94-
Item {
95-
Layout.fillHeight: true
96-
}
97-
98111
Text {
99112
Layout.maximumWidth: contentLayout.width - buttonLayout.width
100-
text: root.summary
113+
text: root.n.summary
101114
elide: Text.ElideRight
102115
font.weight: Font.Bold
103116
}
104117

105118
Text {
106119
id: bodyText
107120
Layout.fillWidth: true
108-
Layout.fillHeight: true
109121
elide: Text.ElideRight
110122
wrapMode: Text.Wrap
111123
font.weight: Font.Medium
112-
maximumLineCount: root.expanded ? 5 : (root.actions.length > 1 ? 1 : 2)
113-
text: root.body
124+
maximumLineCount: root.expanded ? 5 : (root.n.actions.length > 1 ? 1 : 2)
125+
text: root.n.body
114126
}
115127

116128
RowLayout {
117-
visible: root.actions.length > 1
129+
visible: root.n.actions.length > 1
118130

119131
Layout.fillWidth: true
120132
implicitHeight: actionRepeater.implicitHeight
121133

122134
Repeater {
123135
id: actionRepeater
124-
model: root.actions.slice(1)
136+
model: root.n.actions.slice(1)
125137

126138
WrapperMouseArea {
127139
id: actionButtonMA
@@ -170,7 +182,7 @@ WrapperMouseArea {
170182
WrapperMouseArea {
171183
id: expandButton
172184

173-
visible: bodyText.text.length > (root.actions.length > 1 ? 50 : 100)
185+
visible: bodyText.text.length > (root.n.actions.length > 1 ? 50 : 100)
174186

175187
property string sourceIcon: root.expanded ? "go-up-symbolic" : "go-down-symbolic"
176188

home/services/quickshell/notifications/NotificationOverlay.qml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ PanelWindow {
3535

3636
NotificationBox {
3737
required property int index
38-
appIcon: NotificationState.popupNotifs[index].appIcon
39-
app: NotificationState.popupNotifs[index].appName
40-
summary: NotificationState.popupNotifs[index].summary
41-
body: NotificationState.popupNotifs[index].body
42-
icon: NotificationState.popupNotifs[index].appIcon
43-
actions: NotificationState.popupNotifs[index].actions
38+
n: NotificationState.popupNotifs[index]
4439
indexPopup: index
4540
}
4641
}

home/services/quickshell/utils/NotificationState.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Singleton {
8888
onNotification: notif => {
8989
notif.tracked = true;
9090
root.onNewNotif(notif);
91+
console.log("notif: appName", notif.appName || "null", ", appIcon", notif.appIcon || "null", ", image", notif.image || "null")
9192

9293
notif.closed.connect(() => {
9394
notifDismissByNotif(notif);

0 commit comments

Comments
 (0)