mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-21 03:45:42 +02:00
config: bar: no need to check for NULL on required attributes
This commit is contained in:
parent
61a2f84651
commit
3f578d30eb
2 changed files with 34 additions and 33 deletions
|
@ -632,16 +632,20 @@ config_verify_bar(const struct yml_node *bar)
|
||||||
|
|
||||||
static const struct attr_info attrs[] = {
|
static const struct attr_info attrs[] = {
|
||||||
{"height", true, &verify_int},
|
{"height", true, &verify_int},
|
||||||
|
{"location", true, &verify_bar_location},
|
||||||
|
{"background", true, &verify_color},
|
||||||
|
|
||||||
{"spacing", false, &verify_int},
|
{"spacing", false, &verify_int},
|
||||||
{"left_spacing", false, &verify_int},
|
{"left_spacing", false, &verify_int},
|
||||||
{"right_spacing", false, &verify_int},
|
{"right_spacing", false, &verify_int},
|
||||||
|
|
||||||
{"margin", false, &verify_int},
|
{"margin", false, &verify_int},
|
||||||
{"left_margin", false, &verify_int},
|
{"left_margin", false, &verify_int},
|
||||||
{"right_margin", false, &verify_int},
|
{"right_margin", false, &verify_int},
|
||||||
{"location", true, &verify_bar_location},
|
|
||||||
{"background", true, &verify_color},
|
|
||||||
{"border", false, &verify_bar_border},
|
{"border", false, &verify_bar_border},
|
||||||
{"font", false, &verify_font},
|
{"font", false, &verify_font},
|
||||||
|
|
||||||
{"left", false, &verify_module_list},
|
{"left", false, &verify_module_list},
|
||||||
{"center", false, &verify_module_list},
|
{"center", false, &verify_module_list},
|
||||||
{"right", false, &verify_module_list},
|
{"right", false, &verify_module_list},
|
||||||
|
|
59
config.c
59
config.c
|
@ -597,60 +597,49 @@ conf_to_bar(const struct yml_node *bar)
|
||||||
|
|
||||||
struct bar_config conf = {0};
|
struct bar_config conf = {0};
|
||||||
|
|
||||||
/* Create a default font */
|
/*
|
||||||
struct font *font = font_new("sans");
|
* Required attributes
|
||||||
|
*/
|
||||||
|
|
||||||
const struct yml_node *height = yml_get_value(bar, "height");
|
const struct yml_node *height = yml_get_value(bar, "height");
|
||||||
|
conf.height = yml_value_as_int(height);
|
||||||
|
|
||||||
const struct yml_node *location = yml_get_value(bar, "location");
|
const struct yml_node *location = yml_get_value(bar, "location");
|
||||||
|
conf.location = strcmp(yml_value_as_string(location), "top") == 0
|
||||||
|
? BAR_TOP : BAR_BOTTOM;
|
||||||
|
|
||||||
const struct yml_node *background = yml_get_value(bar, "background");
|
const struct yml_node *background = yml_get_value(bar, "background");
|
||||||
|
conf.background = color_from_hexstr(yml_value_as_string(background));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Optional attributes
|
||||||
|
*/
|
||||||
|
|
||||||
const struct yml_node *spacing = yml_get_value(bar, "spacing");
|
const struct yml_node *spacing = yml_get_value(bar, "spacing");
|
||||||
const struct yml_node *left_spacing = yml_get_value(bar, "left_spacing");
|
|
||||||
const struct yml_node *right_spacing = yml_get_value(bar, "right_spacing");
|
|
||||||
const struct yml_node *margin = yml_get_value(bar, "margin");
|
|
||||||
const struct yml_node *left_margin = yml_get_value(bar, "left_margin");
|
|
||||||
const struct yml_node *right_margin = yml_get_value(bar, "right_margin");
|
|
||||||
const struct yml_node *border = yml_get_value(bar, "border");
|
|
||||||
const struct yml_node *font_node = yml_get_value(bar, "font");
|
|
||||||
const struct yml_node *left = yml_get_value(bar, "left");
|
|
||||||
const struct yml_node *center = yml_get_value(bar, "center");
|
|
||||||
const struct yml_node *right = yml_get_value(bar, "right");
|
|
||||||
|
|
||||||
if (height != NULL)
|
|
||||||
conf.height = yml_value_as_int(height);
|
|
||||||
|
|
||||||
if (location != NULL) {
|
|
||||||
const char *loc = yml_value_as_string(location);
|
|
||||||
assert(strcasecmp(loc, "top") == 0 || strcasecmp(loc, "bottom") == 0);
|
|
||||||
|
|
||||||
if (strcasecmp(loc, "top") == 0)
|
|
||||||
conf.location = BAR_TOP;
|
|
||||||
else if (strcasecmp(loc, "bottom") == 0)
|
|
||||||
conf.location = BAR_BOTTOM;
|
|
||||||
else
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (background != NULL)
|
|
||||||
conf.background = color_from_hexstr(yml_value_as_string(background));
|
|
||||||
|
|
||||||
if (spacing != NULL)
|
if (spacing != NULL)
|
||||||
conf.left_spacing = conf.right_spacing = yml_value_as_int(spacing);
|
conf.left_spacing = conf.right_spacing = yml_value_as_int(spacing);
|
||||||
|
|
||||||
|
const struct yml_node *left_spacing = yml_get_value(bar, "left_spacing");
|
||||||
if (left_spacing != NULL)
|
if (left_spacing != NULL)
|
||||||
conf.left_spacing = yml_value_as_int(left_spacing);
|
conf.left_spacing = yml_value_as_int(left_spacing);
|
||||||
|
|
||||||
|
const struct yml_node *right_spacing = yml_get_value(bar, "right_spacing");
|
||||||
if (right_spacing != NULL)
|
if (right_spacing != NULL)
|
||||||
conf.right_spacing = yml_value_as_int(right_spacing);
|
conf.right_spacing = yml_value_as_int(right_spacing);
|
||||||
|
|
||||||
|
const struct yml_node *margin = yml_get_value(bar, "margin");
|
||||||
if (margin != NULL)
|
if (margin != NULL)
|
||||||
conf.left_margin = conf.right_margin = yml_value_as_int(margin);
|
conf.left_margin = conf.right_margin = yml_value_as_int(margin);
|
||||||
|
|
||||||
|
const struct yml_node *left_margin = yml_get_value(bar, "left_margin");
|
||||||
if (left_margin != NULL)
|
if (left_margin != NULL)
|
||||||
conf.left_margin = yml_value_as_int(left_margin);
|
conf.left_margin = yml_value_as_int(left_margin);
|
||||||
|
|
||||||
|
const struct yml_node *right_margin = yml_get_value(bar, "right_margin");
|
||||||
if (right_margin != NULL)
|
if (right_margin != NULL)
|
||||||
conf.right_margin = yml_value_as_int(right_margin);
|
conf.right_margin = yml_value_as_int(right_margin);
|
||||||
|
|
||||||
|
const struct yml_node *border = yml_get_value(bar, "border");
|
||||||
if (border != NULL) {
|
if (border != NULL) {
|
||||||
assert(yml_is_dict(border));
|
assert(yml_is_dict(border));
|
||||||
|
|
||||||
|
@ -664,11 +653,19 @@ conf_to_bar(const struct yml_node *bar)
|
||||||
conf.border.color = color_from_hexstr(yml_value_as_string(color));
|
conf.border.color = color_from_hexstr(yml_value_as_string(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create a default font */
|
||||||
|
struct font *font = font_new("sans");
|
||||||
|
|
||||||
|
const struct yml_node *font_node = yml_get_value(bar, "font");
|
||||||
if (font_node != NULL) {
|
if (font_node != NULL) {
|
||||||
font_destroy(font);
|
font_destroy(font);
|
||||||
font = font_from_config(font_node);
|
font = font_from_config(font_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct yml_node *left = yml_get_value(bar, "left");
|
||||||
|
const struct yml_node *center = yml_get_value(bar, "center");
|
||||||
|
const struct yml_node *right = yml_get_value(bar, "right");
|
||||||
|
|
||||||
for (size_t i = 0; i < 3; i++) {
|
for (size_t i = 0; i < 3; i++) {
|
||||||
const struct yml_node *node = i == 0 ? left : i == 1 ? center : right;
|
const struct yml_node *node = i == 0 ? left : i == 1 ? center : right;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue