From 50d6afab6aac26b2829acd9a9e60f24a8348434c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 15:45:02 +0100 Subject: [PATCH 1/6] bar: add margin properties to the border --- bar/bar.c | 4 ++++ bar/bar.h | 2 ++ bar/private.h | 2 ++ config-verify.c | 5 +++++ config.c | 20 ++++++++++++++++++++ 5 files changed, 33 insertions(+) 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..78017c7 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 { diff --git a/config-verify.c b/config-verify.c index f947979..91dff96 100644 --- a/config-verify.c +++ b/config-verify.c @@ -331,6 +331,11 @@ 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}, + {"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); } /* From 9c611a716b3ba8b1bed0c184d766a65c40cdbfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 15:47:13 +0100 Subject: [PATCH 2/6] config: make border.width and border.color optional --- config-verify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config-verify.c b/config-verify.c index 91dff96..41911a1 100644 --- a/config-verify.c +++ b/config-verify.c @@ -329,8 +329,8 @@ 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}, From cb0c43a61b823bdbdd10c2e12e8c3d5ab98801e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 15:47:29 +0100 Subject: [PATCH 3/6] README: update bar configuration properties --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c19e8d3..a506a7f 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 +| border.left-margin | int | no | left margin from screen edge to bar. Overrides `border.margin` +| border.right-margin | int | no | right margin from screen edge to bar. Overrides `border.margin` +| border.top-margin | int | no | top margin from screen edge to bar. Overrides `border.margin` +| border.bottom-margin | int | no | bottom margin from screen edge to bar. Overrides `border.margin` | 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 From 3d8cb7f17e1106f6af6750b4bba5c63f1878121f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 15:47:44 +0100 Subject: [PATCH 4/6] bar/wayland: implement border margins --- bar/wayland.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bar/wayland.c b/bar/wayland.c index 00fcd1a..59f9ffd 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); From 0ab772f869ea7f63e77370074dec9d95b0c6c0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 19:40:20 +0100 Subject: [PATCH 5/6] bar: move x,y coordinates to xcb backend --- bar/private.h | 1 - bar/wayland.c | 5 ----- bar/xcb.c | 22 ++++++++++++---------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/bar/private.h b/bar/private.h index 78017c7..0f86e86 100644 --- a/bar/private.h +++ b/bar/private.h @@ -40,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 59f9ffd..b7cda6c 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -657,11 +657,6 @@ setup(struct bar *_bar) } 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..2a15965 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; @@ -92,10 +94,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 +133,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 +186,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; From 28d39f3aec94e71c40f35634b36afbcc1743880b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 17 Feb 2019 19:45:26 +0100 Subject: [PATCH 6/6] bar/xcb: ignore non-zero border margins --- README.md | 10 +++++----- bar/wayland.c | 1 + bar/xcb.c | 8 ++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a506a7f..123a205 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ There are a couple types used that are specific to f00bar. | border | dict | no | Configures a border around the status bar | 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 -| border.left-margin | int | no | left margin from screen edge to bar. Overrides `border.margin` -| border.right-margin | int | no | right margin from screen edge to bar. Overrides `border.margin` -| border.top-margin | int | no | top margin from screen edge to bar. Overrides `border.margin` -| border.bottom-margin | int | no | bottom margin from screen edge to bar. Overrides `border.margin` +| 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/wayland.c b/bar/wayland.c index b7cda6c..0d06f4a 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -656,6 +656,7 @@ setup(struct bar *_bar) return false; } + assert(backend->width <= backend->monitor->width_px); bar->width = backend->width; if (pipe(backend->pipe_fds) == -1) { diff --git a/bar/xcb.c b/bar/xcb.c index 2a15965..30fdba0 100644 --- a/bar/xcb.c +++ b/bar/xcb.c @@ -46,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;