From 921cda0a8174d739963e1ee792e759307c9b647b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 17 Nov 2018 11:54:14 +0100 Subject: [PATCH] bar: make location configurable (top or bottom) --- bar.c | 9 +++++---- bar.h | 4 ++++ config.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bar.c b/bar.c index f329595..baa4fe7 100644 --- a/bar.c +++ b/bar.c @@ -24,6 +24,7 @@ struct private { /* From bar_config */ + enum bar_location location; int height; int left_spacing, right_spacing; int left_margin, right_margin; @@ -189,8 +190,6 @@ run(struct bar_run_context *run_ctx) &e); assert(e == NULL); - const bool at_top = false; - bar->height_with_border = bar->height + 2 * bar->border.width; /* Find monitor coordinates and width/height */ @@ -215,7 +214,8 @@ run(struct bar_run_context *run_ctx) bar->x = mon->x; bar->y = mon->y; bar->width = mon->width; - bar->y += at_top ? 0 : screen->height_in_pixels - bar->height_with_border; + bar->y += bar->location == BAR_TOP ? 0 + : screen->height_in_pixels - bar->height_with_border; break; } free(monitors); @@ -317,7 +317,7 @@ run(struct bar_run_context *run_ctx) uint32_t top_strut, bottom_strut; uint32_t top_pair[2], bottom_pair[2]; - if (at_top) { + if (bar->location == BAR_TOP) { top_strut = bar->y + bar->height_with_border; top_pair[0] = bar->x; top_pair[1] = bar->x + bar->width - 1; @@ -530,6 +530,7 @@ struct bar * bar_new(const struct bar_config *config) { struct private *priv = malloc(sizeof(*priv)); + priv->location = config->location; priv->height = config->height; priv->background = config->background; priv->left_spacing = config->left_spacing; diff --git a/bar.h b/bar.h index 7ae9d88..916621c 100644 --- a/bar.h +++ b/bar.h @@ -8,6 +8,7 @@ struct bar_run_context { struct bar *bar; int abort_fd; }; + struct bar { void *private; int (*run)(struct bar_run_context *ctx); @@ -15,7 +16,10 @@ struct bar { void (*refresh)(const struct bar *bar); }; +enum bar_location { BAR_TOP, BAR_BOTTOM }; + struct bar_config { + enum bar_location location; int height; int left_spacing, right_spacing; int left_margin, right_margin; diff --git a/config.c b/config.c index 3327b8a..3327ef9 100644 --- a/config.c +++ b/config.c @@ -198,6 +198,7 @@ conf_to_bar(const struct yml_node *bar) struct font *font = font_new("sans", 12, false, false, 0); const struct yml_node *height = yml_get_value(bar, "height"); + const struct yml_node *location = yml_get_value(bar, "location"); const struct yml_node *background = yml_get_value(bar, "background"); const struct yml_node *spacing = yml_get_value(bar, "spacing"); const struct yml_node *left_spacing = yml_get_value(bar, "left_spacing"); @@ -214,6 +215,18 @@ conf_to_bar(const struct yml_node *bar) 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));