]> git.sur5r.net Git - i3/i3status/commitdiff
add separator and separator_block_width as universal module options 105/head
authorjohannes karoff <johannes@karoff.net>
Sun, 31 Jan 2016 18:16:42 +0000 (19:16 +0100)
committerjohannes karoff <johannes@karoff.net>
Sun, 31 Jan 2016 18:39:29 +0000 (19:39 +0100)
fixes #104

i3status.c
include/i3status.h
man/i3status.man

index ec204e59140572b3e957d98b1890bba625b7dacb..c8c5df04eff4c9acbd9e9c5dcef8f68bf76ce0b5 100644 (file)
 #define CFG_CUSTOM_MIN_WIDTH_OPT \
     CFG_PTR_CB("min_width", NULL, CFGF_NONE, parse_min_width, free)
 
+#define CFG_CUSTOM_SEPARATOR_OPT \
+    CFG_BOOL("separator", 0, CFGF_NODEFAULT)
+
+#define CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT \
+    CFG_INT("separator_block_width", 0, CFGF_NODEFAULT)
+
 /* socket file descriptor for general purposes */
 int general_socket;
 
@@ -304,6 +310,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t path_exists_opts[] = {
@@ -313,6 +321,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t wireless_opts[] = {
@@ -321,6 +331,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t ethernet_opts[] = {
@@ -329,6 +341,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t ipv6_opts[] = {
@@ -337,6 +351,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t battery_opts[] = {
@@ -354,12 +370,16 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t time_opts[] = {
         CFG_STR("format", "%Y-%m-%d %H:%M:%S", CFGF_NONE),
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t tztime_opts[] = {
@@ -368,12 +388,16 @@ int main(int argc, char *argv[]) {
         CFG_STR("format_time", NULL, CFGF_NONE),
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t ddate_opts[] = {
         CFG_STR("format", "%{%a, %b %d%}, %Y%N - %H", CFGF_NONE),
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t load_opts[] = {
@@ -382,12 +406,16 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t usage_opts[] = {
         CFG_STR("format", "%usage", CFGF_NONE),
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t temp_opts[] = {
@@ -397,6 +425,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t disk_opts[] = {
@@ -408,6 +438,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t volume_opts[] = {
@@ -419,6 +451,8 @@ int main(int argc, char *argv[]) {
         CFG_CUSTOM_ALIGN_OPT,
         CFG_CUSTOM_COLOR_OPTS,
         CFG_CUSTOM_MIN_WIDTH_OPT,
+        CFG_CUSTOM_SEPARATOR_OPT,
+        CFG_CUSTOM_SEP_BLOCK_WIDTH_OPT,
         CFG_END()};
 
     cfg_opt_t opts[] = {
index a311d2465a2ff0c1c716f70816ebef8396d1708d..d6679aee714ef2f9469c5cfc1c558503a6a01d96 100644 (file)
@@ -100,32 +100,40 @@ char *pct_mark;
         }                                                                              \
     } while (0)
 
-#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"));     \
-                yajl_gen_bool(json_gen, false);                                                          \
-            }                                                                                            \
-            yajl_gen_map_close(json_gen);                                                                \
-        }                                                                                                \
+#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));                      \
+                }                                                                                                            \
+            }                                                                                                                \
+            if (cfg_size(sec, "separator") > 0) {                                                                            \
+                yajl_gen_string(json_gen, (const unsigned char *) "separator", strlen("separator"));                         \
+                yajl_gen_bool(json_gen, cfg_getbool(sec, "separator"));                                                      \
+            }                                                                                                                \
+            if (cfg_size(sec, "separator_block_width") > 0) {                                                                \
+                yajl_gen_string(json_gen, (const unsigned char *) "separator_block_width", strlen("separator_block_width")); \
+                yajl_gen_integer(json_gen, cfg_getint(sec, "separator_block_width"));                                        \
+            }                                                                                                                \
+            const char *_sep = cfg_getstr(cfg_general, "separator");                                                         \
+            if (strlen(_sep) == 0) {                                                                                         \
+                yajl_gen_string(json_gen, (const unsigned char *) "separator", strlen("separator"));                         \
+                yajl_gen_bool(json_gen, false);                                                                              \
+            }                                                                                                                \
+            yajl_gen_map_close(json_gen);                                                                                    \
+        }                                                                                                                    \
     } while (0)
 
 #define START_COLOR(colorstr)                                                                \
index b5f8f6822e21a85ee078515e5774ee3d0a76c81b..f71ce9821bb22f62f7126e6ad8b344edd540ab4e 100644 (file)
@@ -513,6 +513,15 @@ min_width::
        set a sensible minimum width regardless of which font you are using, and at
        what particular size. Please note that a number enclosed with quotes will
        still be treated as a number.
+separator::
+       A boolean value which specifies whether a separator line should be drawn
+       after this block. The default is true, meaning the separator line will be
+       drawn. Note that if you disable the separator line, there will still be a
+       gap after the block, unless you also use separator_block_width.
+separator_block_width::
+       The amount of pixels to leave blank after the block. In the middle of this
+       gap, a separator symbol will be drawn unless separator is disabled. This is
+       why the specified width should leave enough space for the separator symbol.
 
 *Example configuration*:
 -------------------------------------------------------------
@@ -520,6 +529,8 @@ disk "/" {
     format = "%avail"
     align = "left"
     min_width = 100
+    separator = false
+    separator_block_width = 1
 }
 -------------------------------------------------------------