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
This commit is contained in:
Daniel Eklöf 2021-07-27 16:32:13 +02:00
parent 8c095eb423
commit b97ba80aea
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
8 changed files with 84 additions and 25 deletions

View file

@ -12,6 +12,11 @@
* i3: `persistent` attribute, allowing persistent workspaces * i3: `persistent` attribute, allowing persistent workspaces
(https://codeberg.org/dnkl/yambar/issues/72). (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 ### Changed

View file

@ -67,16 +67,28 @@ expose(const struct bar *_bar)
PIXMAN_OP_SRC, pix, &bar->background, 1, PIXMAN_OP_SRC, pix, &bar->background, 1,
&(pixman_rectangle16_t){0, 0, bar->width, bar->height_with_border}); &(pixman_rectangle16_t){0, 0, bar->width, bar->height_with_border});
if (bar->border.width > 0) {
pixman_image_fill_rectangles( pixman_image_fill_rectangles(
PIXMAN_OP_OVER, pix, &bar->border.color, 4, PIXMAN_OP_OVER, pix, &bar->border.color, 4,
(pixman_rectangle16_t[]){ (pixman_rectangle16_t[]){
{0, 0, bar->width, bar->border.width}, /* Left */
{0, 0, bar->border.width, bar->height_with_border}, {0, 0, bar->border.left_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}, /* 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++) { for (size_t i = 0; i < bar->left.count; i++) {
struct module *m = bar->left.mods[i]; struct module *m = bar->left.mods[i];
@ -105,8 +117,8 @@ expose(const struct bar *_bar)
int left_width, center_width, right_width; int left_width, center_width, right_width;
calculate_widths(bar, &left_width, &center_width, &right_width); calculate_widths(bar, &left_width, &center_width, &right_width);
int y = bar->border.width; int y = bar->border.top_width;
int x = bar->border.width + bar->left_margin - bar->left_spacing; int x = bar->border.left_width + bar->left_margin - bar->left_spacing;
for (size_t i = 0; i < bar->left.count; i++) { for (size_t i = 0; i < bar->left.count; i++) {
const struct exposable *e = bar->left.exps[i]; const struct exposable *e = bar->left.exps[i];
e->expose(e, pix, x + bar->left_spacing, y, bar->height); e->expose(e, pix, x + bar->left_spacing, y, bar->height);
@ -124,7 +136,7 @@ expose(const struct bar *_bar)
right_width + right_width +
bar->left_spacing + bar->left_spacing +
bar->right_margin + bar->right_margin +
bar->border.width); bar->border.right_width);
for (size_t i = 0; i < bar->right.count; i++) { for (size_t i = 0; i < bar->right.count; i++) {
const struct exposable *e = bar->right.exps[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; struct private *bar = _bar->private;
if ((y < bar->border.width || if ((y < bar->border.top_width ||
y >= (bar->height_with_border - bar->border.width)) || y >= (bar->height_with_border - bar->border.bottom_width)) ||
(x < bar->border.width || x >= (bar->width - bar->border.width))) (x < bar->border.left_width || x >= (bar->width - bar->border.right_width)))
{ {
set_cursor(_bar, "left_ptr"); set_cursor(_bar, "left_ptr");
return; 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; int left_width, center_width, right_width;
calculate_widths(bar, &left_width, &center_width, &right_width); calculate_widths(bar, &left_width, &center_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++) { for (size_t i = 0; i < bar->left.count; i++) {
struct exposable *e = bar->left.exps[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 mx = bar->width - (right_width
+ bar->left_spacing + + bar->left_spacing +
bar->right_margin + bar->right_margin +
bar->border.width); bar->border.right_width);
for (size_t i = 0; i < bar->right.count; i++) { for (size_t i = 0; i < bar->right.count; i++) {
struct exposable *e = bar->right.exps[i]; struct exposable *e = bar->right.exps[i];
@ -236,7 +248,8 @@ run(struct bar *_bar)
{ {
struct private *bar = _bar->private; 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)) { if (!bar->backend.iface->setup(_bar)) {
bar->backend.iface->cleanup(_bar); bar->backend.iface->cleanup(_bar);
@ -409,7 +422,10 @@ bar_new(const struct bar_config *config)
priv->left_margin = config->left_margin; priv->left_margin = config->left_margin;
priv->right_margin = config->right_margin; priv->right_margin = config->right_margin;
priv->trackpad_sensitivity = config->trackpad_sensitivity; 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.color = config->border.color;
priv->border.left_margin = config->border.left_margin; priv->border.left_margin = config->border.left_margin;
priv->border.right_margin = config->border.right_margin; priv->border.right_margin = config->border.right_margin;

View file

@ -30,7 +30,8 @@ struct bar_config {
pixman_color_t background; pixman_color_t background;
struct { struct {
int width; int left_width, right_width;
int top_width, bottom_width;
pixman_color_t color; pixman_color_t color;
int left_margin, right_margin; int left_margin, right_margin;
int top_margin, bottom_margin; int top_margin, bottom_margin;

View file

@ -15,7 +15,8 @@ struct private {
pixman_color_t background; pixman_color_t background;
struct { struct {
int width; int left_width, right_width;
int top_width, bottom_width;
pixman_color_t color; pixman_color_t color;
int left_margin, right_margin; int left_margin, right_margin;
int top_margin, bottom_margin; int top_margin, bottom_margin;

View file

@ -891,7 +891,7 @@ update_size(struct wayland_backend *backend)
int height = bar->height_with_border; int height = bar->height_with_border;
height /= scale; height /= scale;
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; bar->height_with_border = height;
zwlr_layer_surface_v1_set_size( zwlr_layer_surface_v1_set_size(

View file

@ -371,6 +371,10 @@ verify_bar_border(keychain_t *chain, const struct yml_node *node)
{ {
static const struct attr_info attrs[] = { static const struct attr_info attrs[] = {
{"width", false, &conf_verify_int}, {"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}, {"color", false, &conf_verify_color},
{"margin", false, &conf_verify_int}, {"margin", false, &conf_verify_int},
{"left-margin", false, &conf_verify_int}, {"left-margin", false, &conf_verify_int},

View file

@ -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"); const struct yml_node *border = yml_get_value(bar, "border");
if (border != NULL) { if (border != NULL) {
const struct yml_node *width = yml_get_value(border, "width"); 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 *color = yml_get_value(border, "color");
const struct yml_node *margin = yml_get_value(border, "margin"); 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 *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"); const struct yml_node *bottom_margin = yml_get_value(border, "bottom-margin");
if (width != NULL) 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) if (color != NULL)
conf.border.color = conf_to_color(color); conf.border.color = conf_to_color(color);

View file

@ -73,10 +73,26 @@ types that are frequently used:
: associative array : associative array
: no : no
: Configures the border around the status bar : 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 | border.width
: int : int
: no : no
: Width, in pixels, of the border : Short-hand for setting _border.left/right/top/bottom-width_
| border.color | border.color
: color : color
: no : no