From 033061aee602a54f65340e2a300054d2790c22ea Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Wed, 15 Sep 2021 05:07:07 -0500 Subject: swaybar: properly draw blocks with transparent black border while the draw itself is a no-op, alignment must still be accounted this requires more signalling about the blocks (border_set; was the border set?) --- swaybar/i3bar.c | 31 ++++++++++++++++--------------- swaybar/render.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 34 deletions(-) (limited to 'swaybar') diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 4bcd5843..6d00befb 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -28,6 +28,19 @@ void i3bar_block_unref(struct i3bar_block *block) { } } +static bool i3bar_parse_json_color(json_object *json, uint32_t *color) { + if (!json) { + return false; + } + + const char *hexstring = json_object_get_string(json); + bool color_set = parse_color(hexstring, color); + if (!color_set) { + sway_log(SWAY_ERROR, "Ignoring invalid block hexadecimal color string: %s", hexstring); + } + return color_set; +} + static void i3bar_parse_json(struct status_line *status, struct json_object *json_array) { struct i3bar_block *block, *tmp; @@ -68,13 +81,7 @@ static void i3bar_parse_json(struct status_line *status, strdup(json_object_get_string(full_text)) : NULL; block->short_text = short_text ? strdup(json_object_get_string(short_text)) : NULL; - if (color) { - const char *hexstring = json_object_get_string(color); - block->color_set = parse_color(hexstring, &block->color); - if (!block->color_set) { - sway_log(SWAY_ERROR, "Invalid block color: %s", hexstring); - } - } + block->color_set = i3bar_parse_json_color(color, &block->color); if (min_width) { json_type type = json_object_get_type(min_width); if (type == json_type_int) { @@ -100,14 +107,8 @@ static void i3bar_parse_json(struct status_line *status, block->separator_block_width = separator_block_width ? json_object_get_int(separator_block_width) : 9; // Airblader features - const char *hex = background ? json_object_get_string(background) : NULL; - if (hex && !parse_color(hex, &block->background)) { - sway_log(SWAY_ERROR, "Ignoring invalid block background: %s", hex); - } - hex = border ? json_object_get_string(border) : NULL; - if (hex && !parse_color(hex, &block->border)) { - sway_log(SWAY_ERROR, "Ignoring invalid block border: %s", hex); - } + i3bar_parse_json_color(background, &block->background); + block->border_set = i3bar_parse_json_color(border, &block->border); block->border_top = border_top ? json_object_get_int(border_top) : 1; block->border_bottom = border_bottom ? json_object_get_int(border_bottom) : 1; diff --git a/swaybar/render.c b/swaybar/render.c index 65cacd39..92b73f4c 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -14,6 +14,7 @@ #include "swaybar/ipc.h" #include "swaybar/render.h" #include "swaybar/status_line.h" +#include "log.h" #if HAVE_TRAY #include "swaybar/tray/tray.h" #endif @@ -215,11 +216,11 @@ static uint32_t render_status_block(struct render_context *ctx, } *x -= width; - if ((block->border || block->urgent) && block->border_left > 0) { + if ((block->border_set || block->urgent) && block->border_left > 0) { *x -= (block->border_left + margin); block_width += block->border_left + margin; } - if ((block->border || block->urgent) && block->border_right > 0) { + if ((block->border_set || block->urgent) && block->border_right > 0) { *x -= (block->border_right + margin); block_width += block->border_right + margin; } @@ -273,18 +274,20 @@ static uint32_t render_status_block(struct render_context *ctx, uint32_t border_color = block->urgent ? config->colors.urgent_workspace.border : block->border; - if (border_color && block->border_top > 0) { - render_sharp_line(cairo, border_color, x_pos, y_pos, - block_width, block->border_top); - } - if (border_color && block->border_bottom > 0) { - render_sharp_line(cairo, border_color, x_pos, - y_pos + render_height - block->border_bottom, - block_width, block->border_bottom); - } - if (border_color && block->border_left > 0) { - render_sharp_line(cairo, border_color, x_pos, y_pos, - block->border_left, render_height); + if (block->border_set || block->urgent) { + if (block->border_top > 0) { + render_sharp_line(cairo, border_color, x_pos, y_pos, + block_width, block->border_top); + } + if (block->border_bottom > 0) { + render_sharp_line(cairo, border_color, x_pos, + y_pos + render_height - block->border_bottom, + block_width, block->border_bottom); + } + if (block->border_left > 0) { + render_sharp_line(cairo, border_color, x_pos, y_pos, + block->border_left, render_height); + } x_pos += block->border_left + margin; } @@ -307,10 +310,12 @@ static uint32_t render_status_block(struct render_context *ctx, render_text(cairo, config->font, 1, block->markup, "%s", text); x_pos += width; - if (border_color && block->border_right > 0) { + if (block->border_set || block->urgent) { x_pos += margin; - render_sharp_line(cairo, border_color, x_pos, y_pos, - block->border_right, render_height); + if (block->border_right > 0) { + render_sharp_line(cairo, border_color, x_pos, y_pos, + block->border_right, render_height); + } x_pos += block->border_right; } @@ -375,10 +380,10 @@ static void predict_status_block_pos(cairo_t *cairo, } *x -= width; - if ((block->border || block->urgent) && block->border_left > 0) { + if ((block->border_set || block->urgent) && block->border_left > 0) { *x -= (block->border_left + margin); } - if ((block->border || block->urgent) && block->border_right > 0) { + if ((block->border_set || block->urgent) && block->border_right > 0) { *x -= (block->border_right + margin); } -- cgit v1.2.3