diff options
author | Marco Hunsicker <i3@hunsicker.de> | 2014-03-05 20:53:07 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2014-03-07 08:46:44 +0100 |
commit | 1de12e7b20e7ce38e2777218f1d922b3255599e1 (patch) | |
tree | 237106d7c44437c2e477a8fb842828f4ca7bbb87 /include/i3status.h | |
parent | 0c2b518b8a30c08a69c07ab6ffeea98eb2d58424 (diff) |
Support align and min_width module options
This patch enables users to define "align" and "min_width" options
right in the i3status module config sections.
Specifically this patch:
* Adds macros for the two new options that are used in the option
definitions. As the min_width option can take either a string or a
number, a custom type has been added along with a corresponding callback
function that parses the provided value (and provides input validation).
The align option also uses a callback for input validation
* Expands all module config option definitions to include the new
options
* Extends the SEC_CLOSE_MAP() macro to generate the JSON for the new
options as necessary
* Updates the manpage to explain the new options
Diffstat (limited to 'include/i3status.h')
-rw-r--r-- | include/i3status.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/i3status.h b/include/i3status.h index 95da091..8c64586 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -88,6 +88,22 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_TERM, O_NONE } output_format; #define SEC_CLOSE_MAP \ do { \ if (output_format == O_I3BAR) { \ + char *_align = cfg_getstr(sec, "align"); \ + if (_align) { \ + yajl_gen_string(json_gen, (const unsigned char *)"align", strlen("align")); \ + yajl_gen_string(json_gen, (const unsigned char *)_align, strlen(_align)); \ + } \ + struct min_width *_width = cfg_getptr(sec, "min_width"); \ + if (_width) { \ + /* if the value can be parsed as a number, we use the numerical value */ \ + if (_width->num > 0) { \ + yajl_gen_string(json_gen, (const unsigned char *)"min_width", strlen("min_width")); \ + yajl_gen_integer(json_gen, _width->num); \ + } else { \ + yajl_gen_string(json_gen, (const unsigned char *)"min_width", strlen("min_width")); \ + yajl_gen_string(json_gen, (const unsigned char *)_width->str, strlen(_width->str)); \ + } \ + } \ const char *_sep = cfg_getstr(cfg_general, "separator"); \ if (strlen(_sep) == 0) {\ yajl_gen_string(json_gen, (const unsigned char *)"separator", strlen("separator")); \ @@ -132,6 +148,14 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_TERM, O_NONE } output_format; typedef enum { CS_DISCHARGING, CS_CHARGING, CS_FULL } charging_status_t; +/* + * The "min_width" module option may either be defined as a string or a number. + */ +struct min_width { + long num; + const char *str; +}; + /* src/general.c */ char *skip_character(char *input, char character, int amount); void die(const char *fmt, ...); |