diff options
author | Ingo Bürk <admin@airblader.de> | 2019-06-22 22:18:29 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2019-06-22 22:18:29 +0200 |
commit | ca82f958125483a0e99c4ab82cda1b188754b32b (patch) | |
tree | d622d61f1a70fcde174f807f3da09ea7d1dec38a /i3bar | |
parent | 48af067dfe56545ccf0f462db4f62bb12ac16004 (diff) | |
download | i3-ca82f958125483a0e99c4ab82cda1b188754b32b.tar.gz i3-ca82f958125483a0e99c4ab82cda1b188754b32b.zip |
feat: added support for user-defined border widths in i3bar blocks (#3726)
This change introduces support for four new properties on the i3bar
protocol, namely "border_top", "border_right", "border_bottom"
and "border_left".
If a block is drawn with a border, these values define the width of
the corresponding edge in pixels. They all default to 1 if not
specified to preserve compatibility.
fixes #3722
Diffstat (limited to 'i3bar')
-rw-r--r-- | i3bar/include/common.h | 4 | ||||
-rw-r--r-- | i3bar/src/child.c | 22 | ||||
-rw-r--r-- | i3bar/src/xcb.c | 17 |
3 files changed, 35 insertions, 8 deletions
diff --git a/i3bar/include/common.h b/i3bar/include/common.h index 77be3182..fe7444a3 100644 --- a/i3bar/include/common.h +++ b/i3bar/include/common.h @@ -61,6 +61,10 @@ struct status_block { bool urgent; bool no_separator; + uint32_t border_top; + uint32_t border_right; + uint32_t border_bottom; + uint32_t border_left; bool pango_markup; /* The amount of pixels necessary to render a separater after the block. */ diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 549a2f70..83ee26b4 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -176,6 +176,12 @@ static int stdin_start_map(void *context) { else ctx->block.sep_block_width = logical_px(8) + separator_symbol_width; + /* By default we draw all four borders if a border is set. */ + ctx->block.border_top = 1; + ctx->block.border_right = 1; + ctx->block.border_bottom = 1; + ctx->block.border_left = 1; + return 1; } @@ -262,6 +268,22 @@ static int stdin_integer(void *context, long long val) { ctx->block.sep_block_width = (uint32_t)val; return 1; } + if (strcasecmp(ctx->last_map_key, "border_top") == 0) { + ctx->block.border_top = (uint32_t)val; + return 1; + } + if (strcasecmp(ctx->last_map_key, "border_right") == 0) { + ctx->block.border_right = (uint32_t)val; + return 1; + } + if (strcasecmp(ctx->last_map_key, "border_bottom") == 0) { + ctx->block.border_bottom = (uint32_t)val; + return 1; + } + if (strcasecmp(ctx->last_map_key, "border_left") == 0) { + ctx->block.border_left = (uint32_t)val; + return 1; + } return 1; } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 33e13c1b..412981bc 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -213,7 +213,7 @@ static uint32_t predict_statusline_length(bool use_short_text) { render->width = predict_text_width(text); if (block->border) - render->width += logical_px(2); + render->width += logical_px(block->border_left + block->border_right); /* Compute offset and append for text aligment in min_width. */ if (block->min_width <= render->width) { @@ -287,8 +287,8 @@ static void draw_statusline(i3_output *output, uint32_t clip_left, bool use_focu color_t bg_color = bar_color; - int border_width = (block->border) ? logical_px(1) : 0; int full_render_width = render->width + render->x_offset + render->x_append; + int has_border = block->border ? 1 : 0; if (block->border || block->background || block->urgent) { /* Let's determine the colors first. */ color_t border_color = bar_color; @@ -310,15 +310,16 @@ static void draw_statusline(i3_output *output, uint32_t clip_left, bool use_focu /* Draw the background. */ draw_util_rectangle(&output->statusline_buffer, bg_color, - x + border_width, - logical_px(1) + border_width, - full_render_width - 2 * border_width, - bar_height - 2 * border_width - logical_px(2)); + x + has_border * logical_px(block->border_left), + logical_px(1) + has_border * logical_px(block->border_top), + full_render_width - has_border * logical_px(block->border_right + block->border_left), + bar_height - has_border * logical_px(block->border_bottom + block->border_top) - logical_px(2)); } draw_util_text(text, &output->statusline_buffer, fg_color, bg_color, - x + render->x_offset + border_width, logical_px(ws_voff_px), - render->width - 2 * border_width); + x + render->x_offset + has_border * logical_px(block->border_left), + bar_height / 2 - font.height / 2, + render->width - has_border * logical_px(block->border_left + block->border_right)); x += full_render_width; /* If this is not the last block, draw a separator. */ |