Allow min_width of a block in i3bar to be a string
Patch status: merged
Patch by AndrĂ¡s Mohari
Long description:
With this change, min_width can either be an integer (as usual), or a string. In the latter case, the width of the text given by min_width determines the minimum width of the block. This way one does not have to figure out a minimum width by trial and error, only to do it again every time the font is changed.
To apply this patch, use:
curl http://cr.i3wm.org/patch/58/raw.patch | git am
b/docs/i3bar-protocol
19 |
@@ -140,6 +140,10 @@ min_width:: |
20 |
will be padded to the left and/or the right side, according to the +align+ |
21 |
key. This is useful when you want to prevent the whole status line to shift |
22 |
when value take more or less space between each iteration. |
23 |
+ The value can also be a string. In this case, the width of the text given |
24 |
+ by +min_width+ determines the minimum width of the block. This is useful |
25 |
+ when you want to set a sensible minimum width regardless of which font you |
26 |
+ are using, and at what particular size. |
27 |
align:: |
28 |
Align text on the +center+ (default), +right+ or +left+ of the block, when |
29 |
the minimum width of the latter, specified by the +min_width+ key, is not |
30 |
@@ -178,6 +182,17 @@ of the i3bar protocol. |
31 |
} |
32 |
------------------------------------------ |
33 |
|
34 |
+In the following example, the longest (widest) possible value of the block is |
35 |
+used to set the minimum width: |
36 |
+ |
37 |
+------------------------------------------ |
38 |
+{ |
39 |
+ "full_text": "CPU 4%", |
40 |
+ "min_width": "CPU 100%", |
41 |
+ "align": "left" |
42 |
+} |
43 |
+------------------------------------------ |
44 |
+ |
45 |
An example of a block which uses all possible entries follows: |
46 |
|
47 |
*Example*: |
b/i3bar/src/child.c
52 |
@@ -147,6 +147,10 @@ static int stdin_string(void *context, const unsigned char *val, unsigned int le |
53 |
} else { |
54 |
ctx->block.align = ALIGN_CENTER; |
55 |
} |
56 |
+ } else if (strcasecmp(ctx->last_map_key, "min_width") == 0) { |
57 |
+ i3String *text = i3string_from_utf8_with_length((const char *)val, len); |
58 |
+ ctx->block.min_width = (uint32_t)predict_text_width(text); |
59 |
+ i3string_free(text); |
60 |
} |
61 |
return 1; |
62 |
} |