diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-27 08:36:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-27 08:36:29 -0400 |
commit | ef169fcaeb17ec40cf83e54bba2ddbdcff10936f (patch) | |
tree | db2771489afbfbffcc77a038867bcc45117ba38a | |
parent | Merge pull request #1633 from mckinney-subgraph/0.15 (diff) | |
parent | swaybar: correctly render min_width for strings (diff) | |
download | sway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.tar.gz sway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.tar.zst sway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.zip |
Merge pull request #1636 from jrouleau/master
swaybar: correctly render min_width for strings
-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 { | |||
17 | }; | 17 | }; |
18 | 18 | ||
19 | struct status_block { | 19 | struct status_block { |
20 | char *full_text, *short_text, *align; | 20 | char *full_text, *short_text, *align, *min_width_str; |
21 | bool urgent; | 21 | bool urgent; |
22 | uint32_t color; | 22 | uint32_t color; |
23 | int min_width; | 23 | 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 | |||
61 | int textwidth = width; | 61 | int textwidth = width; |
62 | double block_width = width; | 62 | double block_width = width; |
63 | 63 | ||
64 | if (block->min_width_str) { | ||
65 | int w, h; | ||
66 | get_text_size(window->cairo, window->font, &w, &h, | ||
67 | window->scale, block->markup, "%s", block->min_width_str); | ||
68 | block->min_width = w; | ||
69 | } | ||
70 | |||
64 | if (width < block->min_width) { | 71 | if (width < block->min_width) { |
65 | width = block->min_width; | 72 | width = block->min_width; |
66 | } | 73 | } |
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) { | |||
121 | new->min_width = json_object_get_int(min_width); | 121 | new->min_width = json_object_get_int(min_width); |
122 | } else if (type == json_type_string) { | 122 | } else if (type == json_type_string) { |
123 | /* the width will be calculated when rendering */ | 123 | /* the width will be calculated when rendering */ |
124 | new->min_width = 0; | 124 | new->min_width_str = strdup(json_object_get_string(min_width)); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||