Add new bar.binding_mode_indicator configuration.
Patch status: superseded
Patch by syl20bnr
Long description:
i3 current behavior hides the binding mode indicator when workspace buttons are disabled. This patch adds a new configuration for i3bar called 'binding_mode_indicator' which acts like the workspace_buttons. It is now possible to configure i3bar to hide the workspace buttons and keep showing the binding mode indicator. This should make the hide workspace buttons configuration more convenient for those who are heavily using binding modes. Default value for binding_mode_indicator is true.
To apply this patch, use:
curl http://cr.i3wm.org/patch/212/raw.patch | git am
b/docs/ipc
34 |
@@ -494,6 +494,8 @@ font (string):: |
35 |
The font to use for text on the bar. |
36 |
workspace_buttons (boolean):: |
37 |
Display workspace buttons or not? Defaults to true. |
38 |
+binding_mode_indicator (boolean):: |
39 |
+ Display the mode indicator or not? Defaults to true. |
40 |
verbose (boolean):: |
41 |
Should the bar enable verbose output for debugging? Defaults to false. |
42 |
colors (map):: |
43 |
@@ -539,6 +541,7 @@ urgent_workspace_text/urgent_workspace_bar:: |
44 |
"status_command": "i3status", |
45 |
"font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1", |
46 |
"workspace_buttons": true, |
47 |
+ "binding_mode_indicator": true, |
48 |
"verbose": false, |
49 |
"colors": { |
50 |
"background": "#c0c0c0", |
b/docs/userguide
55 |
@@ -1186,6 +1186,28 @@ bar { |
56 |
} |
57 |
-------------------- |
58 |
|
59 |
+=== Binding Mode indicator |
60 |
+ |
61 |
+Specifies whether the current binding mode indicator should be shown or not. |
62 |
+This is useful if you want to hide the workspace buttons but still be able |
63 |
+to see the current binding mode indicator. |
64 |
+For an example of a +mode+ definition, please refer to the resize mode |
65 |
+section. |
66 |
+ |
67 |
+The default is to show the mode button. |
68 |
+ |
69 |
+*Syntax*: |
70 |
+-------------------------- |
71 |
+binding_mode_indicator <yes|no> |
72 |
+-------------------------- |
73 |
+ |
74 |
+*Example*: |
75 |
+-------------------- |
76 |
+bar { |
77 |
+ binding_mode_indicator no |
78 |
+} |
79 |
+-------------------- |
80 |
+ |
81 |
=== Colors |
82 |
|
83 |
As with i3, colors are in HTML hex format (#rrggbb). The following colors can |
b/i3bar/include/config.h
88 |
@@ -23,6 +23,7 @@ typedef struct config_t { |
89 |
position_t position; |
90 |
int verbose; |
91 |
struct xcb_color_strings_t colors; |
92 |
+ int disable_binding_mode_indicator; |
93 |
int disable_ws; |
94 |
char *bar_id; |
95 |
char *command; |
b/i3bar/src/config.c
100 |
@@ -193,6 +193,12 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in |
101 |
* |
102 |
*/ |
103 |
static int config_boolean_cb(void *params_, int val) { |
104 |
+ if (!strcmp(cur_key, "binding_mode_indicator")) { |
105 |
+ DLOG("binding_mode_indicator = %d\n", val); |
106 |
+ config.disable_binding_mode_indicator = !val; |
107 |
+ return 1; |
108 |
+ } |
109 |
+ |
110 |
if (!strcmp(cur_key, "workspace_buttons")) { |
111 |
DLOG("workspace_buttons = %d\n", val); |
112 |
config.disable_ws = !val; |
b/i3bar/src/xcb.c
117 |
@@ -1666,72 +1666,72 @@ void draw_bars(bool unhide) { |
118 |
MIN(outputs_walk->rect.w - traypx - 4, statusline_width), font.height + 2); |
119 |
} |
120 |
|
121 |
- if (config.disable_ws) { |
122 |
- continue; |
123 |
- } |
124 |
- |
125 |
- i3_ws *ws_walk; |
126 |
- |
127 |
- TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { |
128 |
- DLOG("Drawing Button for WS %s at x = %d, len = %d\n", i3string_as_utf8(ws_walk->name), i, ws_walk->name_width); |
129 |
- uint32_t fg_color = colors.inactive_ws_fg; |
130 |
- uint32_t bg_color = colors.inactive_ws_bg; |
131 |
- uint32_t border_color = colors.inactive_ws_border; |
132 |
- if (ws_walk->visible) { |
133 |
- if (!ws_walk->focused) { |
134 |
- fg_color = colors.active_ws_fg; |
135 |
- bg_color = colors.active_ws_bg; |
136 |
- border_color = colors.active_ws_border; |
137 |
- } else { |
138 |
- fg_color = colors.focus_ws_fg; |
139 |
- bg_color = colors.focus_ws_bg; |
140 |
- border_color = colors.focus_ws_border; |
141 |
- if (last_urgent_ws && strcmp(i3string_as_utf8(ws_walk->name), last_urgent_ws) == 0) |
142 |
- walks_away = false; |
143 |
+ if (!config.disable_ws) { |
144 |
+ i3_ws *ws_walk; |
145 |
+ TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) { |
146 |
+ DLOG("Drawing Button for WS %s at x = %d, len = %d\n", |
147 |
+ i3string_as_utf8(ws_walk->name), i, ws_walk->name_width); |
148 |
+ uint32_t fg_color = colors.inactive_ws_fg; |
149 |
+ uint32_t bg_color = colors.inactive_ws_bg; |
150 |
+ uint32_t border_color = colors.inactive_ws_border; |
151 |
+ if (ws_walk->visible) { |
152 |
+ if (!ws_walk->focused) { |
153 |
+ fg_color = colors.active_ws_fg; |
154 |
+ bg_color = colors.active_ws_bg; |
155 |
+ border_color = colors.active_ws_border; |
156 |
+ } else { |
157 |
+ fg_color = colors.focus_ws_fg; |
158 |
+ bg_color = colors.focus_ws_bg; |
159 |
+ border_color = colors.focus_ws_border; |
160 |
+ if (last_urgent_ws && strcmp(i3string_as_utf8(ws_walk->name), |
161 |
+ last_urgent_ws) == 0) |
162 |
+ walks_away = false; |
163 |
+ } |
164 |
} |
165 |
- } |
166 |
- if (ws_walk->urgent) { |
167 |
- DLOG("WS %s is urgent!\n", i3string_as_utf8(ws_walk->name)); |
168 |
- fg_color = colors.urgent_ws_fg; |
169 |
- bg_color = colors.urgent_ws_bg; |
170 |
- border_color = colors.urgent_ws_border; |
171 |
- unhide = true; |
172 |
- if (!ws_walk->focused) { |
173 |
- FREE(last_urgent_ws); |
174 |
- last_urgent_ws = sstrdup(i3string_as_utf8(ws_walk->name)); |
175 |
+ if (ws_walk->urgent) { |
176 |
+ DLOG("WS %s is urgent!\n", i3string_as_utf8(ws_walk->name)); |
177 |
+ fg_color = colors.urgent_ws_fg; |
178 |
+ bg_color = colors.urgent_ws_bg; |
179 |
+ border_color = colors.urgent_ws_border; |
180 |
+ unhide = true; |
181 |
+ if (!ws_walk->focused) { |
182 |
+ FREE(last_urgent_ws); |
183 |
+ last_urgent_ws = sstrdup(i3string_as_utf8(ws_walk->name)); |
184 |
+ } |
185 |
} |
186 |
- } |
187 |
- uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; |
188 |
- uint32_t vals_border[] = { border_color, border_color }; |
189 |
- xcb_change_gc(xcb_connection, |
190 |
- outputs_walk->bargc, |
191 |
- mask, |
192 |
- vals_border); |
193 |
- xcb_rectangle_t rect_border = { i, 1, ws_walk->name_width + 10, font.height + 4 }; |
194 |
- xcb_poly_fill_rectangle(xcb_connection, |
195 |
- outputs_walk->buffer, |
196 |
- outputs_walk->bargc, |
197 |
- 1, |
198 |
- &rect_border); |
199 |
- uint32_t vals[] = { bg_color, bg_color }; |
200 |
- xcb_change_gc(xcb_connection, |
201 |
- outputs_walk->bargc, |
202 |
- mask, |
203 |
- vals); |
204 |
- xcb_rectangle_t rect = { i + 1, 2, ws_walk->name_width + 8, font.height + 2 }; |
205 |
- xcb_poly_fill_rectangle(xcb_connection, |
206 |
- outputs_walk->buffer, |
207 |
- outputs_walk->bargc, |
208 |
- 1, |
209 |
- &rect); |
210 |
- set_font_colors(outputs_walk->bargc, fg_color, bg_color); |
211 |
- draw_text(ws_walk->name, outputs_walk->buffer, outputs_walk->bargc, i + 5, 3, ws_walk->name_width); |
212 |
- i += 10 + ws_walk->name_width + 1; |
213 |
+ uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; |
214 |
+ uint32_t vals_border[] = { border_color, border_color }; |
215 |
+ xcb_change_gc(xcb_connection, |
216 |
+ outputs_walk->bargc, |
217 |
+ mask, |
218 |
+ vals_border); |
219 |
+ xcb_rectangle_t rect_border = { i, 1, ws_walk->name_width + 10, font.height + 4 }; |
220 |
+ xcb_poly_fill_rectangle(xcb_connection, |
221 |
+ outputs_walk->buffer, |
222 |
+ outputs_walk->bargc, |
223 |
+ 1, |
224 |
+ &rect_border); |
225 |
+ uint32_t vals[] = { bg_color, bg_color }; |
226 |
+ xcb_change_gc(xcb_connection, |
227 |
+ outputs_walk->bargc, |
228 |
+ mask, |
229 |
+ vals); |
230 |
+ xcb_rectangle_t rect = { i + 1, 2, ws_walk->name_width + 8, font.height + 2 }; |
231 |
+ xcb_poly_fill_rectangle(xcb_connection, |
232 |
+ outputs_walk->buffer, |
233 |
+ outputs_walk->bargc, |
234 |
+ 1, |
235 |
+ &rect); |
236 |
+ set_font_colors(outputs_walk->bargc, fg_color, bg_color); |
237 |
+ draw_text(ws_walk->name, outputs_walk->buffer, outputs_walk->bargc, |
238 |
+ i + 5, 3, ws_walk->name_width); |
239 |
+ i += 10 + ws_walk->name_width + 1; |
240 |
|
241 |
+ } |
242 |
} |
243 |
|
244 |
- if (binding.name) { |
245 |
|
246 |
+ if (binding.name && !config.disable_binding_mode_indicator) { |
247 |
uint32_t fg_color = colors.urgent_ws_fg; |
248 |
uint32_t bg_color = colors.urgent_ws_bg; |
249 |
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND; |
250 |
@@ -1766,6 +1766,7 @@ void draw_bars(bool unhide) { |
251 |
unhide = true; |
252 |
} |
253 |
|
254 |
+ |
255 |
i = 0; |
256 |
} |
257 |
|
b/include/config.h
262 |
@@ -267,6 +267,10 @@ struct Barconfig { |
263 |
* zero. */ |
264 |
bool hide_workspace_buttons; |
265 |
|
266 |
+ /** Hide mode button? Configuration option is 'binding_mode_indicator no' |
267 |
+ * but we invert the bool for the same reason as hide_workspace_buttons.*/ |
268 |
+ bool hide_binding_mode_indicator; |
269 |
+ |
270 |
/** Enable verbose mode? Useful for debugging purposes. */ |
271 |
bool verbose; |
272 |
|
b/include/config_directives.h
277 |
@@ -74,6 +74,7 @@ CFGFUN(bar_socket_path, const char *socket_path); |
278 |
CFGFUN(bar_tray_output, const char *output); |
279 |
CFGFUN(bar_color_single, const char *colorclass, const char *color); |
280 |
CFGFUN(bar_status_command, const char *command); |
281 |
+CFGFUN(bar_binding_mode_indicator, const char *value); |
282 |
CFGFUN(bar_workspace_buttons, const char *value); |
283 |
CFGFUN(bar_finish); |
284 |
|
b/parser-specs/config.spec
289 |
@@ -345,20 +345,21 @@ state BAR: |
290 |
error -> |
291 |
'#' -> BAR_IGNORE_LINE |
292 |
'set' -> BAR_IGNORE_LINE |
293 |
- 'i3bar_command' -> BAR_BAR_COMMAND |
294 |
- 'status_command' -> BAR_STATUS_COMMAND |
295 |
- 'socket_path' -> BAR_SOCKET_PATH |
296 |
- 'mode' -> BAR_MODE |
297 |
- 'hidden_state' -> BAR_HIDDEN_STATE |
298 |
- 'id' -> BAR_ID |
299 |
- 'modifier' -> BAR_MODIFIER |
300 |
- 'position' -> BAR_POSITION |
301 |
- 'output' -> BAR_OUTPUT |
302 |
- 'tray_output' -> BAR_TRAY_OUTPUT |
303 |
- 'font' -> BAR_FONT |
304 |
- 'workspace_buttons' -> BAR_WORKSPACE_BUTTONS |
305 |
- 'verbose' -> BAR_VERBOSE |
306 |
- 'colors' -> BAR_COLORS_BRACE |
307 |
+ 'i3bar_command' -> BAR_BAR_COMMAND |
308 |
+ 'status_command' -> BAR_STATUS_COMMAND |
309 |
+ 'socket_path' -> BAR_SOCKET_PATH |
310 |
+ 'mode' -> BAR_MODE |
311 |
+ 'hidden_state' -> BAR_HIDDEN_STATE |
312 |
+ 'id' -> BAR_ID |
313 |
+ 'modifier' -> BAR_MODIFIER |
314 |
+ 'position' -> BAR_POSITION |
315 |
+ 'output' -> BAR_OUTPUT |
316 |
+ 'tray_output' -> BAR_TRAY_OUTPUT |
317 |
+ 'font' -> BAR_FONT |
318 |
+ 'binding_mode_indicator' -> BAR_BINDING_MODE_INDICATOR |
319 |
+ 'workspace_buttons' -> BAR_WORKSPACE_BUTTONS |
320 |
+ 'verbose' -> BAR_VERBOSE |
321 |
+ 'colors' -> BAR_COLORS_BRACE |
322 |
'}' |
323 |
-> call cfg_bar_finish(); INITIAL |
324 |
|
325 |
@@ -411,6 +412,10 @@ state BAR_FONT: |
326 |
font = string |
327 |
-> call cfg_bar_font($font); BAR |
328 |
|
329 |
+state BAR_BINDING_MODE_INDICATOR: |
330 |
+ value = word |
331 |
+ -> call cfg_bar_binding_mode_indicator($value); BAR |
332 |
+ |
333 |
state BAR_WORKSPACE_BUTTONS: |
334 |
value = word |
335 |
-> call cfg_bar_workspace_buttons($value); BAR |
b/src/config_directives.c
340 |
@@ -550,6 +550,10 @@ CFGFUN(bar_status_command, const char *command) { |
341 |
current_bar.status_command = sstrdup(command); |
342 |
} |
343 |
|
344 |
+CFGFUN(bar_binding_mode_indicator, const char *value) { |
345 |
+ current_bar.hide_binding_mode_indicator = !eval_boolstr(value); |
346 |
+} |
347 |
+ |
348 |
CFGFUN(bar_workspace_buttons, const char *value) { |
349 |
current_bar.hide_workspace_buttons = !eval_boolstr(value); |
350 |
} |
b/src/ipc.c
355 |
@@ -686,6 +686,9 @@ IPC_HANDLER(get_bar_config) { |
356 |
ystr("workspace_buttons"); |
357 |
y(bool, !config->hide_workspace_buttons); |
358 |
|
359 |
+ ystr("binding_mode_indicator"); |
360 |
+ y(bool, !config->hide_binding_mode_indicator); |
361 |
+ |
362 |
ystr("verbose"); |
363 |
y(bool, config->verbose); |
364 |
|
b/testcases/t/177-bar-config.t
369 |
@@ -63,6 +63,7 @@ my $bar_config = $i3->get_bar_config($bar_id)->recv; |
370 |
is($bar_config->{status_command}, 'i3status --foo', 'status_command correct'); |
371 |
ok(!$bar_config->{verbose}, 'verbose off by default'); |
372 |
ok($bar_config->{workspace_buttons}, 'workspace buttons enabled per default'); |
373 |
+ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled per default'); |
374 |
is($bar_config->{mode}, 'dock', 'dock mode by default'); |
375 |
is($bar_config->{position}, 'bottom', 'position bottom by default'); |
376 |
|
377 |
@@ -85,7 +86,8 @@ $config = <<EOT; |
378 |
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
379 |
|
380 |
bar { |
381 |
- # Start a default instance of i3bar which provides workspace buttons. |
382 |
+ # Start a default instance of i3bar which does not provide |
383 |
+ # workspace buttons. |
384 |
# Additionally, i3status will provide a statusline. |
385 |
status_command i3status --bar |
386 |
|
387 |
@@ -98,6 +100,7 @@ bar { |
388 |
mode dock |
389 |
font Terminus |
390 |
workspace_buttons no |
391 |
+ binding_mode_indicator no |
392 |
verbose yes |
393 |
socket_path /tmp/foobar |
394 |
|
395 |
@@ -125,6 +128,7 @@ $bar_config = $i3->get_bar_config($bar_id)->recv; |
396 |
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct'); |
397 |
ok($bar_config->{verbose}, 'verbose on'); |
398 |
ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled'); |
399 |
+ok(!$bar_config->{binding_mode_indicator}, 'mode indicator disabled'); |
400 |
is($bar_config->{mode}, 'dock', 'dock mode'); |
401 |
is($bar_config->{position}, 'top', 'position top'); |
402 |
is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok'); |
403 |
@@ -230,7 +234,8 @@ $config = <<EOT; |
404 |
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
405 |
|
406 |
bar { |
407 |
- # Start a default instance of i3bar which provides workspace buttons. |
408 |
+ # Start a default instance of i3bar which does not provide |
409 |
+ # workspace buttons. |
410 |
# Additionally, i3status will provide a statusline. |
411 |
status_command i3status --bar |
412 |
|
413 |
@@ -243,6 +248,7 @@ bar { |
414 |
mode dock |
415 |
font Terminus |
416 |
workspace_buttons no |
417 |
+ binding_mode_indicator yes |
418 |
verbose yes |
419 |
socket_path /tmp/foobar |
420 |
|
421 |
@@ -271,6 +277,7 @@ $bar_config = $i3->get_bar_config($bar_id)->recv; |
422 |
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct'); |
423 |
ok($bar_config->{verbose}, 'verbose on'); |
424 |
ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled'); |
425 |
+ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled'); |
426 |
is($bar_config->{mode}, 'dock', 'dock mode'); |
427 |
is($bar_config->{position}, 'top', 'position top'); |
428 |
is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok'); |
b/testcases/t/201-config-parser.t
433 |
@@ -627,7 +627,7 @@ EOT |
434 |
|
435 |
$expected = <<'EOT'; |
436 |
cfg_bar_output(LVDS-1) |
437 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'workspace_buttons', 'verbose', 'colors', '}' |
438 |
+ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'binding_mode_indicator', 'workspace_buttons', 'verbose', 'colors', '}' |
439 |
ERROR: CONFIG: (in file <stdin>) |
440 |
ERROR: CONFIG: Line 1: bar { |
441 |
ERROR: CONFIG: Line 2: output LVDS-1 |