Finally fix parsing of app buttons, now settings and fallback values should work as expected

This commit is contained in:
eleksir
2025-07-15 14:08:34 +03:00
parent 069b09e5ec
commit 7f76a68139
3 changed files with 35 additions and 28 deletions

View File

@@ -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.

View File

@@ -192,7 +192,14 @@ func main() {
)
}
b.FullText = app.FullText
b.FullText = fmt.Sprintf(
"<span color='%s' background='%s' font='%s' size='%s'>%s</span>",
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

View File

@@ -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)
}
}
}