From 1de12e7b20e7ce38e2777218f1d922b3255599e1 Mon Sep 17 00:00:00 2001 From: Marco Hunsicker Date: Wed, 5 Mar 2014 20:53:07 +0100 Subject: 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 --- include/i3status.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include') 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, ...); -- cgit v1.2.3