i3 - improved tiling WM


i3status: Allow customization of module separator

Patch status: superseded

Patch by Marco Hunsicker

Long description:

This patch adds the ability to customize the separator that is placed
between modules.

Specifically this patch:

* adds the "separator" general directive
* moves the definition of the default separator for the different
  output formats (excluding color formatting) to src/i3status.c
* updates the SEC_CLOSE_MAP macro to disable the separator for the
  i3bar output format if the separator directive dictates so
* changes print_seperator() in src/output.c to disable the separator
  if the separator directive dictates so and to use the configured
  separator otherwise
* updates the manpage to explain the new directive

To apply this patch, use:
curl http://cr.i3wm.org/patch/436/raw.patch | git am

b/i3status.c

30
@@ -191,12 +191,25 @@ static char *get_config_path(void) {
31
         return NULL;
32
 }
33
 
34
+/*
35
+ * Returns the default separator to use if no custom separator has been specified.
36
+ */
37
+static char *get_default_separator() {
38
+        if (output_format == O_DZEN2)
39
+                return "^p(5;-2)^ro(2)^p()^p(5)";
40
+        if (output_format == O_I3BAR)
41
+                // anything besides the empty string indicates that the default separator should be used
42
+                return "default";
43
+        return " | ";
44
+}
45
+
46
 int main(int argc, char *argv[]) {
47
         unsigned int j;
48
 
49
         cfg_opt_t general_opts[] = {
50
                 CFG_STR("output_format", "auto", CFGF_NONE),
51
                 CFG_BOOL("colors", 1, CFGF_NONE),
52
+                CFG_STR("separator", "default", CFGF_NONE),
53
                 CFG_STR("color_separator", "#333333", CFGF_NONE),
54
                 CFG_INT("interval", 1, CFGF_NONE),
55
                 CFG_COLOR_OPTS("#00FF00", "#FFFF00", "#FF0000"),
56
@@ -403,6 +416,12 @@ int main(int argc, char *argv[]) {
57
                 output_format = O_NONE;
58
         else die("Unknown output format: \"%s\"\n", output_str);
59
 
60
+        separator = cfg_getstr(cfg_general, "separator");
61
+
62
+        // if no custom separator has been provided, use the default one
63
+        if (strcasecmp(separator, "default") == 0)
64
+                separator = get_default_separator();
65
+
66
         if (!valid_color(cfg_getstr(cfg_general, "color_good"))
67
                         || !valid_color(cfg_getstr(cfg_general, "color_degraded"))
68
                         || !valid_color(cfg_getstr(cfg_general, "color_bad"))

b/include/i3status.h

73
@@ -88,6 +88,10 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_TERM, O_NONE } output_format;
74
 #define SEC_CLOSE_MAP \
75
 	do { \
76
 		if (output_format == O_I3BAR) { \
77
+			if (strlen(separator) == 0) {\
78
+				yajl_gen_string(json_gen, (const unsigned char *)"separator", strlen("separator")); \
79
+				yajl_gen_string(json_gen, (const unsigned char *)"false", strlen("false")); \
80
+			} \
81
 			yajl_gen_map_close(json_gen); \
82
 		} \
83
 	} while (0)
84
@@ -160,6 +164,10 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format, const float
85
 void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *fmt_muted, const char *device, const char *mixer, int mixer_idx);
86
 bool process_runs(const char *path);
87
 
88
+/* The separator that should be displayed between modules. The empty string 
89
+ * indicates that no default separator should be displayed at all. */
90
+char *separator;
91
+
92
 /* socket file descriptor for general purposes */
93
 extern int general_socket;
94
 

b/man/i3status.man

99
@@ -160,14 +160,41 @@ easier because the terminal-output of i3status becomes much more readable, but
100
 should only used for such quick glances, because it will only support very
101
 basic output-features (for example you only get 3 bits of color depth).
102
 none::
103
-Does not use any color codes. Separates values by the pipe symbol. This should
104
-be used with i3bar and can be used for custom scripts.
105
+Does not use any color codes. Separates values by the pipe symbol by default.
106
+This should be used with i3bar and can be used for custom scripts.
107
 
108
 It's also possible to use the color_good, color_degraded, color_bad directives
109
 to define specific colors per module. If one of these directives is defined
110
 in a module section its value will override the value defined in the general
111
 section just for this module.
112
 
113
+If you don't fancy the vertical separators between modules i3status/i3bar
114
+uses by default, you can employ the +separator+ directive to configure how
115
+modules are separated. You can either disable the default separator altogether
116
+setting it to the empty string. You might then define separation as part of a
117
+module's format string. This is your only option when using the i3bar output
118
+format as the separator is drawn by i3bar directly otherwise. For the other
119
+output formats, the provided non-empty string will be automatically enclosed
120
+with the necessary coloring bits if color support is enabled.
121
+
122
+*Example configuration*:
123
+-------------------------------------------------------------
124
+general {
125
+    output_format = "xmobar"
126
+    separator = "  "
127
+}
128
+
129
+order += "load"
130
+order += "disk /"
131
+
132
+load {
133
+    format = "[ load: %1min, %5min, %15min ]"
134
+}
135
+disk "/" {
136
+    format = "%avail"
137
+}
138
+-------------------------------------------------------------
139
+
140
 === IPv6
141
 
142
 This module gets the IPv6 address used for outgoing connections (that is, the

b/src/output.c

147
@@ -53,14 +53,17 @@ char *endcolor(void) {
148
 }
149
 
150
 void print_seperator(void) {
151
+        if (output_format == O_I3BAR || strlen(separator) == 0)
152
+                return;
153
+
154
         if (output_format == O_DZEN2)
155
-                printf("^fg(%s)^p(5;-2)^ro(2)^p()^fg()^p(5)", cfg_getstr(cfg_general, "color_separator"));
156
+                printf("^fg(%s)%s^fg()", cfg_getstr(cfg_general, "color_separator"), separator);
157
         else if (output_format == O_XMOBAR)
158
-                printf("<fc=%s> | </fc>", cfg_getstr(cfg_general, "color_separator"));
159
+                printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
160
         else if (output_format == O_TERM)
161
-                printf(" %s|%s ", color("color_separator"), endcolor());
162
+                printf("%s%s%s", color("color_separator"), separator, endcolor());
163
         else if (output_format == O_NONE)
164
-                printf(" | ");
165
+                printf("%s", separator);
166
 }
167
 
168
 /*