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_init(current_match);
35 CFGFUN(criteria_pop_state) {
36 result->next_state = criteria_next_state;
40 * Interprets a ctype=cvalue pair and adds it to the current match
44 CFGFUN(criteria_add, const char *ctype, const char *cvalue) {
45 match_parse_property(current_match, ctype, cvalue);
48 /*******************************************************************************
50 ******************************************************************************/
52 static bool eval_boolstr(const char *str) {
53 return (strcasecmp(str, "1") == 0 ||
54 strcasecmp(str, "yes") == 0 ||
55 strcasecmp(str, "true") == 0 ||
56 strcasecmp(str, "on") == 0 ||
57 strcasecmp(str, "enable") == 0 ||
58 strcasecmp(str, "active") == 0);
62 * A utility function to convert a string containing the group and modifiers to
63 * the corresponding bit mask.
65 i3_event_state_mask_t event_state_from_str(const char *str) {
66 /* It might be better to use strtok() here, but the simpler strstr() should
68 i3_event_state_mask_t result = 0;
71 if (strstr(str, "Mod1") != NULL)
72 result |= XCB_KEY_BUT_MASK_MOD_1;
73 if (strstr(str, "Mod2") != NULL)
74 result |= XCB_KEY_BUT_MASK_MOD_2;
75 if (strstr(str, "Mod3") != NULL)
76 result |= XCB_KEY_BUT_MASK_MOD_3;
77 if (strstr(str, "Mod4") != NULL)
78 result |= XCB_KEY_BUT_MASK_MOD_4;
79 if (strstr(str, "Mod5") != NULL)
80 result |= XCB_KEY_BUT_MASK_MOD_5;
81 if (strstr(str, "Control") != NULL ||
82 strstr(str, "Ctrl") != NULL)
83 result |= XCB_KEY_BUT_MASK_CONTROL;
84 if (strstr(str, "Shift") != NULL)
85 result |= XCB_KEY_BUT_MASK_SHIFT;
87 if (strstr(str, "Group1") != NULL)
88 result |= (I3_XKB_GROUP_MASK_1 << 16);
89 if (strstr(str, "Group2") != NULL ||
90 strstr(str, "Mode_switch") != NULL)
91 result |= (I3_XKB_GROUP_MASK_2 << 16);
92 if (strstr(str, "Group3") != NULL)
93 result |= (I3_XKB_GROUP_MASK_3 << 16);
94 if (strstr(str, "Group4") != NULL)
95 result |= (I3_XKB_GROUP_MASK_4 << 16);
99 static char *font_pattern;
101 CFGFUN(font, const char *font) {
102 config.font = load_font(font, true);
103 set_font(&config.font);
105 /* Save the font pattern for using it as bar font later on */
107 font_pattern = sstrdup(font);
110 CFGFUN(binding, const char *bindtype, const char *modifiers, const char *key, const char *release, const char *border, const char *whole_window, const char *command) {
111 configure_binding(bindtype, modifiers, key, release, border, whole_window, command, DEFAULT_BINDING_MODE);
114 /*******************************************************************************
116 ******************************************************************************/
118 static char *current_mode;
120 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) {
121 configure_binding(bindtype, modifiers, key, release, border, whole_window, command, current_mode);
124 CFGFUN(enter_mode, const char *modename) {
125 if (strcasecmp(modename, DEFAULT_BINDING_MODE) == 0) {
126 ELOG("You cannot use the name %s for your mode\n", DEFAULT_BINDING_MODE);
129 DLOG("\t now in mode %s\n", modename);
131 current_mode = sstrdup(modename);
134 CFGFUN(exec, const char *exectype, const char *no_startup_id, const char *command) {
135 struct Autostart *new = smalloc(sizeof(struct Autostart));
136 new->command = sstrdup(command);
137 new->no_startup_id = (no_startup_id != NULL);
138 if (strcmp(exectype, "exec") == 0) {
139 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
141 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
145 CFGFUN(for_window, const char *command) {
146 if (match_is_empty(current_match)) {
147 ELOG("Match is empty, ignoring this for_window statement\n");
150 DLOG("\t should execute command %s for the criteria mentioned above\n", command);
151 Assignment *assignment = scalloc(1, sizeof(Assignment));
152 assignment->type = A_COMMAND;
153 match_copy(&(assignment->match), current_match);
154 assignment->dest.command = sstrdup(command);
155 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
158 CFGFUN(floating_minimum_size, const long width, const long height) {
159 config.floating_minimum_width = width;
160 config.floating_minimum_height = height;
163 CFGFUN(floating_maximum_size, const long width, const long height) {
164 config.floating_maximum_width = width;
165 config.floating_maximum_height = height;
168 CFGFUN(floating_modifier, const char *modifiers) {
169 config.floating_modifier = event_state_from_str(modifiers);
172 CFGFUN(default_orientation, const char *orientation) {
173 if (strcmp(orientation, "horizontal") == 0)
174 config.default_orientation = HORIZ;
175 else if (strcmp(orientation, "vertical") == 0)
176 config.default_orientation = VERT;
178 config.default_orientation = NO_ORIENTATION;
181 CFGFUN(workspace_layout, const char *layout) {
182 if (strcmp(layout, "default") == 0)
183 config.default_layout = L_DEFAULT;
184 else if (strcmp(layout, "stacking") == 0 ||
185 strcmp(layout, "stacked") == 0)
186 config.default_layout = L_STACKED;
188 config.default_layout = L_TABBED;
191 CFGFUN(new_window, const char *windowtype, const char *border, const long width) {
195 if (strcmp(border, "1pixel") == 0) {
196 border_style = BS_PIXEL;
198 } else if (strcmp(border, "none") == 0) {
199 border_style = BS_NONE;
201 } else if (strcmp(border, "pixel") == 0) {
202 border_style = BS_PIXEL;
203 border_width = width;
205 border_style = BS_NORMAL;
206 border_width = width;
209 if (strcmp(windowtype, "new_window") == 0) {
210 DLOG("default tiled border style = %d and border width = %d (%d physical px)\n",
211 border_style, border_width, logical_px(border_width));
212 config.default_border = border_style;
213 config.default_border_width = logical_px(border_width);
215 DLOG("default floating border style = %d and border width = %d (%d physical px)\n",
216 border_style, border_width, logical_px(border_width));
217 config.default_floating_border = border_style;
218 config.default_floating_border_width = logical_px(border_width);
222 CFGFUN(hide_edge_borders, const char *borders) {
223 if (strcmp(borders, "vertical") == 0)
224 config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
225 else if (strcmp(borders, "horizontal") == 0)
226 config.hide_edge_borders = ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
227 else if (strcmp(borders, "both") == 0)
228 config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE | ADJ_UPPER_SCREEN_EDGE | ADJ_LOWER_SCREEN_EDGE;
229 else if (strcmp(borders, "none") == 0)
230 config.hide_edge_borders = ADJ_NONE;
231 else if (eval_boolstr(borders))
232 config.hide_edge_borders = ADJ_LEFT_SCREEN_EDGE | ADJ_RIGHT_SCREEN_EDGE;
234 config.hide_edge_borders = ADJ_NONE;
237 CFGFUN(focus_follows_mouse, const char *value) {
238 config.disable_focus_follows_mouse = !eval_boolstr(value);
241 CFGFUN(mouse_warping, const char *value) {
242 if (strcmp(value, "none") == 0)
243 config.mouse_warping = POINTER_WARPING_NONE;
244 else if (strcmp(value, "output") == 0)
245 config.mouse_warping = POINTER_WARPING_OUTPUT;
248 CFGFUN(force_xinerama, const char *value) {
249 config.force_xinerama = eval_boolstr(value);
252 CFGFUN(force_focus_wrapping, const char *value) {
253 config.force_focus_wrapping = eval_boolstr(value);
256 CFGFUN(workspace_back_and_forth, const char *value) {
257 config.workspace_auto_back_and_forth = eval_boolstr(value);
260 CFGFUN(fake_outputs, const char *outputs) {
261 config.fake_outputs = sstrdup(outputs);
264 CFGFUN(force_display_urgency_hint, const long duration_ms) {
265 config.workspace_urgency_timer = duration_ms / 1000.0;
268 CFGFUN(focus_on_window_activation, const char *mode) {
269 if (strcmp(mode, "smart") == 0)
270 config.focus_on_window_activation = FOWA_SMART;
271 else if (strcmp(mode, "urgent") == 0)
272 config.focus_on_window_activation = FOWA_URGENT;
273 else if (strcmp(mode, "focus") == 0)
274 config.focus_on_window_activation = FOWA_FOCUS;
275 else if (strcmp(mode, "none") == 0)
276 config.focus_on_window_activation = FOWA_NONE;
278 ELOG("Unknown focus_on_window_activation mode \"%s\", ignoring it.\n", mode);
282 DLOG("Set new focus_on_window_activation mode = %i.\n", config.focus_on_window_activation);
285 CFGFUN(show_marks, const char *value) {
286 config.show_marks = eval_boolstr(value);
289 CFGFUN(workspace, const char *workspace, const char *output) {
290 DLOG("Assigning workspace \"%s\" to output \"%s\"\n", workspace, output);
291 /* Check for earlier assignments of the same workspace so that we
292 * don’t have assignments of a single workspace to different
294 struct Workspace_Assignment *assignment;
295 bool duplicate = false;
296 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
297 if (strcasecmp(assignment->name, workspace) == 0) {
298 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
300 assignment->output = sstrdup(output);
305 assignment = scalloc(1, sizeof(struct Workspace_Assignment));
306 assignment->name = sstrdup(workspace);
307 assignment->output = sstrdup(output);
308 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
312 CFGFUN(ipc_socket, const char *path) {
313 config.ipc_socket_path = sstrdup(path);
316 CFGFUN(restart_state, const char *path) {
317 config.restart_state_path = sstrdup(path);
320 CFGFUN(popup_during_fullscreen, const char *value) {
321 if (strcmp(value, "ignore") == 0) {
322 config.popup_during_fullscreen = PDF_IGNORE;
323 } else if (strcmp(value, "leave_fullscreen") == 0) {
324 config.popup_during_fullscreen = PDF_LEAVE_FULLSCREEN;
326 config.popup_during_fullscreen = PDF_SMART;
330 CFGFUN(color_single, const char *colorclass, const char *color) {
331 /* used for client.background only currently */
332 config.client.background = get_colorpixel(color);
335 CFGFUN(color, const char *colorclass, const char *border, const char *background, const char *text, const char *indicator) {
336 #define APPLY_COLORS(classname) \
338 if (strcmp(colorclass, "client." #classname) == 0) { \
339 config.client.classname.border = get_colorpixel(border); \
340 config.client.classname.background = get_colorpixel(background); \
341 config.client.classname.text = get_colorpixel(text); \
342 if (indicator != NULL) { \
343 config.client.classname.indicator = get_colorpixel(indicator); \
348 APPLY_COLORS(focused_inactive);
349 APPLY_COLORS(focused);
350 APPLY_COLORS(unfocused);
351 APPLY_COLORS(urgent);
352 APPLY_COLORS(placeholder);
357 CFGFUN(assign, const char *workspace) {
358 if (match_is_empty(current_match)) {
359 ELOG("Match is empty, ignoring this assignment\n");
362 DLOG("New assignment, using above criteria, to workspace \"%s\".\n", workspace);
363 Assignment *assignment = scalloc(1, sizeof(Assignment));
364 match_copy(&(assignment->match), current_match);
365 assignment->type = A_TO_WORKSPACE;
366 assignment->dest.workspace = sstrdup(workspace);
367 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
371 if (match_is_empty(current_match)) {
372 ELOG("Match is empty, ignoring this assignment\n");
376 DLOG("New assignment, using above criteria, to ignore focus on manage.\n");
377 Assignment *assignment = scalloc(1, sizeof(Assignment));
378 match_copy(&(assignment->match), current_match);
379 assignment->type = A_NO_FOCUS;
380 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
383 /*******************************************************************************
384 * Bar configuration (i3bar)
385 ******************************************************************************/
387 static Barconfig current_bar;
389 CFGFUN(bar_font, const char *font) {
390 FREE(current_bar.font);
391 current_bar.font = sstrdup(font);
394 CFGFUN(bar_separator_symbol, const char *separator) {
395 FREE(current_bar.separator_symbol);
396 current_bar.separator_symbol = sstrdup(separator);
399 CFGFUN(bar_mode, const char *mode) {
400 current_bar.mode = (strcmp(mode, "dock") == 0 ? M_DOCK : (strcmp(mode, "hide") == 0 ? M_HIDE : M_INVISIBLE));
403 CFGFUN(bar_hidden_state, const char *hidden_state) {
404 current_bar.hidden_state = (strcmp(hidden_state, "hide") == 0 ? S_HIDE : S_SHOW);
407 CFGFUN(bar_id, const char *bar_id) {
408 current_bar.id = sstrdup(bar_id);
411 CFGFUN(bar_output, const char *output) {
412 int new_outputs = current_bar.num_outputs + 1;
413 current_bar.outputs = srealloc(current_bar.outputs, sizeof(char *) * new_outputs);
414 current_bar.outputs[current_bar.num_outputs] = sstrdup(output);
415 current_bar.num_outputs = new_outputs;
418 CFGFUN(bar_verbose, const char *verbose) {
419 current_bar.verbose = eval_boolstr(verbose);
422 CFGFUN(bar_modifier, const char *modifier) {
423 if (strcmp(modifier, "Mod1") == 0)
424 current_bar.modifier = M_MOD1;
425 else if (strcmp(modifier, "Mod2") == 0)
426 current_bar.modifier = M_MOD2;
427 else if (strcmp(modifier, "Mod3") == 0)
428 current_bar.modifier = M_MOD3;
429 else if (strcmp(modifier, "Mod4") == 0)
430 current_bar.modifier = M_MOD4;
431 else if (strcmp(modifier, "Mod5") == 0)
432 current_bar.modifier = M_MOD5;
433 else if (strcmp(modifier, "Control") == 0 ||
434 strcmp(modifier, "Ctrl") == 0)
435 current_bar.modifier = M_CONTROL;
436 else if (strcmp(modifier, "Shift") == 0)
437 current_bar.modifier = M_SHIFT;
440 static void bar_configure_binding(const char *button, const char *command) {
441 if (strncasecmp(button, "button", strlen("button")) != 0) {
442 ELOG("Bindings for a bar can only be mouse bindings, not \"%s\", ignoring.\n", button);
446 int input_code = atoi(button + strlen("button"));
447 if (input_code < 1) {
448 ELOG("Button \"%s\" does not seem to be in format 'buttonX'.\n", button);
452 struct Barbinding *current;
453 TAILQ_FOREACH(current, &(current_bar.bar_bindings), bindings) {
454 if (current->input_code == input_code) {
455 ELOG("command for button %s was already specified, ignoring.\n", button);
460 struct Barbinding *new_binding = scalloc(1, sizeof(struct Barbinding));
461 new_binding->input_code = input_code;
462 new_binding->command = sstrdup(command);
463 TAILQ_INSERT_TAIL(&(current_bar.bar_bindings), new_binding, bindings);
466 CFGFUN(bar_wheel_up_cmd, const char *command) {
467 ELOG("'wheel_up_cmd' is deprecated. Please us 'bindsym button4 %s' instead.\n", command);
468 bar_configure_binding("button4", command);
471 CFGFUN(bar_wheel_down_cmd, const char *command) {
472 ELOG("'wheel_down_cmd' is deprecated. Please us 'bindsym button5 %s' instead.\n", command);
473 bar_configure_binding("button5", command);
476 CFGFUN(bar_bindsym, const char *button, const char *command) {
477 bar_configure_binding(button, command);
480 CFGFUN(bar_position, const char *position) {
481 current_bar.position = (strcmp(position, "top") == 0 ? P_TOP : P_BOTTOM);
484 CFGFUN(bar_i3bar_command, const char *i3bar_command) {
485 FREE(current_bar.i3bar_command);
486 current_bar.i3bar_command = sstrdup(i3bar_command);
489 CFGFUN(bar_color, const char *colorclass, const char *border, const char *background, const char *text) {
490 #define APPLY_COLORS(classname) \
492 if (strcmp(colorclass, #classname) == 0) { \
493 if (text != NULL) { \
494 /* New syntax: border, background, text */ \
495 current_bar.colors.classname##_border = sstrdup(border); \
496 current_bar.colors.classname##_bg = sstrdup(background); \
497 current_bar.colors.classname##_text = sstrdup(text); \
499 /* Old syntax: text, background */ \
500 current_bar.colors.classname##_bg = sstrdup(background); \
501 current_bar.colors.classname##_text = sstrdup(border); \
506 APPLY_COLORS(focused_workspace);
507 APPLY_COLORS(active_workspace);
508 APPLY_COLORS(inactive_workspace);
509 APPLY_COLORS(urgent_workspace);
510 APPLY_COLORS(binding_mode);
515 CFGFUN(bar_socket_path, const char *socket_path) {
516 FREE(current_bar.socket_path);
517 current_bar.socket_path = sstrdup(socket_path);
520 CFGFUN(bar_tray_output, const char *output) {
521 FREE(current_bar.tray_output);
522 current_bar.tray_output = sstrdup(output);
525 CFGFUN(bar_tray_padding, const long padding_px) {
526 current_bar.tray_padding = padding_px;
529 CFGFUN(bar_color_single, const char *colorclass, const char *color) {
530 if (strcmp(colorclass, "background") == 0)
531 current_bar.colors.background = sstrdup(color);
532 else if (strcmp(colorclass, "separator") == 0)
533 current_bar.colors.separator = sstrdup(color);
535 current_bar.colors.statusline = sstrdup(color);
538 CFGFUN(bar_status_command, const char *command) {
539 FREE(current_bar.status_command);
540 current_bar.status_command = sstrdup(command);
543 CFGFUN(bar_binding_mode_indicator, const char *value) {
544 current_bar.hide_binding_mode_indicator = !eval_boolstr(value);
547 CFGFUN(bar_workspace_buttons, const char *value) {
548 current_bar.hide_workspace_buttons = !eval_boolstr(value);
551 CFGFUN(bar_strip_workspace_numbers, const char *value) {
552 current_bar.strip_workspace_numbers = eval_boolstr(value);
556 TAILQ_INIT(&(current_bar.bar_bindings));
557 current_bar.tray_padding = 2;
561 DLOG("\t new bar configuration finished, saving.\n");
562 /* Generate a unique ID for this bar if not already configured */
564 sasprintf(¤t_bar.id, "bar-%d", config.number_barconfigs);
566 config.number_barconfigs++;
568 /* If no font was explicitly set, we use the i3 font as default */
569 if (!current_bar.font && font_pattern)
570 current_bar.font = sstrdup(font_pattern);
572 /* Copy the current (static) structure into a dynamically allocated
573 * one, then cleanup our static one. */
574 Barconfig *bar_config = scalloc(1, sizeof(Barconfig));
575 memcpy(bar_config, ¤t_bar, sizeof(Barconfig));
576 TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
578 memset(¤t_bar, '\0', sizeof(Barconfig));