From d472297c23bc4e1d9b6bb59983fbeae81e334029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Wed, 25 Sep 2024 20:05:16 -0300 Subject: [PATCH 1/3] refactor: change font size type to `uint8` --- internal/dbus.go | 6 ++---- internal/hypripc.go | 2 +- internal/notify.go | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/dbus.go b/internal/dbus.go index 3486a1c..8110a18 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -69,8 +69,8 @@ var ( 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*(.)") + sound bool ) type DBusNotify string @@ -187,7 +187,7 @@ func parse_hints(nf *Notification, hints map[string]dbus.Variant) { font_size, ok := hints["x-hyprnotify-font-size"].Value().(int32) if ok { - nf.font_size.value = font_size + nf.font_size.value = uint8(font_size) } hint_icon, ok := hints["x-hyprnotify-icon"].Value().(int32) @@ -206,8 +206,6 @@ func parse_hints(nf *Notification, hints map[string]dbus.Variant) { nf.color.value = nf.color.HEX(hint_color) } } - - } func InitDBus(enable_sound bool) { diff --git a/internal/hypripc.go b/internal/hypripc.go index b1fb0b3..bc01f4c 100644 --- a/internal/hypripc.go +++ b/internal/hypripc.go @@ -60,7 +60,7 @@ func (hypr HyprConn) HyprCtl(args ...string) { func (hypr HyprConn) SendNotification(nf *Notification) { icon := i32ToString(nf.icon.value) timeout := i32ToString(nf.time_ms) - font_size := i32ToString(nf.font_size.value) + font_size := fmt.Sprintf("%d", nf.font_size.value) msg := "fontsize:" + font_size + " " + nf.icon.padding + nf.message hypr.HyprCtl("notify", icon, timeout, nf.color.value, msg) diff --git a/internal/notify.go b/internal/notify.go index dc51316..cfa3105 100644 --- a/internal/notify.go +++ b/internal/notify.go @@ -44,8 +44,7 @@ type icon struct { } type fontSize struct { - value int32 - DEFAULT int32 + value uint8 } func newColorStruct() color { @@ -106,7 +105,7 @@ func NewNotification() Notification { n.icon = newIconStruct() n.color = newColorStruct() - n.font_size = fontSize{value: 13, DEFAULT: 13} + n.font_size = fontSize{value: 13} n.set_urgency(1) // default return n From d4ff6e3110e622d5c3c84679f6b7372d7be98906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Fri, 27 Sep 2024 13:04:59 -0300 Subject: [PATCH 2/3] feat(cli): add `--font-size` flag set default font size (range 1-255) (default 13) --- cmd/hyprnotify/main.go | 1 + internal/notify.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/hyprnotify/main.go b/cmd/hyprnotify/main.go index cd3b0f6..6e67ef0 100644 --- a/cmd/hyprnotify/main.go +++ b/cmd/hyprnotify/main.go @@ -19,6 +19,7 @@ func main() { CmdFlags := Cmd.Flags() CmdFlags.BoolVarP(&disableSound, "no-sound", "s", false, "disable sound, silent mode") + CmdFlags.Uint8VarP(&internal.DefaultFontSize, "font-size", "f", 13, "set default font size (range 1-255)") Cmd.Execute() } diff --git a/internal/notify.go b/internal/notify.go index cfa3105..0f8d98b 100644 --- a/internal/notify.go +++ b/internal/notify.go @@ -1,5 +1,7 @@ package internal +var DefaultFontSize uint8 + type Notification struct { message string @@ -105,7 +107,8 @@ func NewNotification() Notification { n.icon = newIconStruct() n.color = newColorStruct() - n.font_size = fontSize{value: 13} + + n.font_size = fontSize{value: DefaultFontSize} n.set_urgency(1) // default return n From a601e0b0382eb3a97e4f575069825b27865cfb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lelzin=20=CE=BB?= Date: Fri, 27 Sep 2024 13:06:33 -0300 Subject: [PATCH 3/3] feat(cli): add `--fixed-font-size` flag makes font size fixed, ignoring new sizes --- cmd/hyprnotify/main.go | 1 + internal/dbus.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/hyprnotify/main.go b/cmd/hyprnotify/main.go index 6e67ef0..5186801 100644 --- a/cmd/hyprnotify/main.go +++ b/cmd/hyprnotify/main.go @@ -20,6 +20,7 @@ func main() { CmdFlags.BoolVarP(&disableSound, "no-sound", "s", false, "disable sound, silent mode") CmdFlags.Uint8VarP(&internal.DefaultFontSize, "font-size", "f", 13, "set default font size (range 1-255)") + CmdFlags.BoolVar(&internal.FixedFontSize, "fixed-font-size", false, "makes font size fixed, ignoring new sizes") Cmd.Execute() } diff --git a/internal/dbus.go b/internal/dbus.go index 8110a18..e5a6023 100644 --- a/internal/dbus.go +++ b/internal/dbus.go @@ -71,6 +71,7 @@ var ( current_id uint32 = 0 notification_padding_regexp *regexp.Regexp = regexp.MustCompile("^\\s*|(\n)\\s*(.)") sound bool + FixedFontSize bool ) type DBusNotify string @@ -185,16 +186,18 @@ func parse_hints(nf *Notification, hints map[string]dbus.Variant) { nf.set_urgency(urgency) } - font_size, ok := hints["x-hyprnotify-font-size"].Value().(int32) - if ok { - nf.font_size.value = uint8(font_size) + if !FixedFontSize { + font_size, ok := hints["x-hyprnotify-font-size"].Value().(int32) + if ok { + nf.font_size.value = uint8(font_size) + } } - + hint_icon, ok := hints["x-hyprnotify-icon"].Value().(int32) if ok { nf.icon.value = hint_icon nf.icon.padding = "" - nf.color.value = nf.color.DEFAULT + nf.color.value = nf.color.DEFAULT } hint_color, ok := hints["x-hyprnotify-color"].Value().(string)