diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2018-03-27 01:14:03 +0000 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2018-03-27 01:14:03 +0000 |
| commit | 47e78cee23bde3fbea569a616a470e06c0dfed99 (patch) | |
| tree | db2771489afbfbffcc77a038867bcc45117ba38a | |
| parent | a0edc48046a34107f7c60b2edecba66049b4544d (diff) | |
swaybar: correctly render min_width for strings
fixes #1635
| -rw-r--r-- | include/swaybar/status_line.h | 2 | ||||
| -rw-r--r-- | swaybar/render.c | 7 | ||||
| -rw-r--r-- | swaybar/status_line.c | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index 3ec0fcd0..93cb0ee2 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h @@ -17,7 +17,7 @@ struct status_line { }; struct status_block { - char *full_text, *short_text, *align; + char *full_text, *short_text, *align, *min_width_str; bool urgent; uint32_t color; int min_width; diff --git a/swaybar/render.c b/swaybar/render.c index e874fc86..b3494351 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -61,6 +61,13 @@ static void render_block(struct window *window, struct config *config, struct st int textwidth = width; double block_width = width; + if (block->min_width_str) { + int w, h; + get_text_size(window->cairo, window->font, &w, &h, + window->scale, block->markup, "%s", block->min_width_str); + block->min_width = w; + } + if (width < block->min_width) { width = block->min_width; } diff --git a/swaybar/status_line.c b/swaybar/status_line.c index bbb798f1..0f88cfc8 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -121,7 +121,7 @@ static void parse_json(struct bar *bar, const char *text) { new->min_width = json_object_get_int(min_width); } else if (type == json_type_string) { /* the width will be calculated when rendering */ - new->min_width = 0; + new->min_width_str = strdup(json_object_get_string(min_width)); } } |
