i3 - improved tiling WM


Separator color in config; disable separator via ipc

Patch status: rejected

Patch by Artem Shinkarov

Long description:

This patch adds the following features:
1) Configure a color of the separator via config.  It is done like
   bar {
      colors {
         separator #000000
      }
   }
2) A block can have an entry "separator", which being set to "off"
   disables drawing of the separating line.

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

b/docs/i3bar-protocol

33
@@ -154,7 +154,11 @@ urgent::
34
 	A boolean which specifies whether the current value is urgent. Examples
35
 	are battery charge values below 1 percent or no more available disk
36
 	space (for non-root users). The presentation of urgency is up to i3bar.
37
-
38
+separator::
39
+	The boolean value false disables drawing of a separating line after the
40
+	block.  If the field is not present then the separator will be still
41
+	drawn.  Keep in mind that absece of a separator reduces the gap between
42
+	blocks from 9 pixels to 3.
43
 If you want to put in your own entries into a block, prefix the key with an
44
 underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing
45
 them with an underscore makes it clear in every script that they are not part

b/docs/ipc

50
@@ -507,6 +507,8 @@ background::
51
 	Background color of the bar.
52
 statusline::
53
 	Text color to be used for the statusline.
54
+separator::
55
+	Text color to be used for the separator.
56
 focused_workspace_text/focused_workspace_bg::
57
 	Text color/background color for a workspace button when the workspace
58
 	has focus.

b/docs/userguide

63
@@ -1154,6 +1154,8 @@ background::
64
 	Background color of the bar.
65
 statusline::
66
 	Text color to be used for the statusline.
67
+separator::	
68
+	Text color to be used for the separator.
69
 focused_workspace::
70
 	Border, background and text color for a workspace button when the workspace
71
 	has focus.
72
@@ -1175,6 +1177,7 @@ urgent_workspace::
73
 colors {
74
     background <color>
75
     statusline <color>
76
+    separator <color>
77
 
78
     colorclass <border> <background> <text>
79
 }
80
@@ -1186,6 +1189,7 @@ bar {
81
     colors {
82
         background #000000
83
         statusline #ffffff
84
+        separator #666666
85
 
86
         focused_workspace  #4c7899 #285577 #ffffff
87
         active_workspace   #333333 #5f676a #ffffff

b/i3bar/include/common.h

92
@@ -43,6 +43,7 @@ struct status_block {
93
     blockalign_t align;
94
 
95
     bool urgent;
96
+    bool no_separator;
97
 
98
     /* The amount of pixels necessary to render this block. These variables are
99
      * only temporarily used in refresh_statusline(). */

b/i3bar/include/xcb.h

104
@@ -28,6 +28,7 @@
105
 struct xcb_color_strings_t {
106
     char *bar_fg;
107
     char *bar_bg;
108
+    char *sep_fg;
109
     char *active_ws_fg;
110
     char *active_ws_bg;
111
     char *active_ws_border;

b/i3bar/src/child.c

116
@@ -117,6 +117,9 @@ static int stdin_boolean(void *context, int val) {
117
     if (strcasecmp(ctx->last_map_key, "urgent") == 0) {
118
         ctx->block.urgent = val;
119
     }
120
+    if (strcasecmp(ctx->last_map_key, "separator") == 0) {
121
+        ctx->block.no_separator = !val;
122
+    }
123
     return 1;
124
 }
125
 

b/i3bar/src/config.c

130
@@ -161,6 +161,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
131
 
132
     COLOR(statusline, bar_fg);
133
     COLOR(background, bar_bg);
134
+    COLOR(separator, sep_fg);
135
     COLOR(focused_workspace_border, focus_ws_border);
136
     COLOR(focused_workspace_bg, focus_ws_bg);
137
     COLOR(focused_workspace_text, focus_ws_fg);
138
@@ -260,6 +261,7 @@ void free_colors(struct xcb_color_strings_t *colors) {
139
     } while (0)
140
     FREE_COLOR(bar_fg);
141
     FREE_COLOR(bar_bg);
142
+    FREE_COLOR(sep_fg);
143
     FREE_COLOR(active_ws_fg);
144
     FREE_COLOR(active_ws_bg);
145
     FREE_COLOR(active_ws_border);

b/i3bar/src/xcb.c

150
@@ -84,6 +84,7 @@ static mode binding;
151
 struct xcb_colors_t {
152
     uint32_t bar_fg;
153
     uint32_t bar_bg;
154
+    uint32_t sep_fg;
155
     uint32_t active_ws_fg;
156
     uint32_t active_ws_bg;
157
     uint32_t active_ws_border;
158
@@ -148,8 +149,11 @@ void refresh_statusline(void) {
159
         }
160
 
161
         /* If this is not the last block, add some pixels for a separator. */
162
-        if (TAILQ_NEXT(block, blocks) != NULL)
163
-            block->width += 9;
164
+        if (TAILQ_NEXT(block, blocks) != NULL) {
165
+            /* If a block comes with no_separator, use 3 pixels to avoid
166
+               text of the block sticking to the content of the next block.  */
167
+            block->width += block->no_separator ? 3 : 9;
168
+        }
169
         statusline_width += block->width + block->x_offset + block->x_append;
170
     }
171
 
172
@@ -174,9 +178,9 @@ void refresh_statusline(void) {
173
         draw_text(block->full_text, statusline_pm, statusline_ctx, x + block->x_offset, 1, block->width);
174
         x += block->width + block->x_offset + block->x_append;
175
 
176
-        if (TAILQ_NEXT(block, blocks) != NULL) {
177
+        if (TAILQ_NEXT(block, blocks) != NULL && !block->no_separator) {
178
             /* This is not the last block, draw a separator. */
179
-            set_font_colors(statusline_ctx, get_colorpixel("#666666"), colors.bar_bg);
180
+            set_font_colors(statusline_ctx, colors.sep_fg, colors.bar_bg);
181
             xcb_poly_line(xcb_connection, XCB_COORD_MODE_ORIGIN, statusline_pm,
182
                           statusline_ctx, 2,
183
                           (xcb_point_t[]){ { x - 5, 2 }, { x - 5, font.height - 2 } });
184
@@ -259,6 +263,7 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {
185
     } while  (0)
186
     PARSE_COLOR(bar_fg, "#FFFFFF");
187
     PARSE_COLOR(bar_bg, "#000000");
188
+    PARSE_COLOR(sep_fg, "#666666");
189
     PARSE_COLOR(active_ws_fg, "#FFFFFF");
190
     PARSE_COLOR(active_ws_bg, "#333333");
191
     PARSE_COLOR(active_ws_border, "#333333");

b/include/config.h

196
@@ -267,6 +267,7 @@ struct Barconfig {
197
     struct bar_colors {
198
         char *background;
199
         char *statusline;
200
+        char *separator;
201
 
202
         char *focused_workspace_border;
203
         char *focused_workspace_bg;

b/parser-specs/config.spec

208
@@ -419,7 +419,7 @@ state BAR_COLORS:
209
   end ->
210
   '#' -> BAR_COLORS_IGNORE_LINE
211
   'set' -> BAR_COLORS_IGNORE_LINE
212
-  colorclass = 'background', 'statusline'
213
+  colorclass = 'background', 'statusline', 'separator'
214
       -> BAR_COLORS_SINGLE
215
   colorclass = 'focused_workspace', 'active_workspace', 'inactive_workspace', 'urgent_workspace'
216
       -> BAR_COLORS_BORDER

b/src/config_directives.c

221
@@ -526,7 +526,10 @@ CFGFUN(bar_tray_output, const char *output) {
222
 CFGFUN(bar_color_single, const char *colorclass, const char *color) {
223
     if (strcmp(colorclass, "background") == 0)
224
         current_bar.colors.background = sstrdup(color);
225
-    else current_bar.colors.statusline = sstrdup(color);
226
+    else if (strcmp(colorclass, "separator") == 0)
227
+        current_bar.colors.separator = sstrdup(color);
228
+    else
229
+        current_bar.colors.statusline = sstrdup(color);
230
 }
231
 
232
 CFGFUN(bar_status_command, const char *command) {

b/src/ipc.c

237
@@ -677,6 +677,7 @@ IPC_HANDLER(get_bar_config) {
238
         y(map_open);
239
         YSTR_IF_SET(background);
240
         YSTR_IF_SET(statusline);
241
+        YSTR_IF_SET(separator);
242
         YSTR_IF_SET(focused_workspace_border);
243
         YSTR_IF_SET(focused_workspace_bg);
244
         YSTR_IF_SET(focused_workspace_text);