diff options
author | Nathan Schulte <nmschulte@gmail.com> | 2021-09-15 05:07:07 -0500 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-09-20 09:53:32 +0200 |
commit | 033061aee602a54f65340e2a300054d2790c22ea (patch) | |
tree | 79aa689ba0523caeecd25e8d20320d60de8632b0 /swaybar | |
parent | Drop hardcoded font metric values (diff) | |
download | sway-033061aee602a54f65340e2a300054d2790c22ea.tar.gz sway-033061aee602a54f65340e2a300054d2790c22ea.tar.zst sway-033061aee602a54f65340e2a300054d2790c22ea.zip |
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?)
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/i3bar.c | 31 | ||||
-rw-r--r-- | swaybar/render.c | 43 |
2 files changed, 40 insertions, 34 deletions
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) { | |||
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | static bool i3bar_parse_json_color(json_object *json, uint32_t *color) { | ||
32 | if (!json) { | ||
33 | return false; | ||
34 | } | ||
35 | |||
36 | const char *hexstring = json_object_get_string(json); | ||
37 | bool color_set = parse_color(hexstring, color); | ||
38 | if (!color_set) { | ||
39 | sway_log(SWAY_ERROR, "Ignoring invalid block hexadecimal color string: %s", hexstring); | ||
40 | } | ||
41 | return color_set; | ||
42 | } | ||
43 | |||
31 | static void i3bar_parse_json(struct status_line *status, | 44 | static void i3bar_parse_json(struct status_line *status, |
32 | struct json_object *json_array) { | 45 | struct json_object *json_array) { |
33 | struct i3bar_block *block, *tmp; | 46 | struct i3bar_block *block, *tmp; |
@@ -68,13 +81,7 @@ static void i3bar_parse_json(struct status_line *status, | |||
68 | strdup(json_object_get_string(full_text)) : NULL; | 81 | strdup(json_object_get_string(full_text)) : NULL; |
69 | block->short_text = short_text ? | 82 | block->short_text = short_text ? |
70 | strdup(json_object_get_string(short_text)) : NULL; | 83 | strdup(json_object_get_string(short_text)) : NULL; |
71 | if (color) { | 84 | block->color_set = i3bar_parse_json_color(color, &block->color); |
72 | const char *hexstring = json_object_get_string(color); | ||
73 | block->color_set = parse_color(hexstring, &block->color); | ||
74 | if (!block->color_set) { | ||
75 | sway_log(SWAY_ERROR, "Invalid block color: %s", hexstring); | ||
76 | } | ||
77 | } | ||
78 | if (min_width) { | 85 | if (min_width) { |
79 | json_type type = json_object_get_type(min_width); | 86 | json_type type = json_object_get_type(min_width); |
80 | if (type == json_type_int) { | 87 | if (type == json_type_int) { |
@@ -100,14 +107,8 @@ static void i3bar_parse_json(struct status_line *status, | |||
100 | block->separator_block_width = separator_block_width ? | 107 | block->separator_block_width = separator_block_width ? |
101 | json_object_get_int(separator_block_width) : 9; | 108 | json_object_get_int(separator_block_width) : 9; |
102 | // Airblader features | 109 | // Airblader features |
103 | const char *hex = background ? json_object_get_string(background) : NULL; | 110 | i3bar_parse_json_color(background, &block->background); |
104 | if (hex && !parse_color(hex, &block->background)) { | 111 | block->border_set = i3bar_parse_json_color(border, &block->border); |
105 | sway_log(SWAY_ERROR, "Ignoring invalid block background: %s", hex); | ||
106 | } | ||
107 | hex = border ? json_object_get_string(border) : NULL; | ||
108 | if (hex && !parse_color(hex, &block->border)) { | ||
109 | sway_log(SWAY_ERROR, "Ignoring invalid block border: %s", hex); | ||
110 | } | ||
111 | block->border_top = border_top ? json_object_get_int(border_top) : 1; | 112 | block->border_top = border_top ? json_object_get_int(border_top) : 1; |
112 | block->border_bottom = border_bottom ? | 113 | block->border_bottom = border_bottom ? |
113 | json_object_get_int(border_bottom) : 1; | 114 | 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 @@ | |||
14 | #include "swaybar/ipc.h" | 14 | #include "swaybar/ipc.h" |
15 | #include "swaybar/render.h" | 15 | #include "swaybar/render.h" |
16 | #include "swaybar/status_line.h" | 16 | #include "swaybar/status_line.h" |
17 | #include "log.h" | ||
17 | #if HAVE_TRAY | 18 | #if HAVE_TRAY |
18 | #include "swaybar/tray/tray.h" | 19 | #include "swaybar/tray/tray.h" |
19 | #endif | 20 | #endif |
@@ -215,11 +216,11 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
215 | } | 216 | } |
216 | 217 | ||
217 | *x -= width; | 218 | *x -= width; |
218 | if ((block->border || block->urgent) && block->border_left > 0) { | 219 | if ((block->border_set || block->urgent) && block->border_left > 0) { |
219 | *x -= (block->border_left + margin); | 220 | *x -= (block->border_left + margin); |
220 | block_width += block->border_left + margin; | 221 | block_width += block->border_left + margin; |
221 | } | 222 | } |
222 | if ((block->border || block->urgent) && block->border_right > 0) { | 223 | if ((block->border_set || block->urgent) && block->border_right > 0) { |
223 | *x -= (block->border_right + margin); | 224 | *x -= (block->border_right + margin); |
224 | block_width += block->border_right + margin; | 225 | block_width += block->border_right + margin; |
225 | } | 226 | } |
@@ -273,18 +274,20 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
273 | 274 | ||
274 | uint32_t border_color = block->urgent | 275 | uint32_t border_color = block->urgent |
275 | ? config->colors.urgent_workspace.border : block->border; | 276 | ? config->colors.urgent_workspace.border : block->border; |
276 | if (border_color && block->border_top > 0) { | 277 | if (block->border_set || block->urgent) { |
277 | render_sharp_line(cairo, border_color, x_pos, y_pos, | 278 | if (block->border_top > 0) { |
278 | block_width, block->border_top); | 279 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
279 | } | 280 | block_width, block->border_top); |
280 | if (border_color && block->border_bottom > 0) { | 281 | } |
281 | render_sharp_line(cairo, border_color, x_pos, | 282 | if (block->border_bottom > 0) { |
282 | y_pos + render_height - block->border_bottom, | 283 | render_sharp_line(cairo, border_color, x_pos, |
283 | block_width, block->border_bottom); | 284 | y_pos + render_height - block->border_bottom, |
284 | } | 285 | block_width, block->border_bottom); |
285 | if (border_color && block->border_left > 0) { | 286 | } |
286 | render_sharp_line(cairo, border_color, x_pos, y_pos, | 287 | if (block->border_left > 0) { |
287 | block->border_left, render_height); | 288 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
289 | block->border_left, render_height); | ||
290 | } | ||
288 | x_pos += block->border_left + margin; | 291 | x_pos += block->border_left + margin; |
289 | } | 292 | } |
290 | 293 | ||
@@ -307,10 +310,12 @@ static uint32_t render_status_block(struct render_context *ctx, | |||
307 | render_text(cairo, config->font, 1, block->markup, "%s", text); | 310 | render_text(cairo, config->font, 1, block->markup, "%s", text); |
308 | x_pos += width; | 311 | x_pos += width; |
309 | 312 | ||
310 | if (border_color && block->border_right > 0) { | 313 | if (block->border_set || block->urgent) { |
311 | x_pos += margin; | 314 | x_pos += margin; |
312 | render_sharp_line(cairo, border_color, x_pos, y_pos, | 315 | if (block->border_right > 0) { |
313 | block->border_right, render_height); | 316 | render_sharp_line(cairo, border_color, x_pos, y_pos, |
317 | block->border_right, render_height); | ||
318 | } | ||
314 | x_pos += block->border_right; | 319 | x_pos += block->border_right; |
315 | } | 320 | } |
316 | 321 | ||
@@ -375,10 +380,10 @@ static void predict_status_block_pos(cairo_t *cairo, | |||
375 | } | 380 | } |
376 | 381 | ||
377 | *x -= width; | 382 | *x -= width; |
378 | if ((block->border || block->urgent) && block->border_left > 0) { | 383 | if ((block->border_set || block->urgent) && block->border_left > 0) { |
379 | *x -= (block->border_left + margin); | 384 | *x -= (block->border_left + margin); |
380 | } | 385 | } |
381 | if ((block->border || block->urgent) && block->border_right > 0) { | 386 | if ((block->border_set || block->urgent) && block->border_right > 0) { |
382 | *x -= (block->border_right + margin); | 387 | *x -= (block->border_right + margin); |
383 | } | 388 | } |
384 | 389 | ||