]> git.sur5r.net Git - i3/i3/blob - src/config_directives.c
Merge pull request #1712 from Airblader/feature-next-wm-size-hints-adopted
[i3/i3] / src / config_directives.c
1 #undef I3__FILE__
2 #define I3__FILE__ "config_directives.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * config_directives.c: all config storing functions (see config_parser.c)
10  *
11  */
12 #include <float.h>
13 #include <stdarg.h>
14
15 #include "all.h"
16
17 /*******************************************************************************
18  * Criteria functions.
19  ******************************************************************************/
20
21 static int criteria_next_state;
22
23 /*
24  * Initializes the specified 'Match' data structure and the initial state of
25  * commands.c for matching target windows of a command.
26  *
27  */
28 CFGFUN(criteria_init, int _state) {
29     criteria_next_state = _state;
30
31     DLOG("Initializing criteria, current_match = %p, state = %d\n", current_match, _state);
32     match_init(current_match);
33 }
34
35 CFGFUN(criteria_pop_state) {
36     result->next_state = criteria_next_state;
37 }
38
39 /*
40  * Interprets a ctype=cvalue pair and adds it to the current match
41  * specification.
42  *
43  */
44 CFGFUN(criteria_add, const char *ctype, const char *cvalue) {
45     DLOG("ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
46
47     if (strcmp(ctype, "class") == 0) {
48         current_match->class = regex_new(cvalue);
49         return;
50     }
51
52     if (strcmp(ctype, "instance") == 0) {
53         current_match->instance = regex_new(cvalue);
54         return;
55     }
56
57     if (strcmp(ctype, "window_role") == 0) {
58         current_match->window_role = regex_new(cvalue);
59         return;
60     }
61
62     if (strcmp(ctype, "con_id") == 0) {
63         char *end;
64         long parsed = strtol(cvalue, &end, 10);
65         if (parsed == LONG_MIN ||
66             parsed == LONG_MAX ||
67             parsed < 0 ||
68             (end && *end != '\0')) {
69             ELOG("Could not parse con id \"%s\"\n", cvalue);
70         } else {
71             current_match->con_id = (Con *)parsed;
72             DLOG("id as int = %p\n", current_match->con_id);
73         }
74         return;
75     }
76
77     if (strcmp(ctype, "id") == 0) {
78         char *end;
79         long parsed = strtol(cvalue, &end, 10);
80         if (parsed == LONG_MIN ||
81             parsed == LONG_MAX ||
82             parsed < 0 ||
83             (end && *end != '\0')) {
84             ELOG("Could not parse window id \"%s\"\n", cvalue);
85         } else {
86             current_match->id = parsed;
87             DLOG("window id as int = %d\n", current_match->id);
88         }
89         return;
90     }
91
92     if (strcmp(ctype, "window_type") == 0) {
93         if (strcasecmp(cvalue, "normal") == 0)
94             current_match->window_type = A__NET_WM_WINDOW_TYPE_NORMAL;
95         else if (strcasecmp(cvalue, "dialog") == 0)
96             current_match->window_type = A__NET_WM_WINDOW_TYPE_DIALOG;
97         else if (strcasecmp(cvalue, "utility") == 0)
98             current_match->window_type = A__NET_WM_WINDOW_TYPE_UTILITY;
99         else if (strcasecmp(cvalue, "toolbar") == 0)
100             current_match->window_type = A__NET_WM_WINDOW_TYPE_TOOLBAR;
101         else if (strcasecmp(cvalue, "splash") == 0)
102             current_match->window_type = A__NET_WM_WINDOW_TYPE_SPLASH;
103         else if (strcasecmp(cvalue, "menu") == 0)
104             current_match->window_type = A__NET_WM_WINDOW_TYPE_MENU;
105         else if (strcasecmp(cvalue, "dropdown_menu") == 0)
106             current_match->window_type = A__NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
107         else if (strcasecmp(cvalue, "popup_menu") == 0)
108             current_match->window_type = A__NET_WM_WINDOW_TYPE_POPUP_MENU;
109         else if (strcasecmp(cvalue, "tooltip") == 0)
110             current_match->window_type = A__NET_WM_WINDOW_TYPE_TOOLTIP;
111         else
112             ELOG("unknown window_type value \"%s\"\n", cvalue);
113
114         return;
115     }
116
117     if (strcmp(ctype, "con_mark") == 0) {
118         current_match->mark = regex_new(cvalue);
119         return;
120     }
121
122     if (strcmp(ctype, "title") == 0) {
123         current_match->title = regex_new(cvalue);
124         return;
125     }
126
127     if (strcmp(ctype, "urgent") == 0) {
128         if (strcasecmp(cvalue, "latest") == 0 ||
129             strcasecmp(cvalue, "newest") == 0 ||
130             strcasecmp(cvalue, "recent") == 0 ||
131             strcasecmp(cvalue, "last") == 0) {
132             current_match->urgent = U_LATEST;
133         } else if (strcasecmp(cvalue, "oldest") == 0 ||
134                    strcasecmp(cvalue, "first") == 0) {
135             current_match->urgent = U_OLDEST;
136         }
137         return;
138     }
139
140     if (strcmp(ctype, "workspace") == 0) {
141         current_match->workspace = regex_new(cvalue);
142         return;
143     }
144
145     ELOG("Unknown criterion: %s\n", ctype);
146 }
147
148 /* TODO: refactor the above criteria code into a single file (with src/commands.c). */
149
150 /*******************************************************************************
151  * Utility functions
152  ******************************************************************************/
153
154 static bool eval_boolstr(const char *str) {
155     return (strcasecmp(str, "1") == 0 ||
156             strcasecmp(str, "yes") == 0 ||
157             strcasecmp(str, "true") == 0 ||
158             strcasecmp(str, "on") == 0 ||
159             strcasecmp(str, "enable") == 0 ||
160             strcasecmp(str, "active") == 0);
161 }
162
163 /*
164  * A utility function to convert a string of modifiers to the corresponding bit
165  * mask.
166  */
167 uint32_t modifiers_from_str(const char *str) {
168     /* It might be better to use strtok() here, but the simpler strstr() should
169      * do for now. */
170     uint32_t result = 0;
171     if (str == NULL)
172         return result;
173     if (strstr(str, "Mod1") != NULL)
174         result |= BIND_MOD1;
175     if (strstr(str, "Mod2") != NULL)
176         result |= BIND_MOD2;
177     if (strstr(str, "Mod3") != NULL)
178         result |= BIND_MOD3;
179     if (strstr(str, "Mod4") != NULL)
180         result |= BIND_MOD4;
181     if (strstr(str, "Mod5") != NULL)
182         result |= BIND_MOD5;
183     if (strstr(str, "Control") != NULL ||
184         strstr(str, "Ctrl") != NULL)
185         result |= BIND_CONTROL;
186     if (strstr(str, "Shift") != NULL)
187         result |= BIND_SHIFT;
188     if (strstr(str, "Mode_switch") != NULL)
189         result |= BIND_MODE_SWITCH;
190     return result;
191 }
192
193 static char *font_pattern;
194
195 CFGFUN(font, const char *font) {
196     config.font = load_font(font, true);
197     set_font(&config.font);
198
199     /* Save the font pattern for using it as bar font later on */
200     FREE(font_pattern);
201     font_pattern = sstrdup(font);
202 }
203
204 CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
205     configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE);
206 }
207
208 /*******************************************************************************
209  * Mode handling
210  ******************************************************************************/
211
212 static char *current_mode;
213
214 CFGFUN(mode_binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
215     configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode);
216 }
217
218 CFGFUN(enter_mode, const char *modename) {
219     if (strcasecmp(modename, DEFAULT_BINDING_MODE) == 0) {
220         ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE);
221         exit(1);
222     }
223     DLOG("\t now in mode %s\n", modename);
224     FREE(current_mode);
225     current_mode = sstrdup(modename);
226 }
227
228 CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *command) {
229     struct Autostart *new = smalloc(sizeof(struct Autostart));
230     new->command = sstrdup(command);
231     new->no_startup_id = (no_startup_id != NULL);
232     if (strcmp(exectype, "exec") == 0) {
233         TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
234     } else {
235         TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
236     }
237 }
238
239 CFGFUN(for_window, const char *command) {
240     if (match_is_empty(current_match)) {
241         ELOG("Match is empty, ignoring this for_window statement\n");
242         return;
243     }
244     DLOG("\t should execute command %s for the criteria mentioned above\n", command);
245     Assignment *assignment = scalloc(sizeof(Assignment));
246     assignment->type = A_COMMAND;
247     match_copy(&(assignment->match), current_match);
248     assignment->dest.command = sstrdup(command);
249     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
250 }
251
252 CFGFUN(floating_minimum_size, const long width, const long height) {
253     config.floating_minimum_width = width;
254     config.floating_minimum_height = height;
255 }
256
257 CFGFUN(floating_maximum_size, const long width, const long height) {
258     config.floating_maximum_width = width;
259     config.floating_maximum_height = height;
260 }
261
262 CFGFUN(floating_modifier, const char *modifiers) {
263     config.floating_modifier = modifiers_from_str(modifiers);
264 }
265
266 CFGFUN(default_orientation, const char *orientation) {
267     if (strcmp(orientation, "horizontal") == 0)
268         config.default_orientation = HORIZ;
269     else if (strcmp(orientation, "vertical") == 0)
270         config.default_orientation = VERT;
271     else
272         config.default_orientation = NO_ORIENTATION;
273 }
274
275 CFGFUN(workspace_layout, const char *layout) {
276     if (strcmp(layout, "default") == 0)
277         config.default_layout = L_DEFAULT;
278     else if (strcmp(layout, "stacking") == 0 ||
279              strcmp(layout, "stacked") == 0)
280         config.default_layout = L_STACKED;
281     else
282         config.default_layout = L_TABBED;
283 }
284
285 CFGFUN(new_window, const char *windowtype, const char *border, const long width) {
286     int border_style;
287     int border_width;
288
289     if (strcmp(border, "1pixel") == 0) {
290         border_style = BS_PIXEL;
291         border_width = 1;
292     } else if (strcmp(border, "none") == 0) {
293         border_style = BS_NONE;
294         border_width = 0;
295     } else if (strcmp(border, "pixel") == 0) {
296         border_style = BS_PIXEL;
297         border_width = width;
298     } else {
299         border_style = BS_NORMAL;
300         border_width = width;
301     }
302
303     if (strcmp(windowtype, "new_window") == 0) {
304         DLOG("default tiled border style = %d and border width = %d (%d physical px)\n",
305              border_style, border_width, logical_px(border_width));
306         config.default_border = border_style;
307         config.default_border_width = logical_px(border_width);
308     } else {
309         DLOG("default floating border style = %d and border width = %d (%d physical px)\n",
310              border_style, border_width, logical_px(border_width));
311         config.default_floating_border = border_style;
312         config.default_floating_border_width = logical_px(border_width);
313     }
314 }
315
316 CFGFUN(hide_edge_borders, const char *borders) {
317     if (strcmp(borders, "vertical") == 0)
318         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
319     else if (strcmp(borders, "horizontal") == 0)
320         config.hide_edge_borders = ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
321     else if (strcmp(borders, "both") == 0)
322         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE | ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
323     else if (strcmp(borders, "none") == 0)
324         config.hide_edge_borders = ADJ_NONE;
325     else if (eval_boolstr(borders))
326         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
327     else
328         config.hide_edge_borders = ADJ_NONE;
329 }
330
331 CFGFUN(focus_follows_mouse, const char *value) {
332     config.disable_focus_follows_mouse = !eval_boolstr(value);
333 }
334
335 CFGFUN(mouse_warping, const char *value) {
336     if (strcmp(value, "none") == 0)
337         config.mouse_warping = POINTER_WARPING_NONE;
338     else if (strcmp(value, "output") == 0)
339         config.mouse_warping = POINTER_WARPING_OUTPUT;
340 }
341
342 CFGFUN(force_xinerama, const char *value) {
343     config.force_xinerama = eval_boolstr(value);
344 }
345
346 CFGFUN(force_focus_wrapping, const char *value) {
347     config.force_focus_wrapping = eval_boolstr(value);
348 }
349
350 CFGFUN(workspace_back_and_forth, const char *value) {
351     config.workspace_auto_back_and_forth = eval_boolstr(value);
352 }
353
354 CFGFUN(fake_outputs, const char *outputs) {
355     config.fake_outputs = sstrdup(outputs);
356 }
357
358 CFGFUN(force_display_urgency_hint, const long duration_ms) {
359     config.workspace_urgency_timer = duration_ms / 1000.0;
360 }
361
362 CFGFUN(delay_exit_on_zero_displays, const long duration_ms) {
363     config.zero_disp_exit_timer_ms = duration_ms;
364 }
365
366 CFGFUN(focus_on_window_activation, const char *mode) {
367     if (strcmp(mode, "smart") == 0)
368         config.focus_on_window_activation = FOWA_SMART;
369     else if (strcmp(mode, "urgent") == 0)
370         config.focus_on_window_activation = FOWA_URGENT;
371     else if (strcmp(mode, "focus") == 0)
372         config.focus_on_window_activation = FOWA_FOCUS;
373     else if (strcmp(mode, "none") == 0)
374         config.focus_on_window_activation = FOWA_NONE;
375     else {
376         ELOG("Unknown focus_on_window_activation mode \"%s\", ignoring it.\n", mode);
377         return;
378     }
379
380     DLOG("Set new focus_on_window_activation mode = %i.\n", config.focus_on_window_activation);
381 }
382
383 CFGFUN(show_marks, const char *value) {
384     config.show_marks = eval_boolstr(value);
385 }
386
387 CFGFUN(workspace, const char *workspace, const char *output) {
388     DLOG("Assigning workspace \"%s\" to output \"%s\"\n", workspace, output);
389     /* Check for earlier assignments of the same workspace so that we
390      * don’t have assignments of a single workspace to different
391      * outputs */
392     struct Workspace_Assignment *assignment;
393     bool duplicate = false;
394     TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
395         if (strcasecmp(assignment->name, workspace) == 0) {
396             ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
397                  workspace);
398             assignment->output = sstrdup(output);
399             duplicate = true;
400         }
401     }
402     if (!duplicate) {
403         assignment = scalloc(sizeof(struct Workspace_Assignment));
404         assignment->name = sstrdup(workspace);
405         assignment->output = sstrdup(output);
406         TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
407     }
408 }
409
410 CFGFUN(ipc_socket, const char *path) {
411     config.ipc_socket_path = sstrdup(path);
412 }
413
414 CFGFUN(restart_state, const char *path) {
415     config.restart_state_path = sstrdup(path);
416 }
417
418 CFGFUN(popup_during_fullscreen, const char *value) {
419     if (strcmp(value, "ignore") == 0) {
420         config.popup_during_fullscreen = PDF_IGNORE;
421     } else if (strcmp(value, "leave_fullscreen") == 0) {
422         config.popup_during_fullscreen = PDF_LEAVE_FULLSCREEN;
423     } else {
424         config.popup_during_fullscreen = PDF_SMART;
425     }
426 }
427
428 CFGFUN(color_single, const char *colorclass, const char *color) {
429     /* used for client.background only currently */
430     config.client.background = get_colorpixel(color);
431 }
432
433 CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator) {
434 #define APPLY_COLORS(classname)                                                \
435     do {                                                                       \
436         if (strcmp(colorclass, "client." #classname) == 0) {                   \
437             config.client.classname.border = get_colorpixel(border);           \
438             config.client.classname.background = get_colorpixel(background);   \
439             config.client.classname.text = get_colorpixel(text);               \
440             if (indicator != NULL) {                                           \
441                 config.client.classname.indicator = get_colorpixel(indicator); \
442             }                                                                  \
443         }                                                                      \
444     } while (0)
445
446     APPLY_COLORS(focused_inactive);
447     APPLY_COLORS(focused);
448     APPLY_COLORS(unfocused);
449     APPLY_COLORS(urgent);
450     APPLY_COLORS(placeholder);
451
452 #undef APPLY_COLORS
453 }
454
455 CFGFUN(assign, const char *workspace) {
456     if (match_is_empty(current_match)) {
457         ELOG("Match is empty, ignoring this assignment\n");
458         return;
459     }
460     DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace);
461     Assignment *assignment = scalloc(sizeof(Assignment));
462     match_copy(&(assignment->match), current_match);
463     assignment->type = A_TO_WORKSPACE;
464     assignment->dest.workspace = sstrdup(workspace);
465     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
466 }
467
468 CFGFUN(no_focus) {
469     if (match_is_empty(current_match)) {
470         ELOG("Match is empty, ignoring this assignment\n");
471         return;
472     }
473
474     DLOG("New assignment, using above criteria, to ignore focus on manage.\n");
475     Assignment *assignment = scalloc(sizeof(Assignment));
476     match_copy(&(assignment->match), current_match);
477     assignment->type = A_NO_FOCUS;
478     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
479 }
480
481 /*******************************************************************************
482  * Bar configuration (i3bar)
483  ******************************************************************************/
484
485 static Barconfig current_bar;
486
487 CFGFUN(bar_font, const char *font) {
488     FREE(current_bar.font);
489     current_bar.font = sstrdup(font);
490 }
491
492 CFGFUN(bar_separator_symbol, const char *separator) {
493     FREE(current_bar.separator_symbol);
494     current_bar.separator_symbol = sstrdup(separator);
495 }
496
497 CFGFUN(bar_mode, const char *mode) {
498     current_bar.mode = (strcmp(mode, "dock") == 0 ? M_DOCK : (strcmp(mode, "hide") == 0 ? M_HIDE : M_INVISIBLE));
499 }
500
501 CFGFUN(bar_hidden_state, const char *hidden_state) {
502     current_bar.hidden_state = (strcmp(hidden_state, "hide") == 0 ? S_HIDE : S_SHOW);
503 }
504
505 CFGFUN(bar_id, const char *bar_id) {
506     current_bar.id = sstrdup(bar_id);
507 }
508
509 CFGFUN(bar_output, const char *output) {
510     int new_outputs = current_bar.num_outputs + 1;
511     current_bar.outputs = srealloc(current_bar.outputs, sizeof(char *) * new_outputs);
512     current_bar.outputs[current_bar.num_outputs] = sstrdup(output);
513     current_bar.num_outputs = new_outputs;
514 }
515
516 CFGFUN(bar_verbose, const char *verbose) {
517     current_bar.verbose = eval_boolstr(verbose);
518 }
519
520 CFGFUN(bar_modifier, const char *modifier) {
521     if (strcmp(modifier, "Mod1") == 0)
522         current_bar.modifier = M_MOD1;
523     else if (strcmp(modifier, "Mod2") == 0)
524         current_bar.modifier = M_MOD2;
525     else if (strcmp(modifier, "Mod3") == 0)
526         current_bar.modifier = M_MOD3;
527     else if (strcmp(modifier, "Mod4") == 0)
528         current_bar.modifier = M_MOD4;
529     else if (strcmp(modifier, "Mod5") == 0)
530         current_bar.modifier = M_MOD5;
531     else if (strcmp(modifier, "Control") == 0 ||
532              strcmp(modifier, "Ctrl") == 0)
533         current_bar.modifier = M_CONTROL;
534     else if (strcmp(modifier, "Shift") == 0)
535         current_bar.modifier = M_SHIFT;
536 }
537
538 static void bar_configure_binding(const char *button, const char *command) {
539     if (strncasecmp(button, "button", strlen("button")) != 0) {
540         ELOG("Bindings for a bar can only be mouse bindings, not \"%s\", ignoring.\n", button);
541         return;
542     }
543
544     int input_code = atoi(button + strlen("button"));
545     if (input_code < 1) {
546         ELOG("Button \"%s\" does not seem to be in format 'buttonX'.\n", button);
547         return;
548     }
549
550     struct Barbinding *current;
551     TAILQ_FOREACH(current, &(current_bar.bar_bindings), bindings) {
552         if (current->input_code == input_code) {
553             ELOG("command for button %s was already specified, ignoring.\n", button);
554             return;
555         }
556     }
557
558     struct Barbinding *new_binding = scalloc(sizeof(struct Barbinding));
559     new_binding->input_code = input_code;
560     new_binding->command = sstrdup(command);
561     TAILQ_INSERT_TAIL(&(current_bar.bar_bindings), new_binding, bindings);
562 }
563
564 CFGFUN(bar_wheel_up_cmd, const char *command) {
565     ELOG("'wheel_up_cmd' is deprecated. Please us 'bindsym button4 %s' instead.\n", command);
566     bar_configure_binding("button4", command);
567 }
568
569 CFGFUN(bar_wheel_down_cmd, const char *command) {
570     ELOG("'wheel_down_cmd' is deprecated. Please us 'bindsym button5 %s' instead.\n", command);
571     bar_configure_binding("button5", command);
572 }
573
574 CFGFUN(bar_bindsym, const char *button, const char *command) {
575     bar_configure_binding(button, command);
576 }
577
578 CFGFUN(bar_position, const char *position) {
579     current_bar.position = (strcmp(position, "top") == 0 ? P_TOP : P_BOTTOM);
580 }
581
582 CFGFUN(bar_i3bar_command, const char *i3bar_command) {
583     FREE(current_bar.i3bar_command);
584     current_bar.i3bar_command = sstrdup(i3bar_command);
585 }
586
587 CFGFUN(bar_color, const char *colorclass, const char *border, const char *background, const char *text) {
588 #define APPLY_COLORS(classname)                                          \
589     do {                                                                 \
590         if (strcmp(colorclass, #classname) == 0) {                       \
591             if (text != NULL) {                                          \
592                 /* New syntax: border, background, text */               \
593                 current_bar.colors.classname##_border = sstrdup(border); \
594                 current_bar.colors.classname##_bg = sstrdup(background); \
595                 current_bar.colors.classname##_text = sstrdup(text);     \
596             } else {                                                     \
597                 /* Old syntax: text, background */                       \
598                 current_bar.colors.classname##_bg = sstrdup(background); \
599                 current_bar.colors.classname##_text = sstrdup(border);   \
600             }                                                            \
601         }                                                                \
602     } while (0)
603
604     APPLY_COLORS(focused_workspace);
605     APPLY_COLORS(active_workspace);
606     APPLY_COLORS(inactive_workspace);
607     APPLY_COLORS(urgent_workspace);
608     APPLY_COLORS(binding_mode);
609
610 #undef APPLY_COLORS
611 }
612
613 CFGFUN(bar_socket_path, const char *socket_path) {
614     FREE(current_bar.socket_path);
615     current_bar.socket_path = sstrdup(socket_path);
616 }
617
618 CFGFUN(bar_tray_output, const char *output) {
619     FREE(current_bar.tray_output);
620     current_bar.tray_output = sstrdup(output);
621 }
622
623 CFGFUN(bar_tray_padding, const long padding_px) {
624     current_bar.tray_padding = padding_px;
625 }
626
627 CFGFUN(bar_color_single, const char *colorclass, const char *color) {
628     if (strcmp(colorclass, "background") == 0)
629         current_bar.colors.background = sstrdup(color);
630     else if (strcmp(colorclass, "separator") == 0)
631         current_bar.colors.separator = sstrdup(color);
632     else
633         current_bar.colors.statusline = sstrdup(color);
634 }
635
636 CFGFUN(bar_status_command, const char *command) {
637     FREE(current_bar.status_command);
638     current_bar.status_command = sstrdup(command);
639 }
640
641 CFGFUN(bar_binding_mode_indicator, const char *value) {
642     current_bar.hide_binding_mode_indicator = !eval_boolstr(value);
643 }
644
645 CFGFUN(bar_workspace_buttons, const char *value) {
646     current_bar.hide_workspace_buttons = !eval_boolstr(value);
647 }
648
649 CFGFUN(bar_strip_workspace_numbers, const char *value) {
650     current_bar.strip_workspace_numbers = eval_boolstr(value);
651 }
652
653 CFGFUN(bar_start) {
654     TAILQ_INIT(&(current_bar.bar_bindings));
655     current_bar.tray_padding = 2;
656 }
657
658 CFGFUN(bar_finish) {
659     DLOG("\t new bar configuration finished, saving.\n");
660     /* Generate a unique ID for this bar if not already configured */
661     if (!current_bar.id)
662         sasprintf(&current_bar.id, "bar-%d", config.number_barconfigs);
663
664     config.number_barconfigs++;
665
666     /* If no font was explicitly set, we use the i3 font as default */
667     if (!current_bar.font && font_pattern)
668         current_bar.font = sstrdup(font_pattern);
669
670     /* Copy the current (static) structure into a dynamically allocated
671      * one, then cleanup our static one. */
672     Barconfig *bar_config = scalloc(sizeof(Barconfig));
673     memcpy(bar_config, &current_bar, sizeof(Barconfig));
674     TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
675
676     memset(&current_bar, '\0', sizeof(Barconfig));
677 }