2 #define I3__FILE__ "config_directives.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
9 * config_directives.c: all config storing functions (see config_parser.c)
17 /*******************************************************************************
19 ******************************************************************************/
21 static int criteria_next_state;
24 * Initializes the specified 'Match' data structure and the initial state of
25 * commands.c for matching target windows of a command.
28 CFGFUN(criteria_init, int _state) {
29 criteria_next_state = _state;
31 DLOG("Initializing criteria, current_match = %p, state = %d\n", current_match, _state);
32 match_free(current_match);
33 match_init(current_match);
36 CFGFUN(criteria_pop_state) {
37 result->next_state = criteria_next_state;
41 * Interprets a ctype=cvalue pair and adds it to the current match
45 CFGFUN(criteria_add, const char *ctype, const char *cvalue) {
46 match_parse_property(current_match, ctype, cvalue);
49 /*******************************************************************************
51 ******************************************************************************/
53 static bool eval_boolstr(const char *str) {
54 return (strcasecmp(str, "1") == 0 ||
55 strcasecmp(str, "yes") == 0 ||
56 strcasecmp(str, "true") == 0 ||
57 strcasecmp(str, "on") == 0 ||
58 strcasecmp(str, "enable") == 0 ||
59 strcasecmp(str, "active") == 0);
63 * A utility function to convert a string containing the group and modifiers to
64 * the corresponding bit mask.
66 i3_event_state_mask_t event_state_from_str(const char *str) {
67 /* It might be better to use strtok() here, but the simpler strstr() should
69 i3_event_state_mask_t result = 0;
72 if (strstr(str, "Mod1") != NULL)
73 result |= XCB_KEY_BUT_MASK_MOD_1;
74 if (strstr(str, "Mod2") != NULL)
75 result |= XCB_KEY_BUT_MASK_MOD_2;
76 if (strstr(str, "Mod3") != NULL)
77 result |= XCB_KEY_BUT_MASK_MOD_3;
78 if (strstr(str, "Mod4") != NULL)
79 result |= XCB_KEY_BUT_MASK_MOD_4;
80 if (strstr(str, "Mod5") != NULL)
81 result |= XCB_KEY_BUT_MASK_MOD_5;
82 if (strstr(str, "Control") != NULL ||
83 strstr(str, "Ctrl") != NULL)
84 result |= XCB_KEY_BUT_MASK_CONTROL;
85 if (strstr(str, "Shift") != NULL)
86 result |= XCB_KEY_BUT_MASK_SHIFT;
88 if (strstr(str, "Group1") != NULL)
89 result |= (I3_XKB_GROUP_MASK_1 << 16);
90 if (strstr(str, "Group2") != NULL ||
91 strstr(str, "Mode_switch") != NULL)
92 result |= (I3_XKB_GROUP_MASK_2 << 16);
93 if (strstr(str, "Group3") != NULL)
94 result |= (I3_XKB_GROUP_MASK_3 << 16);
95 if (strstr(str, "Group4") != NULL)
96 result |= (I3_XKB_GROUP_MASK_4 << 16);
100 static char *font_pattern;
102 CFGFUN(font, const char *font) {
103 config.font = load_font(font, true);
104 set_font(&config.font);
106 /* Save the font pattern for using it as bar font later on */
108 font_pattern = sstrdup(font);
111 CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
112 configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE, false);
115 /*******************************************************************************
117 ******************************************************************************/
119 static char *current_mode;
120 static bool current_mode_pango_markup;
122 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) {
123 configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode, current_mode_pango_markup);
126 CFGFUN(enter_mode, const char *pango_markup, const char *modename) {
127 if (strcasecmp(modename, DEFAULT_BINDING_MODE) == 0) {
128 ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE);
131 DLOG("\t now in mode %s\n", modename);
133 current_mode = sstrdup(modename);
134 current_mode_pango_markup = (pango_markup != NULL);
137 CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *command) {
138 struct Autostart *new = smalloc(sizeof(struct Autostart));
139 new->command = sstrdup(command);
140 new->no_startup_id = (no_startup_id != NULL);
141 if (strcmp(exectype, "exec") == 0) {
142 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
144 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
148 CFGFUN(for_window, const char *command) {
149 if (match_is_empty(current_match)) {
150 ELOG("Match is empty, ignoring this for_window statement\n");
153 DLOG("\t should execute command %s for the criteria mentioned above\n", command);
154 Assignment *assignment = scalloc(1, sizeof(Assignment));
155 assignment->type = A_COMMAND;
156 match_copy(&(assignment->match), current_match);
157 assignment->dest.command = sstrdup(command);
158 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
161 CFGFUN(floating_minimum_size, const long width, const long height) {
162 config.floating_minimum_width = width;
163 config.floating_minimum_height = height;
166 CFGFUN(floating_maximum_size, const long width, const long height) {
167 config.floating_maximum_width = width;
168 config.floating_maximum_height = height;
171 CFGFUN(floating_modifier, const char *modifiers) {
172 config.floating_modifier = event_state_from_str(modifiers);
175 CFGFUN(default_orientation, const char *orientation) {
176 if (strcmp(orientation, "horizontal") == 0)
177 config.default_orientation = HORIZ;
178 else if (strcmp(orientation, "vertical") == 0)
179 config.default_orientation = VERT;
181 config.default_orientation = NO_ORIENTATION;
184 CFGFUN(workspace_layout, const char *layout) {
185 if (strcmp(layout, "default") == 0)
186 config.default_layout = L_DEFAULT;
187 else if (strcmp(layout, "stacking") == 0 ||
188 strcmp(layout, "stacked") == 0)
189 config.default_layout = L_STACKED;
191 config.default_layout = L_TABBED;
194 CFGFUN(new_window, const char *windowtype, const char *border, const long width) {
198 if (strcmp(border, "1pixel") == 0) {
199 border_style = BS_PIXEL;
201 } else if (strcmp(border, "none") == 0) {
202 border_style = BS_NONE;
204 } else if (strcmp(border, "pixel") == 0) {
205 border_style = BS_PIXEL;
206 border_width = width;
208 border_style = BS_NORMAL;
209 border_width = width;
212 if (strcmp(windowtype, "new_window") == 0) {
213 DLOG("default tiled border style = %d and border width = %d (%d physical px)\n",
214 border_style, border_width, logical_px(border_width));
215 config.default_border = border_style;
216 config.default_border_width = logical_px(border_width);
218 DLOG("default floating border style = %d and border width = %d (%d physical px)\n",
219 border_style, border_width, logical_px(border_width));
220 config.default_floating_border = border_style;
221 config.default_floating_border_width = logical_px(border_width);
225 CFGFUN(hide_edge_borders, const char *borders) {
226 if (strcmp(borders, "smart") == 0)
227 config.hide_edge_borders = HEBM_SMART;
228 else if (strcmp(borders, "vertical") == 0)
229 config.hide_edge_borders = HEBM_VERTICAL;
230 else if (strcmp(borders, "horizontal") == 0)
231 config.hide_edge_borders = HEBM_HORIZONTAL;
232 else if (strcmp(borders, "both") == 0)
233 config.hide_edge_borders = HEBM_BOTH;
234 else if (strcmp(borders, "none") == 0)
235 config.hide_edge_borders = HEBM_NONE;
236 else if (eval_boolstr(borders))
237 config.hide_edge_borders = HEBM_VERTICAL;
239 config.hide_edge_borders = HEBM_NONE;
242 CFGFUN(focus_follows_mouse, const char *value) {
243 config.disable_focus_follows_mouse = !eval_boolstr(value);
246 CFGFUN(mouse_warping, const char *value) {
247 if (strcmp(value, "none") == 0)
248 config.mouse_warping = POINTER_WARPING_NONE;
249 else if (strcmp(value, "output") == 0)
250 config.mouse_warping = POINTER_WARPING_OUTPUT;
253 CFGFUN(force_xinerama, const char *value) {
254 config.force_xinerama = eval_boolstr(value);
257 CFGFUN(force_focus_wrapping, const char *value) {
258 config.force_focus_wrapping = eval_boolstr(value);
261 CFGFUN(workspace_back_and_forth, const char *value) {
262 config.workspace_auto_back_and_forth = eval_boolstr(value);
265 CFGFUN(fake_outputs, const char *outputs) {
266 free(config.fake_outputs);
267 config.fake_outputs = sstrdup(outputs);
270 CFGFUN(force_display_urgency_hint, const long duration_ms) {
271 config.workspace_urgency_timer = duration_ms / 1000.0;
274 CFGFUN(focus_on_window_activation, const char *mode) {
275 if (strcmp(mode, "smart") == 0)
276 config.focus_on_window_activation = FOWA_SMART;
277 else if (strcmp(mode, "urgent") == 0)
278 config.focus_on_window_activation = FOWA_URGENT;
279 else if (strcmp(mode, "focus") == 0)
280 config.focus_on_window_activation = FOWA_FOCUS;
281 else if (strcmp(mode, "none") == 0)
282 config.focus_on_window_activation = FOWA_NONE;
284 ELOG("Unknown focus_on_window_activation mode \"%s\", ignoring it.\n", mode);
288 DLOG("Set new focus_on_window_activation mode = %i.\n", config.focus_on_window_activation);
291 CFGFUN(show_marks, const char *value) {
292 config.show_marks = eval_boolstr(value);
295 CFGFUN(workspace, const char *workspace, const char *output) {
296 DLOG("Assigning workspace \"%s\" to output \"%s\"\n", workspace, output);
297 /* Check for earlier assignments of the same workspace so that we
298 * don’t have assignments of a single workspace to different
300 struct Workspace_Assignment *assignment;
301 bool duplicate = false;
302 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
303 if (strcasecmp(assignment->name, workspace) == 0) {
304 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
306 assignment->output = sstrdup(output);
311 assignment = scalloc(1, sizeof(struct Workspace_Assignment));
312 assignment->name = sstrdup(workspace);
313 assignment->output = sstrdup(output);
314 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
318 CFGFUN(ipc_socket, const char *path) {
319 free(config.ipc_socket_path);
320 config.ipc_socket_path = sstrdup(path);
323 CFGFUN(restart_state, const char *path) {
324 free(config.restart_state_path);
325 config.restart_state_path = sstrdup(path);
328 CFGFUN(popup_during_fullscreen, const char *value) {
329 if (strcmp(value, "ignore") == 0) {
330 config.popup_during_fullscreen = PDF_IGNORE;
331 } else if (strcmp(value, "leave_fullscreen") == 0) {
332 config.popup_during_fullscreen = PDF_LEAVE_FULLSCREEN;
334 config.popup_during_fullscreen = PDF_SMART;
338 CFGFUN(color_single, const char *colorclass, const char *color) {
339 /* used for client.background only currently */
340 config.client.background = draw_util_hex_to_color(color);
343 CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator, const char *child_border) {
344 #define APPLY_COLORS(classname) \
346 if (strcmp(colorclass, "client." #classname) == 0) { \
347 config.client.classname.border = draw_util_hex_to_color(border); \
348 config.client.classname.background = draw_util_hex_to_color(background); \
349 config.client.classname.text = draw_util_hex_to_color(text); \
350 if (indicator != NULL) { \
351 config.client.classname.indicator = draw_util_hex_to_color(indicator); \
353 if (child_border != NULL) { \
354 config.client.classname.child_border = draw_util_hex_to_color(child_border); \
356 config.client.classname.child_border = config.client.classname.background; \
361 APPLY_COLORS(focused_inactive);
362 APPLY_COLORS(focused);
363 APPLY_COLORS(unfocused);
364 APPLY_COLORS(urgent);
365 APPLY_COLORS(placeholder);
370 CFGFUN(assign, const char *workspace) {
371 if (match_is_empty(current_match)) {
372 ELOG("Match is empty, ignoring this assignment\n");
375 DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace);
376 Assignment *assignment = scalloc(1, sizeof(Assignment));
377 match_copy(&(assignment->match), current_match);
378 assignment->type = A_TO_WORKSPACE;
379 assignment->dest.workspace = sstrdup(workspace);
380 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
384 if (match_is_empty(current_match)) {
385 ELOG("Match is empty, ignoring this assignment\n");
389 DLOG("New assignment, using above criteria, to ignore focus on manage.\n");
390 Assignment *assignment = scalloc(1, sizeof(Assignment));
391 match_copy(&(assignment->match), current_match);
392 assignment->type = A_NO_FOCUS;
393 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
396 /*******************************************************************************
397 * Bar configuration (i3bar)
398 ******************************************************************************/
400 static Barconfig *current_bar;
402 CFGFUN(bar_font, const char *font) {
403 FREE(current_bar->font);
404 current_bar->font = sstrdup(font);
407 CFGFUN(bar_separator_symbol, const char *separator) {
408 FREE(current_bar->separator_symbol);
409 current_bar->separator_symbol = sstrdup(separator);
412 CFGFUN(bar_mode, const char *mode) {
413 current_bar->mode = (strcmp(mode, "dock") == 0 ? M_DOCK : (strcmp(mode, "hide") == 0 ? M_HIDE : M_INVISIBLE));
416 CFGFUN(bar_hidden_state, const char *hidden_state) {
417 current_bar->hidden_state = (strcmp(hidden_state, "hide") == 0 ? S_HIDE : S_SHOW);
420 CFGFUN(bar_id, const char *bar_id) {
421 current_bar->id = sstrdup(bar_id);
424 CFGFUN(bar_output, const char *output) {
425 int new_outputs = current_bar->num_outputs + 1;
426 current_bar->outputs = srealloc(current_bar->outputs, sizeof(char *) * new_outputs);
427 current_bar->outputs[current_bar->num_outputs] = sstrdup(output);
428 current_bar->num_outputs = new_outputs;
431 CFGFUN(bar_verbose, const char *verbose) {
432 current_bar->verbose = eval_boolstr(verbose);
435 CFGFUN(bar_modifier, const char *modifier) {
436 if (strcmp(modifier, "Mod1") == 0)
437 current_bar->modifier = M_MOD1;
438 else if (strcmp(modifier, "Mod2") == 0)
439 current_bar->modifier = M_MOD2;
440 else if (strcmp(modifier, "Mod3") == 0)
441 current_bar->modifier = M_MOD3;
442 else if (strcmp(modifier, "Mod4") == 0)
443 current_bar->modifier = M_MOD4;
444 else if (strcmp(modifier, "Mod5") == 0)
445 current_bar->modifier = M_MOD5;
446 else if (strcmp(modifier, "Control") == 0 ||
447 strcmp(modifier, "Ctrl") == 0)
448 current_bar->modifier = M_CONTROL;
449 else if (strcmp(modifier, "Shift") == 0)
450 current_bar->modifier = M_SHIFT;
451 else if (strcmp(modifier, "none") == 0 ||
452 strcmp(modifier, "off") == 0)
453 current_bar->modifier = M_NONE;
456 static void bar_configure_binding(const char *button, const char *command) {
457 if (strncasecmp(button, "button", strlen("button")) != 0) {
458 ELOG("Bindings for a bar can only be mouse bindings, not \"%s\", ignoring.\n", button);
462 int input_code = atoi(button + strlen("button"));
463 if (input_code < 1) {
464 ELOG("Button \"%s\" does not seem to be in format 'buttonX'.\n", button);
468 struct Barbinding *current;
469 TAILQ_FOREACH(current, &(current_bar->bar_bindings), bindings) {
470 if (current->input_code == input_code) {
471 ELOG("command for button %s was already specified, ignoring.\n", button);
476 struct Barbinding *new_binding = scalloc(1, sizeof(struct Barbinding));
477 new_binding->input_code = input_code;
478 new_binding->command = sstrdup(command);
479 TAILQ_INSERT_TAIL(&(current_bar->bar_bindings), new_binding, bindings);
482 CFGFUN(bar_wheel_up_cmd, const char *command) {
483 ELOG("'wheel_up_cmd' is deprecated. Please us 'bindsym button4 %s' instead.\n", command);
484 bar_configure_binding("button4", command);
487 CFGFUN(bar_wheel_down_cmd, const char *command) {
488 ELOG("'wheel_down_cmd' is deprecated. Please us 'bindsym button5 %s' instead.\n", command);
489 bar_configure_binding("button5", command);
492 CFGFUN(bar_bindsym, const char *button, const char *command) {
493 bar_configure_binding(button, command);
496 CFGFUN(bar_position, const char *position) {
497 current_bar->position = (strcmp(position, "top") == 0 ? P_TOP : P_BOTTOM);
500 CFGFUN(bar_i3bar_command, const char *i3bar_command) {
501 FREE(current_bar->i3bar_command);
502 current_bar->i3bar_command = sstrdup(i3bar_command);
505 CFGFUN(bar_color, const char *colorclass, const char *border, const char *background, const char *text) {
506 #define APPLY_COLORS(classname) \
508 if (strcmp(colorclass, #classname) == 0) { \
509 if (text != NULL) { \
510 /* New syntax: border, background, text */ \
511 current_bar->colors.classname##_border = sstrdup(border); \
512 current_bar->colors.classname##_bg = sstrdup(background); \
513 current_bar->colors.classname##_text = sstrdup(text); \
515 /* Old syntax: text, background */ \
516 current_bar->colors.classname##_bg = sstrdup(background); \
517 current_bar->colors.classname##_text = sstrdup(border); \
522 APPLY_COLORS(focused_workspace);
523 APPLY_COLORS(active_workspace);
524 APPLY_COLORS(inactive_workspace);
525 APPLY_COLORS(urgent_workspace);
526 APPLY_COLORS(binding_mode);
531 CFGFUN(bar_socket_path, const char *socket_path) {
532 FREE(current_bar->socket_path);
533 current_bar->socket_path = sstrdup(socket_path);
536 CFGFUN(bar_tray_output, const char *output) {
537 struct tray_output_t *tray_output = scalloc(1, sizeof(struct tray_output_t));
538 tray_output->output = sstrdup(output);
539 TAILQ_INSERT_TAIL(&(current_bar->tray_outputs), tray_output, tray_outputs);
542 CFGFUN(bar_tray_padding, const long padding_px) {
543 current_bar->tray_padding = padding_px;
546 CFGFUN(bar_color_single, const char *colorclass, const char *color) {
547 if (strcmp(colorclass, "background") == 0)
548 current_bar->colors.background = sstrdup(color);
549 else if (strcmp(colorclass, "separator") == 0)
550 current_bar->colors.separator = sstrdup(color);
551 else if (strcmp(colorclass, "statusline") == 0)
552 current_bar->colors.statusline = sstrdup(color);
553 else if (strcmp(colorclass, "focused_background") == 0)
554 current_bar->colors.focused_background = sstrdup(color);
555 else if (strcmp(colorclass, "focused_separator") == 0)
556 current_bar->colors.focused_separator = sstrdup(color);
558 current_bar->colors.focused_statusline = sstrdup(color);
561 CFGFUN(bar_status_command, const char *command) {
562 FREE(current_bar->status_command);
563 current_bar->status_command = sstrdup(command);
566 CFGFUN(bar_binding_mode_indicator, const char *value) {
567 current_bar->hide_binding_mode_indicator = !eval_boolstr(value);
570 CFGFUN(bar_workspace_buttons, const char *value) {
571 current_bar->hide_workspace_buttons = !eval_boolstr(value);
574 CFGFUN(bar_strip_workspace_numbers, const char *value) {
575 current_bar->strip_workspace_numbers = eval_boolstr(value);
579 current_bar = scalloc(1, sizeof(struct Barconfig));
580 TAILQ_INIT(&(current_bar->bar_bindings));
581 TAILQ_INIT(&(current_bar->tray_outputs));
582 current_bar->tray_padding = 2;
583 current_bar->modifier = M_MOD4;
587 DLOG("\t new bar configuration finished, saving.\n");
588 /* Generate a unique ID for this bar if not already configured */
589 if (current_bar->id == NULL)
590 sasprintf(¤t_bar->id, "bar-%d", config.number_barconfigs);
592 config.number_barconfigs++;
594 /* If no font was explicitly set, we use the i3 font as default */
595 if (current_bar->font == NULL && font_pattern != NULL)
596 current_bar->font = sstrdup(font_pattern);
598 TAILQ_INSERT_TAIL(&barconfigs, current_bar, configs);
599 /* Simply reset the pointer, but don't free the resources. */