Skip to content

Commit 0e3378b

Browse files
authored
Merge pull request #8 from d3cryptofc/main
feat: add notification body message & text min-width (#7)
2 parents ec6159c + 7f7737c commit 0e3378b

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

internal/dbus.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package internal
33
import (
44
"fmt"
55
"os"
6+
"regexp"
7+
"strings"
68
"time"
79

810
"github.com/godbus/dbus/v5"
@@ -63,17 +65,18 @@ const DBUS_XML = `<node name="` + FDN_PATH + `">
6365
</node>`
6466

6567
var (
66-
conn *dbus.Conn
67-
hyprsock HyprConn
68-
ongoing_notifications map[uint32]chan uint32 = make(map[uint32]chan uint32)
69-
current_id uint32 = 0
70-
sound bool
68+
conn *dbus.Conn
69+
hyprsock HyprConn
70+
ongoing_notifications map[uint32]chan uint32 = make(map[uint32]chan uint32)
71+
current_id uint32 = 0
72+
sound bool
73+
notification_padding_regexp *regexp.Regexp = regexp.MustCompile("^\\s*|(\n)\\s*(.)")
7174
)
7275

7376
type DBusNotify string
7477

7578
func (n DBusNotify) GetCapabilities() ([]string, *dbus.Error) {
76-
var cap []string
79+
cap := []string{"body"}
7780
return cap, nil
7881
}
7982

@@ -98,9 +101,29 @@ func (n DBusNotify) Notify(
98101

99102
// Send Notification
100103
nf := NewNotification()
101-
nf.message = summary
104+
102105
parse_hints(&nf, hints)
103106

107+
// Setting min-width, left alignment
108+
summary = fmt.Sprintf("%-60s", summary)
109+
if nf.icon.value == nf.icon.NOICON {
110+
summary += " "
111+
}
112+
summary += "\u205F"
113+
114+
if body != "" {
115+
nf.message = fmt.Sprintf("%s\n%s", summary, body)
116+
} else {
117+
nf.message = summary
118+
}
119+
120+
// Using RegExp to add padding for all lines
121+
nf.message = notification_padding_regexp.
122+
ReplaceAllString(
123+
strings.TrimLeft(nf.message, "\n"),
124+
"$1\u205F $2",
125+
)
126+
104127
if expire_timeout != -1 {
105128
nf.time_ms = expire_timeout
106129
}

internal/notify.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,23 @@ func newIconStruct() icon {
8080

8181
func (nf *Notification) set_urgency(urgency uint8) {
8282
icon := nf.icon.NOICON
83-
padding := ""
8483
color := nf.color.DEFAULT
8584
var time_ms int32 = 5 * 1000
8685

8786
if urgency == 0 {
8887
icon = nf.icon.OK
89-
padding = " "
9088
color = nf.color.GREEN
9189
} else if urgency == 1 {
9290
icon = nf.icon.NOICON
93-
padding = " "
9491
color = nf.color.LIGHTBLUE
9592
} else if urgency == 2 {
9693
icon = nf.icon.WARNING
97-
padding = " "
9894
color = nf.color.RED
9995
time_ms = 60 * 1000
10096
}
10197

10298
nf.icon.value = icon
103-
nf.icon.padding = padding
99+
nf.icon.padding = ""
104100
nf.color.value = color
105101
nf.time_ms = time_ms
106102
}

0 commit comments

Comments
 (0)