Skip to content

Commit

Permalink
feat: add x-hyprnotify-color hint to specify color
Browse files Browse the repository at this point in the history
  • Loading branch information
codelif committed Apr 3, 2024
1 parent fe8e75e commit 521837e
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions internal/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"fmt"
"os"
"strings"
"time"

"github.com/godbus/dbus/v5"
Expand Down Expand Up @@ -122,6 +123,17 @@ func SendCloseSignal(timeout int32, reason uint32) {
)
}

func is_valid_hex_string(code string) bool{
valid := "0123456789abcdefABCDEF"

for _,v := range code {
if !strings.ContainsRune(valid, v){
return false
}
}
return true
}

func prepare_icons_colors_fontsize(hints map[string]dbus.Variant) (string, string, string, string) {
color := hyprsock.color.DEFAULT
icon := hyprsock.icon.INFO
Expand All @@ -132,11 +144,6 @@ func prepare_icons_colors_fontsize(hints map[string]dbus.Variant) (string, strin
urgency = 1
}

font_size, ok := hints["x-hyprnotify-font-size"].Value().(string)
if !ok {
font_size = "13"
}

if urgency == 0 {
icon = hyprsock.icon.OK
color = hyprsock.color.GREEN
Expand All @@ -149,6 +156,21 @@ func prepare_icons_colors_fontsize(hints map[string]dbus.Variant) (string, strin
icon_padding = " "
}

font_size, ok := hints["x-hyprnotify-font-size"].Value().(string)
if !ok {
font_size = "13"
}

hint_color, ok:= hints["x-hyprnotify-color"].Value().(string)
if ok {
if string(hint_color[0]) == "#"{
hint_color = hint_color[1:]
}
if len(hint_color) == 6 && is_valid_hex_string(hint_color){
color = hyprsock.color.HEX(hint_color)
}
}

return icon, color, icon_padding, font_size
}

Expand Down

0 comments on commit 521837e

Please sign in to comment.