Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --font-size & --fixed-font-size flags #11

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/hyprnotify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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)")
CmdFlags.BoolVar(&internal.FixedFontSize, "fixed-font-size", false, "makes font size fixed, ignoring new sizes")

Cmd.Execute()
}
17 changes: 9 additions & 8 deletions internal/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ 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
FixedFontSize bool
)

type DBusNotify string
Expand Down Expand Up @@ -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 = 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)
Expand All @@ -206,8 +209,6 @@ func parse_hints(nf *Notification, hints map[string]dbus.Variant) {
nf.color.value = nf.color.HEX(hint_color)
}
}


}

func InitDBus(enable_sound bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/hypripc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions internal/notify.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package internal

var DefaultFontSize uint8

type Notification struct {
message string

Expand Down Expand Up @@ -44,8 +46,7 @@ type icon struct {
}

type fontSize struct {
value int32
DEFAULT int32
value uint8
}

func newColorStruct() color {
Expand Down Expand Up @@ -106,7 +107,8 @@ func NewNotification() Notification {

n.icon = newIconStruct()
n.color = newColorStruct()
n.font_size = fontSize{value: 13, DEFAULT: 13}

n.font_size = fontSize{value: DefaultFontSize}

n.set_urgency(1) // default
return n
Expand Down
Loading