From 685a463e8bd2bbda45684611d25681909252bd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Tue, 24 Sep 2024 17:40:37 -0300 Subject: [PATCH 1/4] feat: shows the notification body message as well --- internal/dbus.go | 17 ++++++++++++++++- internal/notify.go | 6 +----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/dbus.go b/internal/dbus.go index bd62fd7..996805b 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -3,6 +3,8 @@ package internal import ( "fmt" "os" + "regexp" + "strings" "time" "github.com/godbus/dbus/v5" @@ -98,7 +100,20 @@ func (n DBusNotify) Notify( // Send Notification nf := NewNotification() - nf.message = summary + if body != "" { + nf.message = fmt.Sprintf("%s\n%s", summary, body) + } else { + nf.message = summary + } + + // Using RegExp to add padding for all lines + nf.message = regexp. + MustCompile("^\\s*|(\n)\\s*(.)"). + ReplaceAllString( + strings.TrimLeft(nf.message, "\n"), + "$1\u205F\u205F$2", + ) + parse_hints(&nf, hints) if expire_timeout != -1 { diff --git a/internal/notify.go b/internal/notify.go index 9382196..dc51316 100644 --- a/internal/notify.go +++ b/internal/notify.go @@ -80,27 +80,23 @@ func newIconStruct() icon { func (nf *Notification) set_urgency(urgency uint8) { icon := nf.icon.NOICON - padding := "" color := nf.color.DEFAULT var time_ms int32 = 5 * 1000 if urgency == 0 { icon = nf.icon.OK - padding = " " color = nf.color.GREEN } else if urgency == 1 { icon = nf.icon.NOICON - padding = " " color = nf.color.LIGHTBLUE } else if urgency == 2 { icon = nf.icon.WARNING - padding = " " color = nf.color.RED time_ms = 60 * 1000 } nf.icon.value = icon - nf.icon.padding = padding + nf.icon.padding = "" nf.color.value = color nf.time_ms = time_ms } From 37d3e314bbcd27d0a86b1c6fd001e296b8e91327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Tue, 24 Sep 2024 19:56:04 -0300 Subject: [PATCH 2/4] feat: add text min-width and left alignment --- internal/dbus.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/dbus.go b/internal/dbus.go index 996805b..abd3b52 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -100,6 +100,16 @@ func (n DBusNotify) Notify( // Send Notification nf := NewNotification() + + parse_hints(&nf, hints) + + // Setting min-width, left alignment + summary = fmt.Sprintf("%-60s", summary) + if nf.icon.value == nf.icon.NOICON { + summary += " " + } + summary += "\u205F" + if body != "" { nf.message = fmt.Sprintf("%s\n%s", summary, body) } else { @@ -111,11 +121,9 @@ func (n DBusNotify) Notify( MustCompile("^\\s*|(\n)\\s*(.)"). ReplaceAllString( strings.TrimLeft(nf.message, "\n"), - "$1\u205F\u205F$2", + "$1\u205F $2", ) - parse_hints(&nf, hints) - if expire_timeout != -1 { nf.time_ms = expire_timeout } From 024ba8b2f0fcc854c7a42cb8e84e05e9280997be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Wed, 25 Sep 2024 12:14:24 -0300 Subject: [PATCH 3/4] refactor: store padding regex in a package-level variable --- internal/dbus.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/dbus.go b/internal/dbus.go index abd3b52..f3a1f52 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -65,11 +65,12 @@ const DBUS_XML = ` ` var ( - conn *dbus.Conn - hyprsock HyprConn - ongoing_notifications map[uint32]chan uint32 = make(map[uint32]chan uint32) - current_id uint32 = 0 - sound bool + conn *dbus.Conn + hyprsock HyprConn + ongoing_notifications map[uint32]chan uint32 = make(map[uint32]chan uint32) + current_id uint32 = 0 + sound bool + notification_padding_regexp *regexp.Regexp = regexp.MustCompile("^\\s*|(\n)\\s*(.)") ) type DBusNotify string @@ -117,8 +118,7 @@ func (n DBusNotify) Notify( } // Using RegExp to add padding for all lines - nf.message = regexp. - MustCompile("^\\s*|(\n)\\s*(.)"). + nf.message = notification_padding_regexp. ReplaceAllString( strings.TrimLeft(nf.message, "\n"), "$1\u205F $2", From 7f7737cf95a89f2ca22b7513f589afc7896b0072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Wed, 25 Sep 2024 12:52:25 -0300 Subject: [PATCH 4/4] imp(dbus): add 'body' capability to func `GetCapabilities` --- internal/dbus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/dbus.go b/internal/dbus.go index f3a1f52..3486a1c 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -76,7 +76,7 @@ var ( type DBusNotify string func (n DBusNotify) GetCapabilities() ([]string, *dbus.Error) { - var cap []string + cap := []string{"body"} return cap, nil }