forked from external/yambar
bar: make location configurable (top or bottom)
This commit is contained in:
parent
7c468c20c0
commit
921cda0a81
3 changed files with 22 additions and 4 deletions
9
bar.c
9
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;
|
||||
|
|
4
bar.h
4
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;
|
||||
|
|
13
config.c
13
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));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue