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/24/raw.patch | git am
b/docs/i3bar-protocol
33 |
@@ -154,7 +154,10 @@ 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 value "off" disables drawing of a separating line after the block. |
40 |
+ Keep in mind that it reduces the gap between the blocks from 9 pixels |
41 |
+ to 3. |
42 |
If you want to put in your own entries into a block, prefix the key with an |
43 |
underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing |
44 |
them with an underscore makes it clear in every script that they are not part |
b/docs/ipc
49 |
@@ -507,6 +507,8 @@ background:: |
50 |
Background color of the bar. |
51 |
statusline:: |
52 |
Text color to be used for the statusline. |
53 |
+separator:: |
54 |
+ Text color to be used for the separator. |
55 |
focused_workspace_text/focused_workspace_bg:: |
56 |
Text color/background color for a workspace button when the workspace |
57 |
has focus. |
b/docs/userguide
62 |
@@ -1154,6 +1154,8 @@ background:: |
63 |
Background color of the bar. |
64 |
statusline:: |
65 |
Text color to be used for the statusline. |
66 |
+separator:: |
67 |
+ Text color to be used for the separator. |
68 |
focused_workspace:: |
69 |
Border, background and text color for a workspace button when the workspace |
70 |
has focus. |
71 |
@@ -1175,6 +1177,7 @@ urgent_workspace:: |
72 |
colors { |
73 |
background <color> |
74 |
statusline <color> |
75 |
+ separator <color> |
76 |
|
77 |
colorclass <border> <background> <text> |
78 |
} |
79 |
@@ -1186,6 +1189,7 @@ bar { |
80 |
colors { |
81 |
background #000000 |
82 |
statusline #ffffff |
83 |
+ separator #666666 |
84 |
|
85 |
focused_workspace #4c7899 #285577 #ffffff |
86 |
active_workspace #333333 #5f676a #ffffff |
b/i3bar/include/common.h
91 |
@@ -43,6 +43,7 @@ struct status_block { |
92 |
blockalign_t align; |
93 |
|
94 |
bool urgent; |
95 |
+ bool no_separator; |
96 |
|
97 |
/* The amount of pixels necessary to render this block. These variables are |
98 |
* only temporarily used in refresh_statusline(). */ |
b/i3bar/include/xcb.h
103 |
@@ -28,6 +28,7 @@ |
104 |
struct xcb_color_strings_t { |
105 |
char *bar_fg; |
106 |
char *bar_bg; |
107 |
+ char *sep_fg; |
108 |
char *active_ws_fg; |
109 |
char *active_ws_bg; |
110 |
char *active_ws_border; |
b/i3bar/src/child.c
115 |
@@ -132,6 +132,11 @@ static int stdin_string(void *context, const unsigned char *val, unsigned int le |
116 |
if (strcasecmp(ctx->last_map_key, "color") == 0) { |
117 |
sasprintf(&(ctx->block.color), "%.*s", len, val); |
118 |
} |
119 |
+ if (strcasecmp(ctx->last_map_key, "separator") == 0) { |
120 |
+ if (len == strlen("off") |
121 |
+ && !strncmp((const char*)val, "off", strlen("off"))) |
122 |
+ ctx->block.no_separator = true; |
123 |
+ } |
124 |
if (strcasecmp(ctx->last_map_key, "align") == 0) { |
125 |
if (len == strlen("left") && !strncmp((const char*)val, "left", strlen("left"))) { |
126 |
ctx->block.align = ALIGN_LEFT; |
b/i3bar/src/config.c
131 |
@@ -161,6 +161,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in |
132 |
|
133 |
COLOR(statusline, bar_fg); |
134 |
COLOR(background, bar_bg); |
135 |
+ COLOR(separator, sep_fg); |
136 |
COLOR(focused_workspace_border, focus_ws_border); |
137 |
COLOR(focused_workspace_bg, focus_ws_bg); |
138 |
COLOR(focused_workspace_text, focus_ws_fg); |
139 |
@@ -260,6 +261,7 @@ void free_colors(struct xcb_color_strings_t *colors) { |
140 |
} while (0) |
141 |
FREE_COLOR(bar_fg); |
142 |
FREE_COLOR(bar_bg); |
143 |
+ FREE_COLOR(sep_fg); |
144 |
FREE_COLOR(active_ws_fg); |
145 |
FREE_COLOR(active_ws_bg); |
146 |
FREE_COLOR(active_ws_border); |
b/i3bar/src/xcb.c
151 |
@@ -84,6 +84,7 @@ static mode binding; |
152 |
struct xcb_colors_t { |
153 |
uint32_t bar_fg; |
154 |
uint32_t bar_bg; |
155 |
+ uint32_t sep_fg; |
156 |
uint32_t active_ws_fg; |
157 |
uint32_t active_ws_bg; |
158 |
uint32_t active_ws_border; |
159 |
@@ -148,8 +149,11 @@ void refresh_statusline(void) { |
160 |
} |
161 |
|
162 |
/* If this is not the last block, add some pixels for a separator. */ |
163 |
- if (TAILQ_NEXT(block, blocks) != NULL) |
164 |
- block->width += 9; |
165 |
+ if (TAILQ_NEXT(block, blocks) != NULL) { |
166 |
+ /* If a block comes with no_separator, use 3 pixels to avoid |
167 |
+ text of the block sticking to the content of the next block. */ |
168 |
+ block->width += block->no_separator ? 3 : 9; |
169 |
+ } |
170 |
statusline_width += block->width + block->x_offset + block->x_append; |
171 |
} |
172 |
|
173 |
@@ -174,9 +178,9 @@ void refresh_statusline(void) { |
174 |
draw_text(block->full_text, statusline_pm, statusline_ctx, x + block->x_offset, 1, block->width); |
175 |
x += block->width + block->x_offset + block->x_append; |
176 |
|
177 |
- if (TAILQ_NEXT(block, blocks) != NULL) { |
178 |
+ if (TAILQ_NEXT(block, blocks) != NULL && !block->no_separator) { |
179 |
/* This is not the last block, draw a separator. */ |
180 |
- set_font_colors(statusline_ctx, get_colorpixel("#666666"), colors.bar_bg); |
181 |
+ set_font_colors(statusline_ctx, colors.sep_fg, colors.bar_bg); |
182 |
xcb_poly_line(xcb_connection, XCB_COORD_MODE_ORIGIN, statusline_pm, |
183 |
statusline_ctx, 2, |
184 |
(xcb_point_t[]){ { x - 5, 2 }, { x - 5, font.height - 2 } }); |
185 |
@@ -259,6 +263,7 @@ void init_colors(const struct xcb_color_strings_t *new_colors) { |
186 |
} while (0) |
187 |
PARSE_COLOR(bar_fg, "#FFFFFF"); |
188 |
PARSE_COLOR(bar_bg, "#000000"); |
189 |
+ PARSE_COLOR(sep_fg, "#666666"); |
190 |
PARSE_COLOR(active_ws_fg, "#FFFFFF"); |
191 |
PARSE_COLOR(active_ws_bg, "#333333"); |
192 |
PARSE_COLOR(active_ws_border, "#333333"); |
b/include/config.h
197 |
@@ -267,6 +267,7 @@ struct Barconfig { |
198 |
struct bar_colors { |
199 |
char *background; |
200 |
char *statusline; |
201 |
+ char *separator; |
202 |
|
203 |
char *focused_workspace_border; |
204 |
char *focused_workspace_bg; |
b/parser-specs/config.spec
209 |
@@ -419,7 +419,7 @@ state BAR_COLORS: |
210 |
end -> |
211 |
'#' -> BAR_COLORS_IGNORE_LINE |
212 |
'set' -> BAR_COLORS_IGNORE_LINE |
213 |
- colorclass = 'background', 'statusline' |
214 |
+ colorclass = 'background', 'statusline', 'separator' |
215 |
-> BAR_COLORS_SINGLE |
216 |
colorclass = 'focused_workspace', 'active_workspace', 'inactive_workspace', 'urgent_workspace' |
217 |
-> BAR_COLORS_BORDER |
b/src/config_directives.c
222 |
@@ -526,7 +526,10 @@ CFGFUN(bar_tray_output, const char *output) { |
223 |
CFGFUN(bar_color_single, const char *colorclass, const char *color) { |
224 |
if (strcmp(colorclass, "background") == 0) |
225 |
current_bar.colors.background = sstrdup(color); |
226 |
- else current_bar.colors.statusline = sstrdup(color); |
227 |
+ else if (strcmp(colorclass, "separator") == 0) |
228 |
+ current_bar.colors.separator = sstrdup(color); |
229 |
+ else |
230 |
+ current_bar.colors.statusline = sstrdup(color); |
231 |
} |
232 |
|
233 |
CFGFUN(bar_status_command, const char *command) { |
b/src/ipc.c
238 |
@@ -677,6 +677,7 @@ IPC_HANDLER(get_bar_config) { |
239 |
y(map_open); |
240 |
YSTR_IF_SET(background); |
241 |
YSTR_IF_SET(statusline); |
242 |
+ YSTR_IF_SET(separator); |
243 |
YSTR_IF_SET(focused_workspace_border); |
244 |
YSTR_IF_SET(focused_workspace_bg); |
245 |
YSTR_IF_SET(focused_workspace_text); |