diff --git a/README.md b/README.md index c19e8d3..123a205 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,13 @@ There are a couple types used that are specific to f00bar. | right-margin | int | no | Right-side margin, in pixels | margin | int | no | Short-hand for setting both `left-margin` and `right-margin` | border | dict | no | Configures a border around the status bar -| border.width | int | yes | Width, in pixels, of the border -| border.color | color | yes | The color of the border +| border.width | int | no | Width, in pixels, of the border +| border.color | color | no | The color of the border +| border.margin | int | no | left/rigth/top/bottom margins, from screen edge to bar. _Wayland only_ +| border.left-margin | int | no | left margin from screen edge to bar. Overrides `border.margin`. _Wayland only_ +| border.right-margin | int | no | right margin from screen edge to bar. Overrides `border.margin`. _Wayland only_ +| border.top-margin | int | no | top margin from screen edge to bar. Overrides `border.margin`. _Wayland only_ +| border.bottom-margin | int | no | bottom margin from screen edge to bar. Overrides `border.margin`. _Wayland only_ | font | font | no | Default font to use in modules and particles | foreground | color | no | Default foreground (text) color to use | left | list | no | Left-aligned modules diff --git a/bar/bar.c b/bar/bar.c index f252ca5..f643b0d 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -378,6 +378,10 @@ bar_new(const struct bar_config *config) priv->right_margin = config->right_margin; priv->border.width = config->border.width; priv->border.color = config->border.color; + priv->border.left_margin = config->border.left_margin; + priv->border.right_margin = config->border.right_margin; + priv->border.top_margin = config->border.top_margin; + priv->border.bottom_margin = config->border.bottom_margin; priv->left.mods = malloc(config->left.count * sizeof(priv->left.mods[0])); priv->left.exps = calloc(config->left.count, sizeof(priv->left.exps[0])); priv->center.mods = malloc(config->center.count * sizeof(priv->center.mods[0])); diff --git a/bar/bar.h b/bar/bar.h index b4765a2..90bbb96 100644 --- a/bar/bar.h +++ b/bar/bar.h @@ -28,6 +28,8 @@ struct bar_config { struct { int width; struct rgba color; + int left_margin, right_margin; + int top_margin, bottom_margin; } border; struct { diff --git a/bar/private.h b/bar/private.h index 647fb20..0f86e86 100644 --- a/bar/private.h +++ b/bar/private.h @@ -19,6 +19,8 @@ struct private { struct { int width; struct rgba color; + int left_margin, right_margin; + int top_margin, bottom_margin; } border; struct { @@ -38,7 +40,6 @@ struct private { } right; /* Calculated run-time */ - int x, y; int width; int height_with_border; diff --git a/bar/wayland.c b/bar/wayland.c index 00fcd1a..0d06f4a 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -631,11 +631,18 @@ setup(struct bar *_bar) zwlr_layer_surface_v1_set_size( backend->layer_surface, 0, bar->height_with_border); zwlr_layer_surface_v1_set_exclusive_zone( - backend->layer_surface, bar->height_with_border); + backend->layer_surface, + bar->height_with_border + (bar->location == BAR_TOP ? + bar->border.bottom_margin : + bar->border.top_margin)); - //zwlr_layer_surface_v1_set_margin( - // layer_surface, margin_top, margin_right, margin_bottom, margin_left); - //zwlr_layer_surface_v1_set_keyboard_interactivity(backend->layer_surface, 1); + zwlr_layer_surface_v1_set_margin( + backend->layer_surface, + bar->border.top_margin, + bar->border.right_margin, + bar->border.bottom_margin, + bar->border.left_margin + ); zwlr_layer_surface_v1_add_listener( backend->layer_surface, &layer_surface_listener, backend); @@ -649,12 +656,8 @@ setup(struct bar *_bar) return false; } + assert(backend->width <= backend->monitor->width_px); bar->width = backend->width; - bar->x = backend->monitor->x; - bar->y = backend->monitor->y; - bar->y += bar->location == BAR_TOP - ? 0 - : backend->monitor->height_px - bar->height_with_border; if (pipe(backend->pipe_fds) == -1) { LOG_ERRNO("failed to create pipe"); diff --git a/bar/xcb.c b/bar/xcb.c index 3f0d284..30fdba0 100644 --- a/bar/xcb.c +++ b/bar/xcb.c @@ -21,6 +21,8 @@ #include "../xcb.h" struct xcb_backend { + int x, y; + xcb_connection_t *conn; xcb_window_t win; @@ -44,6 +46,14 @@ setup(struct bar *_bar) struct private *bar = _bar->private; struct xcb_backend *backend = bar->backend.data; + if (bar->border.left_margin != 0 || + bar->border.right_margin != 0 || + bar->border.top_margin != 0 || + bar->border.bottom_margin) + { + LOG_WARN("non-zero border margins ignored in X11 backend"); + } + /* TODO: a lot of this (up to mapping the window) could be done in bar_new() */ xcb_generic_error_t *e; @@ -92,10 +102,10 @@ setup(struct bar *_bar) free(name); - bar->x = mon->x; - bar->y = mon->y; + backend->x = mon->x; + backend->y = mon->y; bar->width = mon->width; - bar->y += bar->location == BAR_TOP ? 0 + backend->y += bar->location == BAR_TOP ? 0 : screen->height_in_pixels - bar->height_with_border; found_monitor = true; break; @@ -131,7 +141,7 @@ setup(struct bar *_bar) xcb_create_window( backend->conn, depth, backend->win, screen->root, - bar->x, bar->y, bar->width, bar->height_with_border, + backend->x, backend->y, bar->width, bar->height_with_border, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, vis->visual_id, (XCB_CW_BACK_PIXEL | @@ -184,16 +194,16 @@ setup(struct bar *_bar) uint32_t top_pair[2], bottom_pair[2]; 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; + top_strut = backend->y + bar->height_with_border; + top_pair[0] = backend->x; + top_pair[1] = backend->x + bar->width - 1; bottom_strut = 0; bottom_pair[0] = bottom_pair[1] = 0; } else { - bottom_strut = screen->height_in_pixels - bar->y; - bottom_pair[0] = bar->x; - bottom_pair[1] = bar->x + bar->width - 1; + bottom_strut = screen->height_in_pixels - backend->y; + bottom_pair[0] = backend->x; + bottom_pair[1] = backend->x + bar->width - 1; top_strut = 0; top_pair[0] = top_pair[1] = 0; diff --git a/config-verify.c b/config-verify.c index f947979..41911a1 100644 --- a/config-verify.c +++ b/config-verify.c @@ -329,8 +329,13 @@ static bool verify_bar_border(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"width", true, &conf_verify_int}, - {"color", true, &conf_verify_color}, + {"width", false, &conf_verify_int}, + {"color", false, &conf_verify_color}, + {"margin", false, &conf_verify_int}, + {"left-margin", false, &conf_verify_int}, + {"right-margin", false, &conf_verify_int}, + {"top-margin", false, &conf_verify_int}, + {"bottom-margin", false, &conf_verify_int}, {NULL, false, NULL}, }; diff --git a/config.c b/config.c index 73590ea..d576460 100644 --- a/config.c +++ b/config.c @@ -226,12 +226,32 @@ conf_to_bar(const struct yml_node *bar) if (border != NULL) { const struct yml_node *width = yml_get_value(border, "width"); const struct yml_node *color = yml_get_value(border, "color"); + const struct yml_node *margin = yml_get_value(border, "margin"); + const struct yml_node *left_margin = yml_get_value(border, "left-margin"); + const struct yml_node *right_margin = yml_get_value(border, "right-margin"); + const struct yml_node *top_margin = yml_get_value(border, "top-margin"); + const struct yml_node *bottom_margin = yml_get_value(border, "bottom-margin"); if (width != NULL) conf.border.width = yml_value_as_int(width); if (color != NULL) conf.border.color = conf_to_color(color); + + if (margin != NULL) + conf.border.left_margin = + conf.border.right_margin = + conf.border.top_margin = + conf.border.bottom_margin = yml_value_as_int(margin); + + if (left_margin != NULL) + conf.border.left_margin = yml_value_as_int(left_margin); + if (right_margin != NULL) + conf.border.right_margin = yml_value_as_int(right_margin); + if (top_margin != NULL) + conf.border.top_margin = yml_value_as_int(top_margin); + if (bottom_margin != NULL) + conf.border.bottom_margin = yml_value_as_int(bottom_margin); } /*