diff options
-rw-r--r-- | include/swaybar/i3bar.h | 2 | ||||
-rw-r--r-- | swaybar/i3bar.c | 3 | ||||
-rw-r--r-- | swaybar/render.c | 6 |
3 files changed, 9 insertions, 2 deletions
diff --git a/include/swaybar/i3bar.h b/include/swaybar/i3bar.h index aa4415ff..5b6001ce 100644 --- a/include/swaybar/i3bar.h +++ b/include/swaybar/i3bar.h | |||
@@ -7,7 +7,7 @@ | |||
7 | struct i3bar_block { | 7 | struct i3bar_block { |
8 | struct wl_list link; // status_link::blocks | 8 | struct wl_list link; // status_link::blocks |
9 | int ref_count; | 9 | int ref_count; |
10 | char *full_text, *short_text, *align; | 10 | char *full_text, *short_text, *align, *min_width_str; |
11 | bool urgent; | 11 | bool urgent; |
12 | uint32_t *color; | 12 | uint32_t *color; |
13 | int min_width; | 13 | int min_width; |
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index da93a132..43e2fe2d 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c | |||
@@ -21,6 +21,7 @@ void i3bar_block_unref(struct i3bar_block *block) { | |||
21 | free(block->full_text); | 21 | free(block->full_text); |
22 | free(block->short_text); | 22 | free(block->short_text); |
23 | free(block->align); | 23 | free(block->align); |
24 | free(block->min_width_str); | ||
24 | free(block->name); | 25 | free(block->name); |
25 | free(block->instance); | 26 | free(block->instance); |
26 | free(block->color); | 27 | free(block->color); |
@@ -78,7 +79,7 @@ static void i3bar_parse_json(struct status_line *status, | |||
78 | block->min_width = json_object_get_int(min_width); | 79 | block->min_width = json_object_get_int(min_width); |
79 | } else if (type == json_type_string) { | 80 | } else if (type == json_type_string) { |
80 | /* the width will be calculated when rendering */ | 81 | /* the width will be calculated when rendering */ |
81 | block->min_width = 0; | 82 | block->min_width_str = strdup(json_object_get_string(min_width)); |
82 | } | 83 | } |
83 | } | 84 | } |
84 | block->align = strdup(align ? json_object_get_string(align) : "left"); | 85 | block->align = strdup(align ? json_object_get_string(align) : "left"); |
diff --git a/swaybar/render.c b/swaybar/render.c index e27f7d4c..116cc595 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -159,6 +159,12 @@ static uint32_t render_status_block(cairo_t *cairo, | |||
159 | double ws_vertical_padding = config->status_padding * output->scale; | 159 | double ws_vertical_padding = config->status_padding * output->scale; |
160 | 160 | ||
161 | int width = text_width; | 161 | int width = text_width; |
162 | if (block->min_width_str) { | ||
163 | int w; | ||
164 | get_text_size(cairo, config->font, &w, NULL, NULL, | ||
165 | output->scale, block->markup, "%s", block->min_width_str); | ||
166 | block->min_width = w; | ||
167 | } | ||
162 | if (width < block->min_width) { | 168 | if (width < block->min_width) { |
163 | width = block->min_width; | 169 | width = block->min_width; |
164 | } | 170 | } |