Skip to content

Commit

Permalink
Merge pull request #8 from d3cryptofc/main
Browse files Browse the repository at this point in the history
feat: add notification body message & text min-width (#7)
  • Loading branch information
codelif authored Sep 25, 2024
2 parents ec6159c + 7f7737c commit 0e3378b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
37 changes: 30 additions & 7 deletions internal/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package internal
import (
"fmt"
"os"
"regexp"
"strings"
"time"

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

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

func (n DBusNotify) GetCapabilities() ([]string, *dbus.Error) {
var cap []string
cap := []string{"body"}
return cap, nil
}

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

// Send Notification
nf := NewNotification()
nf.message = summary

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 {
nf.message = summary
}

// Using RegExp to add padding for all lines
nf.message = notification_padding_regexp.
ReplaceAllString(
strings.TrimLeft(nf.message, "\n"),
"$1\u205F $2",
)

if expire_timeout != -1 {
nf.time_ms = expire_timeout
}
Expand Down
6 changes: 1 addition & 5 deletions internal/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0e3378b

Please sign in to comment.