From b97ba80aea3d15978eb161434a411aebb0bf28ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 27 Jul 2021 16:32:13 +0200 Subject: [PATCH] bar: add border.{left,right,top,bottom}-width This allows you to configure the width of each side of the border individually. border.width can still be used, and will set all four borders to the same width. Closes #77 --- CHANGELOG.md | 5 +++++ bar/bar.c | 56 +++++++++++++++++++++++++++++++----------------- bar/bar.h | 3 ++- bar/private.h | 3 ++- bar/wayland.c | 2 +- config-verify.c | 4 ++++ config.c | 18 +++++++++++++++- doc/yambar.5.scd | 18 +++++++++++++++- 8 files changed, 84 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4156e05..b9a6669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ * i3: `persistent` attribute, allowing persistent workspaces (https://codeberg.org/dnkl/yambar/issues/72). +* bar: `border.{left,right,top,bottom}-width`, allowing the width of + each side of the border to be configured + individually. `border.width` is now a short-hand for setting all + four borders to the same value + (https://codeberg.org/dnkl/yambar/issues/77). ### Changed diff --git a/bar/bar.c b/bar/bar.c index 9806f44..4829162 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -67,16 +67,28 @@ expose(const struct bar *_bar) PIXMAN_OP_SRC, pix, &bar->background, 1, &(pixman_rectangle16_t){0, 0, bar->width, bar->height_with_border}); - if (bar->border.width > 0) { - pixman_image_fill_rectangles( - PIXMAN_OP_OVER, pix, &bar->border.color, 4, - (pixman_rectangle16_t[]){ - {0, 0, bar->width, bar->border.width}, - {0, 0, bar->border.width, bar->height_with_border}, - {bar->width - bar->border.width, 0, bar->border.width, bar->height_with_border}, - {0, bar->height_with_border - bar->border.width, bar->width, bar->border.width}, - }); - } + pixman_image_fill_rectangles( + PIXMAN_OP_OVER, pix, &bar->border.color, 4, + (pixman_rectangle16_t[]){ + /* Left */ + {0, 0, bar->border.left_width, bar->height_with_border}, + + /* Right */ + {bar->width - bar->border.right_width, + 0, bar->border.right_width, bar->height_with_border}, + + /* Top */ + {bar->border.left_width, + 0, + bar->width - bar->border.left_width - bar->border.right_width, + bar->border.top_width}, + + /* Bottom */ + {bar->border.left_width, + bar->height_with_border - bar->border.bottom_width, + bar->width - bar->border.left_width - bar->border.right_width, + bar->border.bottom_width}, + }); for (size_t i = 0; i < bar->left.count; i++) { struct module *m = bar->left.mods[i]; @@ -105,8 +117,8 @@ expose(const struct bar *_bar) int left_width, center_width, right_width; calculate_widths(bar, &left_width, ¢er_width, &right_width); - int y = bar->border.width; - int x = bar->border.width + bar->left_margin - bar->left_spacing; + int y = bar->border.top_width; + int x = bar->border.left_width + bar->left_margin - bar->left_spacing; for (size_t i = 0; i < bar->left.count; i++) { const struct exposable *e = bar->left.exps[i]; e->expose(e, pix, x + bar->left_spacing, y, bar->height); @@ -124,7 +136,7 @@ expose(const struct bar *_bar) right_width + bar->left_spacing + bar->right_margin + - bar->border.width); + bar->border.right_width); for (size_t i = 0; i < bar->right.count; i++) { const struct exposable *e = bar->right.exps[i]; @@ -156,9 +168,9 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, { struct private *bar = _bar->private; - if ((y < bar->border.width || - y >= (bar->height_with_border - bar->border.width)) || - (x < bar->border.width || x >= (bar->width - bar->border.width))) + if ((y < bar->border.top_width || + y >= (bar->height_with_border - bar->border.bottom_width)) || + (x < bar->border.left_width || x >= (bar->width - bar->border.right_width))) { set_cursor(_bar, "left_ptr"); return; @@ -167,7 +179,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, int left_width, center_width, right_width; calculate_widths(bar, &left_width, ¢er_width, &right_width); - int mx = bar->border.width + bar->left_margin - bar->left_spacing; + int mx = bar->border.left_width + bar->left_margin - bar->left_spacing; for (size_t i = 0; i < bar->left.count; i++) { struct exposable *e = bar->left.exps[i]; @@ -198,7 +210,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, mx = bar->width - (right_width + bar->left_spacing + bar->right_margin + - bar->border.width); + bar->border.right_width); for (size_t i = 0; i < bar->right.count; i++) { struct exposable *e = bar->right.exps[i]; @@ -236,7 +248,8 @@ run(struct bar *_bar) { struct private *bar = _bar->private; - bar->height_with_border = bar->height + 2 * bar->border.width; + bar->height_with_border = + bar->height + bar->border.top_width + bar->border.bottom_width; if (!bar->backend.iface->setup(_bar)) { bar->backend.iface->cleanup(_bar); @@ -409,7 +422,10 @@ bar_new(const struct bar_config *config) priv->left_margin = config->left_margin; priv->right_margin = config->right_margin; priv->trackpad_sensitivity = config->trackpad_sensitivity; - priv->border.width = config->border.width; + priv->border.left_width = config->border.left_width; + priv->border.right_width = config->border.right_width; + priv->border.top_width = config->border.top_width; + priv->border.bottom_width = config->border.bottom_width; priv->border.color = config->border.color; priv->border.left_margin = config->border.left_margin; priv->border.right_margin = config->border.right_margin; diff --git a/bar/bar.h b/bar/bar.h index 4e82534..5d154dd 100644 --- a/bar/bar.h +++ b/bar/bar.h @@ -30,7 +30,8 @@ struct bar_config { pixman_color_t background; struct { - int width; + int left_width, right_width; + int top_width, bottom_width; pixman_color_t color; int left_margin, right_margin; int top_margin, bottom_margin; diff --git a/bar/private.h b/bar/private.h index eed532b..56e59bb 100644 --- a/bar/private.h +++ b/bar/private.h @@ -15,7 +15,8 @@ struct private { pixman_color_t background; struct { - int width; + int left_width, right_width; + int top_width, bottom_width; pixman_color_t color; int left_margin, right_margin; int top_margin, bottom_margin; diff --git a/bar/wayland.c b/bar/wayland.c index 7e63cf0..ef62025 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -891,7 +891,7 @@ update_size(struct wayland_backend *backend) int height = bar->height_with_border; height /= scale; height *= scale; - bar->height = height - 2 * bar->border.width; + bar->height = height - bar->border.top_width - bar->border.bottom_width; bar->height_with_border = height; zwlr_layer_surface_v1_set_size( diff --git a/config-verify.c b/config-verify.c index 6c09a4a..7c4f365 100644 --- a/config-verify.c +++ b/config-verify.c @@ -371,6 +371,10 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"width", false, &conf_verify_int}, + {"left-width", false, &conf_verify_int}, + {"right-width", false, &conf_verify_int}, + {"top-width", false, &conf_verify_int}, + {"bottom-width", false, &conf_verify_int}, {"color", false, &conf_verify_color}, {"margin", false, &conf_verify_int}, {"left-margin", false, &conf_verify_int}, diff --git a/config.c b/config.c index bc6d7a7..241e25b 100644 --- a/config.c +++ b/config.c @@ -261,6 +261,10 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend) const struct yml_node *border = yml_get_value(bar, "border"); if (border != NULL) { const struct yml_node *width = yml_get_value(border, "width"); + const struct yml_node *left_width = yml_get_value(border, "left-width"); + const struct yml_node *right_width = yml_get_value(border, "right-width"); + const struct yml_node *top_width = yml_get_value(border, "top-width"); + const struct yml_node *bottom_width = yml_get_value(border, "bottom-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"); @@ -269,7 +273,19 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend) const struct yml_node *bottom_margin = yml_get_value(border, "bottom-margin"); if (width != NULL) - conf.border.width = yml_value_as_int(width); + conf.border.left_width = + conf.border.right_width = + conf.border.top_width = + conf.border.bottom_width = yml_value_as_int(width); + + if (left_width != NULL) + conf.border.left_width = yml_value_as_int(left_width); + if (right_width != NULL) + conf.border.right_width = yml_value_as_int(right_width); + if (top_width != NULL) + conf.border.top_width = yml_value_as_int(top_width); + if (bottom_width != NULL) + conf.border.bottom_width = yml_value_as_int(bottom_width); if (color != NULL) conf.border.color = conf_to_color(color); diff --git a/doc/yambar.5.scd b/doc/yambar.5.scd index d352e0e..9e1eefa 100644 --- a/doc/yambar.5.scd +++ b/doc/yambar.5.scd @@ -73,10 +73,26 @@ types that are frequently used: : associative array : no : Configures the border around the status bar +| border.left-width +: int +: no +: Width of the border on the left side, in pixels +| border.right-width +: int +: no +: Width of the border on the right side, in pixels +| border.top-width +: int +: no +: Width of the border on the top side, in pixels +| border.bottom-width +: int +: no +: Width of the border on the bottom side, in pixels | border.width : int : no -: Width, in pixels, of the border +: Short-hand for setting _border.left/right/top/bottom-width_ | border.color : color : no