aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-27 08:36:29 -0400
committerGitHub <noreply@github.com>2018-03-27 08:36:29 -0400
commitef169fcaeb17ec40cf83e54bba2ddbdcff10936f (patch)
treedb2771489afbfbffcc77a038867bcc45117ba38a
parent45f14fcb24b6dae8bb78efb1ec7d7a51cb9a4d2c (diff)
parent54444e7587589309e329c539ed2b2d505b443ba7 (diff)
downloadsway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.zip
sway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.tar.gz
sway-ef169fcaeb17ec40cf83e54bba2ddbdcff10936f.tar.bz2
Merge pull request #1636 from jrouleau/master
swaybar: correctly render min_width for strings
-rw-r--r--include/swaybar/status_line.h2
-rw-r--r--swaybar/render.c7
-rw-r--r--swaybar/status_line.c2
3 files changed, 9 insertions, 2 deletions
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index 3ec0fcd..93cb0ee 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 e874fc8..b349435 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 bbb798f..0f88cfc 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));
}
}