]> git.sur5r.net Git - i3/i3/blob - src/config_directives.c
Merge branch 'master' into next
[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 containing the group and modifiers to
165  * the corresponding bit mask.
166  */
167 i3_event_state_mask_t event_state_from_str(const char *str) {
168     /* It might be better to use strtok() here, but the simpler strstr() should
169      * do for now. */
170     i3_event_state_mask_t result = 0;
171     if (str == NULL)
172         return result;
173     if (strstr(str, "Mod1") != NULL)
174         result |= XCB_KEY_BUT_MASK_MOD_1;
175     if (strstr(str, "Mod2") != NULL)
176         result |= XCB_KEY_BUT_MASK_MOD_2;
177     if (strstr(str, "Mod3") != NULL)
178         result |= XCB_KEY_BUT_MASK_MOD_3;
179     if (strstr(str, "Mod4") != NULL)
180         result |= XCB_KEY_BUT_MASK_MOD_4;
181     if (strstr(str, "Mod5") != NULL)
182         result |= XCB_KEY_BUT_MASK_MOD_5;
183     if (strstr(str, "Control") != NULL ||
184         strstr(str, "Ctrl") != NULL)
185         result |= XCB_KEY_BUT_MASK_CONTROL;
186     if (strstr(str, "Shift") != NULL)
187         result |= XCB_KEY_BUT_MASK_SHIFT;
188
189     if (strstr(str, "Group1") != NULL)
190         result |= (I3_XKB_GROUP_MASK_1 << 16);
191     if (strstr(str, "Group2") != NULL ||
192         strstr(str, "Mode_switch") != NULL)
193         result |= (I3_XKB_GROUP_MASK_2 << 16);
194     if (strstr(str, "Group3") != NULL)
195         result |= (I3_XKB_GROUP_MASK_3 << 16);
196     if (strstr(str, "Group4") != NULL)
197         result |= (I3_XKB_GROUP_MASK_4 << 16);
198     return result;
199 }
200
201 static char *font_pattern;
202
203 CFGFUN(font, const char *font) {
204     config.font = load_font(font, true);
205     set_font(&config.font);
206
207     /* Save the font pattern for using it as bar font later on */
208     FREE(font_pattern);
209     font_pattern = sstrdup(font);
210 }
211
212 CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
213     configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE);
214 }
215
216 /*******************************************************************************
217  * Mode handling
218  ******************************************************************************/
219
220 static char *current_mode;
221
222 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) {
223     configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode);
224 }
225
226 CFGFUN(enter_mode, const char *modename) {
227     if (strcasecmp(modename, DEFAULT_BINDING_MODE) == 0) {
228         ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE);
229         exit(1);
230     }
231     DLOG("\t now in mode %s\n", modename);
232     FREE(current_mode);
233     current_mode = sstrdup(modename);
234 }
235
236 CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *command) {
237     struct Autostart *new = smalloc(sizeof(struct Autostart));
238     new->command = sstrdup(command);
239     new->no_startup_id = (no_startup_id != NULL);
240     if (strcmp(exectype, "exec") == 0) {
241         TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
242     } else {
243         TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
244     }
245 }
246
247 CFGFUN(for_window, const char *command) {
248     if (match_is_empty(current_match)) {
249         ELOG("Match is empty, ignoring this for_window statement\n");
250         return;
251     }
252     DLOG("\t should execute command %s for the criteria mentioned above\n", command);
253     Assignment *assignment = scalloc(1, sizeof(Assignment));
254     assignment->type = A_COMMAND;
255     match_copy(&(assignment->match), current_match);
256     assignment->dest.command = sstrdup(command);
257     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
258 }
259
260 CFGFUN(floating_minimum_size, const long width, const long height) {
261     config.floating_minimum_width = width;
262     config.floating_minimum_height = height;
263 }
264
265 CFGFUN(floating_maximum_size, const long width, const long height) {
266     config.floating_maximum_width = width;
267     config.floating_maximum_height = height;
268 }
269
270 CFGFUN(floating_modifier, const char *modifiers) {
271     config.floating_modifier = event_state_from_str(modifiers);
272 }
273
274 CFGFUN(default_orientation, const char *orientation) {
275     if (strcmp(orientation, "horizontal") == 0)
276         config.default_orientation = HORIZ;
277     else if (strcmp(orientation, "vertical") == 0)
278         config.default_orientation = VERT;
279     else
280         config.default_orientation = NO_ORIENTATION;
281 }
282
283 CFGFUN(workspace_layout, const char *layout) {
284     if (strcmp(layout, "default") == 0)
285         config.default_layout = L_DEFAULT;
286     else if (strcmp(layout, "stacking") == 0 ||
287              strcmp(layout, "stacked") == 0)
288         config.default_layout = L_STACKED;
289     else
290         config.default_layout = L_TABBED;
291 }
292
293 CFGFUN(new_window, const char *windowtype, const char *border, const long width) {
294     int border_style;
295     int border_width;
296
297     if (strcmp(border, "1pixel") == 0) {
298         border_style = BS_PIXEL;
299         border_width = 1;
300     } else if (strcmp(border, "none") == 0) {
301         border_style = BS_NONE;
302         border_width = 0;
303     } else if (strcmp(border, "pixel") == 0) {
304         border_style = BS_PIXEL;
305         border_width = width;
306     } else {
307         border_style = BS_NORMAL;
308         border_width = width;
309     }
310
311     if (strcmp(windowtype, "new_window") == 0) {
312         DLOG("default tiled border style = %d and border width = %d (%d physical px)\n",
313              border_style, border_width, logical_px(border_width));
314         config.default_border = border_style;
315         config.default_border_width = logical_px(border_width);
316     } else {
317         DLOG("default floating border style = %d and border width = %d (%d physical px)\n",
318              border_style, border_width, logical_px(border_width));
319         config.default_floating_border = border_style;
320         config.default_floating_border_width = logical_px(border_width);
321     }
322 }
323
324 CFGFUN(hide_edge_borders, const char *borders) {
325     if (strcmp(borders, "vertical") == 0)
326         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
327     else if (strcmp(borders, "horizontal") == 0)
328         config.hide_edge_borders = ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
329     else if (strcmp(borders, "both") == 0)
330         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE | ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
331     else if (strcmp(borders, "none") == 0)
332         config.hide_edge_borders = ADJ_NONE;
333     else if (eval_boolstr(borders))
334         config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
335     else
336         config.hide_edge_borders = ADJ_NONE;
337 }
338
339 CFGFUN(focus_follows_mouse, const char *value) {
340     config.disable_focus_follows_mouse = !eval_boolstr(value);
341 }
342
343 CFGFUN(mouse_warping, const char *value) {
344     if (strcmp(value, "none") == 0)
345         config.mouse_warping = POINTER_WARPING_NONE;
346     else if (strcmp(value, "output") == 0)
347         config.mouse_warping = POINTER_WARPING_OUTPUT;
348 }
349
350 CFGFUN(force_xinerama, const char *value) {
351     config.force_xinerama = eval_boolstr(value);
352 }
353
354 CFGFUN(force_focus_wrapping, const char *value) {
355     config.force_focus_wrapping = eval_boolstr(value);
356 }
357
358 CFGFUN(workspace_back_and_forth, const char *value) {
359     config.workspace_auto_back_and_forth = eval_boolstr(value);
360 }
361
362 CFGFUN(fake_outputs, const char *outputs) {
363     config.fake_outputs = sstrdup(outputs);
364 }
365
366 CFGFUN(force_display_urgency_hint, const long duration_ms) {
367     config.workspace_urgency_timer = duration_ms / 1000.0;
368 }
369
370 CFGFUN(delay_exit_on_zero_displays, const long duration_ms) {
371     config.zero_disp_exit_timer_ms = duration_ms;
372 }
373
374 CFGFUN(focus_on_window_activation, const char *mode) {
375     if (strcmp(mode, "smart") == 0)
376         config.focus_on_window_activation = FOWA_SMART;
377     else if (strcmp(mode, "urgent") == 0)
378         config.focus_on_window_activation = FOWA_URGENT;
379     else if (strcmp(mode, "focus") == 0)
380         config.focus_on_window_activation = FOWA_FOCUS;
381     else if (strcmp(mode, "none") == 0)
382         config.focus_on_window_activation = FOWA_NONE;
383     else {
384         ELOG("Unknown focus_on_window_activation mode \"%s\", ignoring it.\n", mode);
385         return;
386     }
387
388     DLOG("Set new focus_on_window_activation mode = %i.\n", config.focus_on_window_activation);
389 }
390
391 CFGFUN(show_marks, const char *value) {
392     config.show_marks = eval_boolstr(value);
393 }
394
395 CFGFUN(workspace, const char *workspace, const char *output) {
396     DLOG("Assigning workspace \"%s\" to output \"%s\"\n", workspace, output);
397     /* Check for earlier assignments of the same workspace so that we
398      * don’t have assignments of a single workspace to different
399      * outputs */
400     struct Workspace_Assignment *assignment;
401     bool duplicate = false;
402     TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
403         if (strcasecmp(assignment->name, workspace) == 0) {
404             ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
405                  workspace);
406             assignment->output = sstrdup(output);
407             duplicate = true;
408         }
409     }
410     if (!duplicate) {
411         assignment = scalloc(1, sizeof(struct Workspace_Assignment));
412         assignment->name = sstrdup(workspace);
413         assignment->output = sstrdup(output);
414         TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
415     }
416 }
417
418 CFGFUN(ipc_socket, const char *path) {
419     config.ipc_socket_path = sstrdup(path);
420 }
421
422 CFGFUN(restart_state, const char *path) {
423     config.restart_state_path = sstrdup(path);
424 }
425
426 CFGFUN(popup_during_fullscreen, const char *value) {
427     if (strcmp(value, "ignore") == 0) {
428         config.popup_during_fullscreen = PDF_IGNORE;
429     } else if (strcmp(value, "leave_fullscreen") == 0) {
430         config.popup_during_fullscreen = PDF_LEAVE_FULLSCREEN;
431     } else {
432         config.popup_during_fullscreen = PDF_SMART;
433     }
434 }
435
436 CFGFUN(color_single, const char *colorclass, const char *color) {
437     /* used for client.background only currently */
438     config.client.background = get_colorpixel(color);
439 }
440
441 CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator) {
442 #define APPLY_COLORS(classname)                                                \
443     do {                                                                       \
444         if (strcmp(colorclass, "client." #classname) == 0) {                   \
445             config.client.classname.border = get_colorpixel(border);           \
446             config.client.classname.background = get_colorpixel(background);   \
447             config.client.classname.text = get_colorpixel(text);               \
448             if (indicator != NULL) {                                           \
449                 config.client.classname.indicator = get_colorpixel(indicator); \
450             }                                                                  \
451         }                                                                      \
452     } while (0)
453
454     APPLY_COLORS(focused_inactive);
455     APPLY_COLORS(focused);
456     APPLY_COLORS(unfocused);
457     APPLY_COLORS(urgent);
458     APPLY_COLORS(placeholder);
459
460 #undef APPLY_COLORS
461 }
462
463 CFGFUN(assign, const char *workspace) {
464     if (match_is_empty(current_match)) {
465         ELOG("Match is empty, ignoring this assignment\n");
466         return;
467     }
468     DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace);
469     Assignment *assignment = scalloc(1, sizeof(Assignment));
470     match_copy(&(assignment->match), current_match);
471     assignment->type = A_TO_WORKSPACE;
472     assignment->dest.workspace = sstrdup(workspace);
473     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
474 }
475
476 CFGFUN(no_focus) {
477     if (match_is_empty(current_match)) {
478         ELOG("Match is empty, ignoring this assignment\n");
479         return;
480     }
481
482     DLOG("New assignment, using above criteria, to ignore focus on manage.\n");
483     Assignment *assignment = scalloc(1, sizeof(Assignment));
484     match_copy(&(assignment->match), current_match);
485     assignment->type = A_NO_FOCUS;
486     TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
487 }
488
489 /*******************************************************************************
490  * Bar configuration (i3bar)
491  ******************************************************************************/
492
493 static Barconfig current_bar;
494
495 CFGFUN(bar_font, const char *font) {
496     FREE(current_bar.font);
497     current_bar.font = sstrdup(font);
498 }
499
500 CFGFUN(bar_separator_symbol, const char *separator) {
501     FREE(current_bar.separator_symbol);
502     current_bar.separator_symbol = sstrdup(separator);
503 }
504
505 CFGFUN(bar_mode, const char *mode) {
506     current_bar.mode = (strcmp(mode, "dock") == 0 ? M_DOCK : (strcmp(mode, "hide") == 0 ? M_HIDE : M_INVISIBLE));
507 }
508
509 CFGFUN(bar_hidden_state, const char *hidden_state) {
510     current_bar.hidden_state = (strcmp(hidden_state, "hide") == 0 ? S_HIDE : S_SHOW);
511 }
512
513 CFGFUN(bar_id, const char *bar_id) {
514     current_bar.id = sstrdup(bar_id);
515 }
516
517 CFGFUN(bar_output, const char *output) {
518     int new_outputs = current_bar.num_outputs + 1;
519     current_bar.outputs = srealloc(current_bar.outputs, sizeof(char *) * new_outputs);
520     current_bar.outputs[current_bar.num_outputs] = sstrdup(output);
521     current_bar.num_outputs = new_outputs;
522 }
523
524 CFGFUN(bar_verbose, const char *verbose) {
525     current_bar.verbose = eval_boolstr(verbose);
526 }
527
528 CFGFUN(bar_modifier, const char *modifier) {
529     if (strcmp(modifier, "Mod1") == 0)
530         current_bar.modifier = M_MOD1;
531     else if (strcmp(modifier, "Mod2") == 0)
532         current_bar.modifier = M_MOD2;
533     else if (strcmp(modifier, "Mod3") == 0)
534         current_bar.modifier = M_MOD3;
535     else if (strcmp(modifier, "Mod4") == 0)
536         current_bar.modifier = M_MOD4;
537     else if (strcmp(modifier, "Mod5") == 0)
538         current_bar.modifier = M_MOD5;
539     else if (strcmp(modifier, "Control") == 0 ||
540              strcmp(modifier, "Ctrl") == 0)
541         current_bar.modifier = M_CONTROL;
542     else if (strcmp(modifier, "Shift") == 0)
543         current_bar.modifier = M_SHIFT;
544 }
545
546 static void bar_configure_binding(const char *button, const char *command) {
547     if (strncasecmp(button, "button", strlen("button")) != 0) {
548         ELOG("Bindings for a bar can only be mouse bindings, not \"%s\", ignoring.\n", button);
549         return;
550     }
551
552     int input_code = atoi(button + strlen("button"));
553     if (input_code < 1) {
554         ELOG("Button \"%s\" does not seem to be in format 'buttonX'.\n", button);
555         return;
556     }
557
558     struct Barbinding *current;
559     TAILQ_FOREACH(current, &(current_bar.bar_bindings), bindings) {
560         if (current->input_code == input_code) {
561             ELOG("command for button %s was already specified, ignoring.\n", button);
562             return;
563         }
564     }
565
566     struct Barbinding *new_binding = scalloc(1, sizeof(struct Barbinding));
567     new_binding->input_code = input_code;
568     new_binding->command = sstrdup(command);
569     TAILQ_INSERT_TAIL(&(current_bar.bar_bindings), new_binding, bindings);
570 }
571
572 CFGFUN(bar_wheel_up_cmd, const char *command) {
573     ELOG("'wheel_up_cmd' is deprecated. Please us 'bindsym button4 %s' instead.\n", command);
574     bar_configure_binding("button4", command);
575 }
576
577 CFGFUN(bar_wheel_down_cmd, const char *command) {
578     ELOG("'wheel_down_cmd' is deprecated. Please us 'bindsym button5 %s' instead.\n", command);
579     bar_configure_binding("button5", command);
580 }
581
582 CFGFUN(bar_bindsym, const char *button, const char *command) {
583     bar_configure_binding(button, command);
584 }
585
586 CFGFUN(bar_position, const char *position) {
587     current_bar.position = (strcmp(position, "top") == 0 ? P_TOP : P_BOTTOM);
588 }
589
590 CFGFUN(bar_i3bar_command, const char *i3bar_command) {
591     FREE(current_bar.i3bar_command);
592     current_bar.i3bar_command = sstrdup(i3bar_command);
593 }
594
595 CFGFUN(bar_color, const char *colorclass, const char *border, const char *background, const char *text) {
596 #define APPLY_COLORS(classname)                                          \
597     do {                                                                 \
598         if (strcmp(colorclass, #classname) == 0) {                       \
599             if (text != NULL) {                                          \
600                 /* New syntax: border, background, text */               \
601                 current_bar.colors.classname##_border = sstrdup(border); \
602                 current_bar.colors.classname##_bg = sstrdup(background); \
603                 current_bar.colors.classname##_text = sstrdup(text);     \
604             } else {                                                     \
605                 /* Old syntax: text, background */                       \
606                 current_bar.colors.classname##_bg = sstrdup(background); \
607                 current_bar.colors.classname##_text = sstrdup(border);   \
608             }                                                            \
609         }                                                                \
610     } while (0)
611
612     APPLY_COLORS(focused_workspace);
613     APPLY_COLORS(active_workspace);
614     APPLY_COLORS(inactive_workspace);
615     APPLY_COLORS(urgent_workspace);
616     APPLY_COLORS(binding_mode);
617
618 #undef APPLY_COLORS
619 }
620
621 CFGFUN(bar_socket_path, const char *socket_path) {
622     FREE(current_bar.socket_path);
623     current_bar.socket_path = sstrdup(socket_path);
624 }
625
626 CFGFUN(bar_tray_output, const char *output) {
627     FREE(current_bar.tray_output);
628     current_bar.tray_output = sstrdup(output);
629 }
630
631 CFGFUN(bar_tray_padding, const long padding_px) {
632     current_bar.tray_padding = padding_px;
633 }
634
635 CFGFUN(bar_color_single, const char *colorclass, const char *color) {
636     if (strcmp(colorclass, "background") == 0)
637         current_bar.colors.background = sstrdup(color);
638     else if (strcmp(colorclass, "separator") == 0)
639         current_bar.colors.separator = sstrdup(color);
640     else
641         current_bar.colors.statusline = sstrdup(color);
642 }
643
644 CFGFUN(bar_status_command, const char *command) {
645     FREE(current_bar.status_command);
646     current_bar.status_command = sstrdup(command);
647 }
648
649 CFGFUN(bar_binding_mode_indicator, const char *value) {
650     current_bar.hide_binding_mode_indicator = !eval_boolstr(value);
651 }
652
653 CFGFUN(bar_workspace_buttons, const char *value) {
654     current_bar.hide_workspace_buttons = !eval_boolstr(value);
655 }
656
657 CFGFUN(bar_strip_workspace_numbers, const char *value) {
658     current_bar.strip_workspace_numbers = eval_boolstr(value);
659 }
660
661 CFGFUN(bar_start) {
662     TAILQ_INIT(&(current_bar.bar_bindings));
663     current_bar.tray_padding = 2;
664 }
665
666 CFGFUN(bar_finish) {
667     DLOG("\t new bar configuration finished, saving.\n");
668     /* Generate a unique ID for this bar if not already configured */
669     if (!current_bar.id)
670         sasprintf(&current_bar.id, "bar-%d", config.number_barconfigs);
671
672     config.number_barconfigs++;
673
674     /* If no font was explicitly set, we use the i3 font as default */
675     if (!current_bar.font && font_pattern)
676         current_bar.font = sstrdup(font_pattern);
677
678     /* Copy the current (static) structure into a dynamically allocated
679      * one, then cleanup our static one. */
680     Barconfig *bar_config = scalloc(1, sizeof(Barconfig));
681     memcpy(bar_config, &current_bar, sizeof(Barconfig));
682     TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
683
684     memset(&current_bar, '\0', sizeof(Barconfig));
685 }