From d9ce42598127a502dc87b0c71d9d0f0c530d9248 Mon Sep 17 00:00:00 2001 From: eleksir Date: Tue, 15 Jul 2025 14:08:34 +0300 Subject: [PATCH] Finally fix parsing of app buttons, now settings and fallback values should work as expected --- cmd/i3status-go/default-config.json | 30 ++++++++++++++--------------- cmd/i3status-go/main.go | 11 ++++++++--- internal/lib/config.go | 24 ++++++++++++----------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/cmd/i3status-go/default-config.json b/cmd/i3status-go/default-config.json index 8046716..e3d4e1c 100644 --- a/cmd/i3status-go/default-config.json +++ b/cmd/i3status-go/default-config.json @@ -2,7 +2,7 @@ // Default text and *block* border colors. If not set #3e78fd is used. "color" : "#3e78fd", -// Default backbround color. If not set value of #edeceb is used. +// Default background color. If not set value of #edeceb is used. "background" : "#000000", // Can be omitted, then Liberation Mono will be used. @@ -834,36 +834,36 @@ // ‘smaller’ or ‘larger’. If omitted set to default font size defined for separator up here. "font_size": "medium" } - }, + } }, // Buttons - application launch "buttons" "apps": [ { - // Text dispalyed on button + // Text displayed on button, pango markup supported. "full_text" : "📂", - // Internal name, can be any string, but unique for each app button + // Internal name, can be any string, but unique for each app button. "name" : "thunar", - // Command itself + // Command itself. "cmd" : "thunar", - // Array of command args, optional + // Array of command args, optional. "args": [ "." ], - // Regexp that match with Instance component of WM_CLASS(STRING) of xprop output + // Regexp that match with Instance component of WM_CLASS(STRING) of xprop output. "instance": "^thunar$", - // Regexp that match with Class component of WM_CLASS(STRING) of xprop output + // Regexp that match with Class component of WM_CLASS(STRING) of xprop output. "class": "^Thunar$", - // text color in html notation + // Text color in html notation. "color": "#ffa500", - // background color in html notation + // background color in html notation. "background" : "#000000", - // border color in html notation - // If omitted set to default font defined for separator up here. + // If omitted set to default font defined for app_buttons up here. "font": "Noto Sans", // ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’, or one of relative sizes - // ‘smaller’ or ‘larger’. If omitted set to default font size defined for separator up here. - "font_size": "medium" + // ‘smaller’ or ‘larger’. If omitted set to default font size defined for app_buttons up here. + "font_size": "medium", + // Border color in html notation. "border": "#666666", - // border color if there is at least one window with given Instance and/or Class exist + // Border color if there is at least one window with given Instance and/or Class exist. "border_active": "#3e78fd", // Vertical line between objects on bar - if omitted true value is assumed by i3bar, but we set it to false // in that case. It is limitation of golang json parser. diff --git a/cmd/i3status-go/main.go b/cmd/i3status-go/main.go index aebc5f6..909b5fe 100644 --- a/cmd/i3status-go/main.go +++ b/cmd/i3status-go/main.go @@ -192,7 +192,14 @@ func main() { ) } - b.FullText = app.FullText + b.FullText = fmt.Sprintf( + "%s", + app.Color, + app.Background, + app.Font, + app.FontSize, + app.FullText, + ) if num == len(Conf.Apps) { b.FullText = fmt.Sprintf( @@ -205,8 +212,6 @@ func main() { ) } - b.Background = app.Background - b.Color = app.Color b.Instance = app.Instance b.Markup = `pango` b.Separator = app.Separator diff --git a/internal/lib/config.go b/internal/lib/config.go index 97d24a9..4f8379d 100644 --- a/internal/lib/config.go +++ b/internal/lib/config.go @@ -21,6 +21,8 @@ type I3BarOutBlock struct { ShortText string `json:"short_text,omitempty"` Color string `json:"color,omitempty"` Background string `json:"background,omitempty"` + Font string `json:"font,omitempty"` + FontSize string `json:"font_size,omitempty"` Border string `json:"border,omitempty"` BorderTop int `json:"border_top"` BorderRight int `json:"border_right"` @@ -1963,29 +1965,29 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) { // app.Instance can be missing. // app.Class can be missing. if app.Name == "" { - app.Name = fmt.Sprintf("app%d", num) + sampleConfig.Apps[num].Name = fmt.Sprintf("app%d", num) } // app.Args can be empty slice. In that case command will be run without aruments. if app.Cmd == "" { // If command omitted it will be just /usr/bin/true. - app.Cmd = "true" + sampleConfig.Apps[num].Cmd = "true" } if app.Color == "" { - app.Color = sampleConfig.AppButtons.Color + sampleConfig.Apps[num].Color = sampleConfig.AppButtons.Color } if app.Background == "" { - app.Background = sampleConfig.AppButtons.Background + sampleConfig.Apps[num].Background = sampleConfig.AppButtons.Background } if app.Font == "" { - app.Font = sampleConfig.AppButtons.Font + sampleConfig.Apps[num].Font = sampleConfig.AppButtons.Font } if app.FontSize == "" { - app.FontSize = sampleConfig.AppButtons.FontSize + sampleConfig.Apps[num].FontSize = sampleConfig.AppButtons.FontSize } else { matched, err := regexp.MatchString( `^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`, @@ -2000,7 +2002,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) { sampleConfig.AppButtons.FontSize, ) - app.FontSize = sampleConfig.AppButtons.FontSize + sampleConfig.Apps[num].FontSize = sampleConfig.AppButtons.FontSize } if !matched { @@ -2009,22 +2011,22 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) { sampleConfig.AppButtons.FontSize, ) - app.FontSize = sampleConfig.AppButtons.FontSize + sampleConfig.Apps[num].FontSize = sampleConfig.AppButtons.FontSize } } if app.Border == "" { - app.Border = sampleConfig.AppButtons.Color + sampleConfig.Apps[num].Border = sampleConfig.AppButtons.Color } if app.BorderActive == "" { - app.BorderActive = sampleConfig.AppButtons.Color + sampleConfig.Apps[num].BorderActive = sampleConfig.AppButtons.Color } // app.Separator can be omitted, in that case it is false // app.SeparatorBlockWidth can be missing if app.FullText == "" { - app.FullText = fmt.Sprintf(" %d ", num) + sampleConfig.Apps[num].FullText = fmt.Sprintf(" %d ", num) } } }