3 * vim:ts=4:sw=4:expandtab
14 static pid_t configerror_pid = -1;
16 static Match current_match;
17 static Barconfig current_bar;
19 typedef struct yy_buffer_state *YY_BUFFER_STATE;
20 extern int yylex(struct context *context);
21 extern int yyparse(void);
22 extern int yylex_destroy(void);
24 YY_BUFFER_STATE yy_scan_string(const char *);
26 static struct bindings_head *current_bindings;
27 static struct context *context;
29 /* We don’t need yydebug for now, as we got decent error messages using
30 * yyerror(). Should you ever want to extend the parser, it might be handy
31 * to just comment it in again, so it stays here. */
34 void yyerror(const char *error_message) {
35 context->has_errors = true;
38 ELOG("CONFIG: %s\n", error_message);
39 ELOG("CONFIG: in file \"%s\", line %d:\n",
40 context->filename, context->line_number);
41 ELOG("CONFIG: %s\n", context->line_copy);
42 char buffer[context->last_column+1];
43 buffer[context->last_column] = '\0';
44 for (int c = 1; c <= context->last_column; c++)
45 buffer[c-1] = (c >= context->first_column ? '^' : ' ');
46 ELOG("CONFIG: %s\n", buffer);
55 * Goes through each line of buf (separated by \n) and checks for statements /
56 * commands which only occur in i3 v4 configuration files. If it finds any, it
57 * returns version 4, otherwise it returns version 3.
60 static int detect_version(char *buf) {
63 while (*walk != '\0') {
69 /* check for some v4-only statements */
70 if (strncasecmp(line, "bindcode", strlen("bindcode")) == 0 ||
71 strncasecmp(line, "force_focus_wrapping", strlen("force_focus_wrapping")) == 0 ||
72 strncasecmp(line, "# i3 config file (v4)", strlen("# i3 config file (v4)")) == 0 ||
73 strncasecmp(line, "workspace_layout", strlen("workspace_layout")) == 0) {
74 printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
78 /* if this is a bind statement, we can check the command */
79 if (strncasecmp(line, "bind", strlen("bind")) == 0) {
80 char *bind = strchr(line, ' ');
83 while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
87 if ((bind = strchr(bind, ' ')) == NULL)
89 while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
93 if (strncasecmp(bind, "layout", strlen("layout")) == 0 ||
94 strncasecmp(bind, "floating", strlen("floating")) == 0 ||
95 strncasecmp(bind, "workspace", strlen("workspace")) == 0 ||
96 strncasecmp(bind, "focus left", strlen("focus left")) == 0 ||
97 strncasecmp(bind, "focus right", strlen("focus right")) == 0 ||
98 strncasecmp(bind, "focus up", strlen("focus up")) == 0 ||
99 strncasecmp(bind, "focus down", strlen("focus down")) == 0 ||
100 strncasecmp(bind, "border normal", strlen("border normal")) == 0 ||
101 strncasecmp(bind, "border 1pixel", strlen("border 1pixel")) == 0 ||
102 strncasecmp(bind, "border borderless", strlen("border borderless")) == 0) {
103 printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
109 /* advance to the next line */
118 * Calls i3-migrate-config-to-v4 to migrate a configuration file (input
121 * Returns the converted config file or NULL if there was an error (for
122 * example the script could not be found in $PATH or the i3 executable’s
126 static char *migrate_config(char *input, off_t size) {
130 if (pipe(writepipe) != 0 ||
131 pipe(readpipe) != 0) {
132 warn("migrate_config: Could not create pipes");
138 warn("Could not fork()");
144 /* close writing end of writepipe, connect reading side to stdin */
146 dup2(writepipe[0], 0);
148 /* close reading end of readpipe, connect writing side to stdout */
150 dup2(readpipe[1], 1);
152 static char *argv[] = {
153 NULL, /* will be replaced by the executable path */
156 exec_i3_utility("i3-migrate-config-to-v4", argv);
161 /* close reading end of the writepipe (connected to the script’s stdin) */
164 /* write the whole config file to the pipe, the script will read everything
168 while (written < size) {
169 if ((ret = write(writepipe[1], input + written, size - written)) < 0) {
170 warn("Could not write to pipe");
177 /* close writing end of the readpipe (connected to the script’s stdout) */
180 /* read the script’s output */
181 int conv_size = 65535;
182 char *converted = malloc(conv_size);
185 if (read_bytes == conv_size) {
187 converted = realloc(converted, conv_size);
189 ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
191 warn("Cannot read from pipe");
198 /* get the returncode */
201 if (!WIFEXITED(status)) {
202 fprintf(stderr, "Child did not terminate normally, using old config file (will lead to broken behaviour)\n");
206 int returncode = WEXITSTATUS(status);
207 if (returncode != 0) {
208 fprintf(stderr, "Migration process exit code was != 0\n");
209 if (returncode == 2) {
210 fprintf(stderr, "could not start the migration script\n");
211 /* TODO: script was not found. tell the user to fix his system or create a v4 config */
212 } else if (returncode == 1) {
213 fprintf(stderr, "This already was a v4 config. Please add the following line to your config file:\n");
214 fprintf(stderr, "# i3 config file (v4)\n");
215 /* TODO: nag the user with a message to include a hint for i3 in his config file */
224 * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
225 * it exited (or could not be started, depending on the exit code).
228 static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
229 ev_child_stop(EV_A_ watcher);
230 if (!WIFEXITED(watcher->rstatus)) {
231 fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
235 int exitcode = WEXITSTATUS(watcher->rstatus);
236 printf("i3-nagbar process exited with status %d\n", exitcode);
238 fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
241 configerror_pid = -1;
244 /* We need ev >= 4 for the following code. Since it is not *that* important (it
245 * only makes sure that there are no i3-nagbar instances left behind) we still
246 * support old systems with libev 3. */
247 #if EV_VERSION_MAJOR >= 4
249 * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
250 * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
253 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
254 if (configerror_pid != -1) {
255 LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", configerror_pid);
256 kill(configerror_pid, SIGKILL);
262 * Starts an i3-nagbar process which alerts the user that his configuration
263 * file contains one or more errors. Also offers two buttons: One to launch an
264 * $EDITOR on the config file and another one to launch a $PAGER on the error
268 static void start_configerror_nagbar(const char *config_path) {
269 if (only_check_config)
272 fprintf(stderr, "Starting i3-nagbar due to configuration errors\n");
273 configerror_pid = fork();
274 if (configerror_pid == -1) {
275 warn("Could not fork()");
280 if (configerror_pid == 0) {
283 if (asprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path) == -1)
285 if (asprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename) == -1)
288 NULL, /* will be replaced by the executable path */
290 (context->has_errors ? "error" : "warning"),
292 (context->has_errors ?
293 "You have an error in your i3 config file!" :
294 "Your config is outdated. Please fix the warnings to make sure everything works."),
298 (errorfilename ? "-b" : NULL),
299 (context->has_errors ? "show errors" : "show warnings"),
303 exec_i3_utility("i3-nagbar", argv);
307 /* install a child watcher */
308 ev_child *child = smalloc(sizeof(ev_child));
309 ev_child_init(child, &nagbar_exited, configerror_pid, 0);
310 ev_child_start(main_loop, child);
312 /* We need ev >= 4 for the following code. Since it is not *that* important (it
313 * only makes sure that there are no i3-nagbar instances left behind) we still
314 * support old systems with libev 3. */
315 #if EV_VERSION_MAJOR >= 4
316 /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
318 ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
319 ev_cleanup_init(cleanup, nagbar_cleanup);
320 ev_cleanup_start(main_loop, cleanup);
325 * Kills the configerror i3-nagbar process, if any.
327 * Called when reloading/restarting.
329 * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
330 * ev is assumed to handle it (reloading).
333 void kill_configerror_nagbar(bool wait_for_it) {
334 if (configerror_pid == -1)
337 if (kill(configerror_pid, SIGTERM) == -1)
338 warn("kill(configerror_nagbar) failed");
343 /* When restarting, we don’t enter the ev main loop anymore and after the
344 * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
345 * for us and we would end up with a <defunct> process. Therefore we
347 waitpid(configerror_pid, NULL, 0);
351 * Checks for duplicate key bindings (the same keycode or keysym is configured
352 * more than once). If a duplicate binding is found, a message is printed to
353 * stderr and the has_errors variable is set to true, which will start
357 static void check_for_duplicate_bindings(struct context *context) {
358 Binding *bind, *current;
359 TAILQ_FOREACH(current, bindings, bindings) {
360 TAILQ_FOREACH(bind, bindings, bindings) {
361 /* Abort when we reach the current keybinding, only check the
366 /* Check if one is using keysym while the other is using bindsym.
368 /* XXX: It should be checked at a later place (when translating the
369 * keysym to keycodes) if there are any duplicates */
370 if ((bind->symbol == NULL && current->symbol != NULL) ||
371 (bind->symbol != NULL && current->symbol == NULL))
374 /* If bind is NULL, current has to be NULL, too (see above).
375 * If the keycodes differ, it can't be a duplicate. */
376 if (bind->symbol != NULL &&
377 strcasecmp(bind->symbol, current->symbol) != 0)
380 /* Check if the keycodes or modifiers are different. If so, they
381 * can't be duplicate */
382 if (bind->keycode != current->keycode ||
383 bind->mods != current->mods)
385 context->has_errors = true;
386 if (current->keycode != 0) {
387 ELOG("Duplicate keybinding in config file:\n modmask %d with keycode %d, command \"%s\"\n",
388 current->mods, current->keycode, current->command);
390 ELOG("Duplicate keybinding in config file:\n modmask %d with keysym %s, command \"%s\"\n",
391 current->mods, current->symbol, current->command);
397 static void migrate_i3bar_exec(struct Autostart *exec) {
398 ELOG("**********************************************************************\n");
399 ELOG("IGNORING exec command: %s\n", exec->command);
400 ELOG("It contains \"i3bar\". Since i3 v4.1, i3bar will be automatically started\n");
401 ELOG("for each 'bar' configuration block in your i3 config. Please remove the exec\n");
402 ELOG("line and add the following to your i3 config:\n");
405 ELOG(" status_command i3status\n");
407 ELOG("**********************************************************************\n");
409 /* Generate a dummy bar configuration */
410 Barconfig *bar_config = scalloc(sizeof(Barconfig));
411 /* The hard-coded ID is not a problem. It does not conflict with the
412 * auto-generated bar IDs and having multiple hard-coded IDs is irrelevant
413 * – they all just contain status_command = i3status */
414 bar_config->id = sstrdup("migrate-bar");
415 bar_config->status_command = sstrdup("i3status");
416 TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
418 /* Trigger an i3-nagbar */
419 context->has_warnings = true;
422 void parse_file(const char *f) {
423 SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
424 int fd, ret, read_bytes = 0;
428 char buffer[1026], key[512], value[512];
430 if ((fd = open(f, O_RDONLY)) == -1)
431 die("Could not open configuration file: %s\n", strerror(errno));
433 if (fstat(fd, &stbuf) == -1)
434 die("Could not fstat file: %s\n", strerror(errno));
436 buf = scalloc((stbuf.st_size + 1) * sizeof(char));
437 while (read_bytes < stbuf.st_size) {
438 if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
439 die("Could not read(): %s\n", strerror(errno));
443 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
444 die("Could not lseek: %s\n", strerror(errno));
446 if ((fstr = fdopen(fd, "r")) == NULL)
447 die("Could not fdopen: %s\n", strerror(errno));
449 while (!feof(fstr)) {
450 if (fgets(buffer, 1024, fstr) == NULL) {
453 die("Could not read configuration file\n");
456 /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
457 if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
458 key[0] == '#' || strlen(key) < 3)
461 if (strcasecmp(key, "set") == 0) {
462 if (value[0] != '$') {
463 ELOG("Malformed variable assignment, name has to start with $\n");
467 /* get key/value for this variable */
468 char *v_key = value, *v_value;
469 if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) {
470 ELOG("Malformed variable assignment, need a value\n");
474 if (!(v_value = strstr(value, " ")))
475 v_value = strstr(value, "\t");
479 struct Variable *new = scalloc(sizeof(struct Variable));
480 new->key = sstrdup(v_key);
481 new->value = sstrdup(v_value);
482 SLIST_INSERT_HEAD(&variables, new, variables);
483 DLOG("Got new variable %s = %s\n", v_key, v_value);
489 /* For every custom variable, see how often it occurs in the file and
490 * how much extra bytes it requires when replaced. */
491 struct Variable *current, *nearest;
493 /* We need to copy the buffer because we need to invalidate the
494 * variables (otherwise we will count them twice, which is bad when
495 * 'extra' is negative) */
496 char *bufcopy = sstrdup(buf);
497 SLIST_FOREACH(current, &variables, variables) {
498 int extra = (strlen(current->value) - strlen(current->key));
501 next < (bufcopy + stbuf.st_size) &&
502 (next = strcasestr(next, current->key)) != NULL;
503 next += strlen(current->key)) {
505 extra_bytes += extra;
510 /* Then, allocate a new buffer and copy the file over to the new one,
511 * but replace occurences of our variables */
512 char *walk = buf, *destwalk;
513 char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
515 while (walk < (buf + stbuf.st_size)) {
516 /* Find the next variable */
517 SLIST_FOREACH(current, &variables, variables)
518 current->next_match = strcasestr(walk, current->key);
520 int distance = stbuf.st_size;
521 SLIST_FOREACH(current, &variables, variables) {
522 if (current->next_match == NULL)
524 if ((current->next_match - walk) < distance) {
525 distance = (current->next_match - walk);
529 if (nearest == NULL) {
530 /* If there are no more variables, we just copy the rest */
531 strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
532 destwalk += (buf + stbuf.st_size) - walk;
536 /* Copy until the next variable, then copy its value */
537 strncpy(destwalk, walk, distance);
538 strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
539 walk += distance + strlen(nearest->key);
540 destwalk += distance + strlen(nearest->value);
544 /* analyze the string to find out whether this is an old config file (3.x)
545 * or a new config file (4.x). If it’s old, we run the converter script. */
546 int version = detect_version(buf);
548 /* We need to convert this v3 configuration */
549 char *converted = migrate_config(new, stbuf.st_size);
550 if (converted != NULL) {
552 printf("****************************************************************\n");
553 printf("NOTE: Automatically converted configuration file from v3 to v4.\n");
555 printf("Please convert your config file to v4. You can use this command:\n");
556 printf(" mv %s %s.O\n", f, f);
557 printf(" i3-migrate-config-to-v4 %s.O > %s\n", f, f);
558 printf("****************************************************************\n");
564 printf("**********************************************************************\n");
565 printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
566 printf("was not correctly installed on your system?\n");
567 printf("**********************************************************************\n");
572 /* now lex/parse it */
575 context = scalloc(sizeof(struct context));
576 context->filename = f;
578 if (yyparse() != 0) {
579 fprintf(stderr, "Could not parse configfile\n");
583 check_for_duplicate_bindings(context);
585 /* XXX: The following code will be removed in i3 v4.3 (three releases from
586 * now, as of 2011-10-22) */
587 /* Check for any exec or exec_always lines starting i3bar. We remove these
588 * and add a bar block instead. Additionally, a i3-nagbar warning (not an
589 * error) will be displayed so that users update their config file. */
590 struct Autostart *exec, *next;
591 for (exec = TAILQ_FIRST(&autostarts); exec; ) {
592 next = TAILQ_NEXT(exec, autostarts);
593 if (strstr(exec->command, "i3bar") != NULL) {
594 migrate_i3bar_exec(exec);
595 TAILQ_REMOVE(&autostarts, exec, autostarts);
600 for (exec = TAILQ_FIRST(&autostarts_always); exec; ) {
601 next = TAILQ_NEXT(exec, autostarts_always);
602 if (strstr(exec->command, "i3bar") != NULL) {
603 migrate_i3bar_exec(exec);
604 TAILQ_REMOVE(&autostarts_always, exec, autostarts_always);
609 if (context->has_errors || context->has_warnings) {
610 start_configerror_nagbar(f);
614 FREE(context->line_copy);
619 while (!SLIST_EMPTY(&variables)) {
620 current = SLIST_FIRST(&variables);
622 FREE(current->value);
623 SLIST_REMOVE_HEAD(&variables, variables);
631 %lex-param { struct context *context }
636 uint32_t *single_color;
637 struct Colortriple *color;
639 struct Binding *binding;
642 %token <number> NUMBER "<number>"
643 %token <string> WORD "<word>"
644 %token <string> STR "<string>"
645 %token <string> STR_NG "<string (non-greedy)>"
646 %token <string> HEXCOLOR "#<hex>"
647 %token <string> OUTPUT "<RandR output>"
650 %token TOKCOMMENT "<comment>"
651 %token TOKFONT "font"
652 %token TOKBINDSYM "bindsym"
653 %token <number> MODIFIER "<modifier>"
654 %token TOKCONTROL "control"
655 %token TOKSHIFT "shift"
656 %token TOKFLOATING_MODIFIER "floating_modifier"
657 %token <string> QUOTEDSTRING "<quoted string>"
658 %token TOKWORKSPACE "workspace"
659 %token TOKOUTPUT "output"
660 %token TOKASSIGN "assign"
662 %token TOKIPCSOCKET "ipc_socket"
663 %token TOKRESTARTSTATE "restart_state"
664 %token TOKEXEC "exec"
665 %token TOKEXEC_ALWAYS "exec_always"
666 %token <single_color> TOKSINGLECOLOR
667 %token <color> TOKCOLOR
669 %token TOKMODE "mode"
671 %token TOK_ORIENTATION "default_orientation"
672 %token TOK_HORIZ "horizontal"
673 %token TOK_VERT "vertical"
674 %token TOK_AUTO "auto"
675 %token TOK_WORKSPACE_LAYOUT "workspace_layout"
676 %token TOKNEWWINDOW "new_window"
677 %token TOKNEWFLOAT "new_float"
678 %token TOK_NORMAL "normal"
679 %token TOK_NONE "none"
680 %token TOK_1PIXEL "1pixel"
681 %token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse"
682 %token TOK_FORCE_FOCUS_WRAPPING "force_focus_wrapping"
683 %token TOK_FORCE_XINERAMA "force_xinerama"
684 %token TOK_WORKSPACE_AUTO_BAF "workspace_auto_back_and_forth"
685 %token TOKWORKSPACEBAR "workspace_bar"
686 %token TOK_DEFAULT "default"
687 %token TOK_STACKING "stacking"
688 %token TOK_TABBED "tabbed"
689 %token <number> TOKSTACKLIMIT "stack-limit"
690 %token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
691 %token TOK_IGNORE "ignore"
692 %token TOK_LEAVE_FULLSCREEN "leave_fullscreen"
693 %token TOK_FOR_WINDOW "for_window"
695 %token TOK_BAR_OUTPUT "output (bar)"
696 %token TOK_BAR_TRAY_OUTPUT "tray_output"
697 %token TOK_BAR_SOCKET_PATH "socket_path"
698 %token TOK_BAR_MODE "mode"
699 %token TOK_BAR_HIDE "hide"
700 %token TOK_BAR_DOCK "dock"
701 %token TOK_BAR_POSITION "position"
702 %token TOK_BAR_BOTTOM "bottom"
703 %token TOK_BAR_TOP "top"
704 %token TOK_BAR_STATUS_COMMAND "status_command"
705 %token TOK_BAR_FONT "font"
706 %token TOK_BAR_WORKSPACE_BUTTONS "workspace_buttons"
707 %token TOK_BAR_VERBOSE "verbose"
708 %token TOK_BAR_COLORS "colors"
709 %token TOK_BAR_COLOR_BACKGROUND "background"
710 %token TOK_BAR_COLOR_STATUSLINE "statusline"
711 %token TOK_BAR_COLOR_FOCUSED_WORKSPACE "focused_workspace"
712 %token TOK_BAR_COLOR_ACTIVE_WORKSPACE "active_workspace"
713 %token TOK_BAR_COLOR_INACTIVE_WORKSPACE "inactive_workspace"
714 %token TOK_BAR_COLOR_URGENT_WORKSPACE "urgent_workspace"
716 %token TOK_MARK "mark"
717 %token TOK_CLASS "class"
718 %token TOK_INSTANCE "instance"
719 %token TOK_WINDOW_ROLE "window_role"
721 %token TOK_CON_ID "con_id"
722 %token TOK_TITLE "title"
724 %type <binding> binding
725 %type <binding> bindcode
726 %type <binding> bindsym
727 %type <number> binding_modifiers
728 %type <number> binding_modifier
729 %type <number> direction
730 %type <number> layout_mode
731 %type <number> border_style
732 %type <number> new_window
733 %type <number> new_float
734 %type <number> colorpixel
736 %type <number> popup_setting
737 %type <number> bar_position_position
738 %type <number> bar_mode_mode
739 %type <string> command
740 %type <string> word_or_number
741 %type <string> optional_workspace_name
742 %type <string> workspace_name
743 %type <string> window_class
762 | focus_follows_mouse
763 | force_focus_wrapping
765 | workspace_back_and_forth
778 | popup_during_fullscreen
792 TAILQ_INSERT_TAIL(bindings, $1, bindings);
797 TOKBINDCODE bindcode { $$ = $2; }
798 | TOKBINDSYM bindsym { $$ = $2; }
802 binding_modifiers NUMBER command
804 printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $3);
805 Binding *new = scalloc(sizeof(Binding));
816 binding_modifiers word_or_number command
818 printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $3);
819 Binding *new = scalloc(sizeof(Binding));
830 TOK_FOR_WINDOW match command
832 if (match_is_empty(¤t_match)) {
833 ELOG("Match is empty, ignoring this for_window statement\n");
836 printf("\t should execute command %s for the criteria mentioned above\n", $3);
837 Assignment *assignment = scalloc(sizeof(Assignment));
838 assignment->type = A_COMMAND;
839 assignment->match = current_match;
840 assignment->dest.command = $3;
841 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
846 | matchstart criteria matchend
848 printf("match parsed\n");
856 match_init(¤t_match);
863 printf("match specification finished\n");
875 printf("criteria: class = %s\n", $3);
876 current_match.class = regex_new($3);
879 | TOK_INSTANCE '=' STR
881 printf("criteria: instance = %s\n", $3);
882 current_match.instance = regex_new($3);
885 | TOK_WINDOW_ROLE '=' STR
887 printf("criteria: window_role = %s\n", $3);
888 current_match.role = regex_new($3);
893 printf("criteria: id = %s\n", $3);
895 long parsed = strtol($3, &end, 10);
896 if (parsed == LONG_MIN ||
897 parsed == LONG_MAX ||
899 (end && *end != '\0')) {
900 ELOG("Could not parse con id \"%s\"\n", $3);
902 current_match.con_id = (Con*)parsed;
903 printf("id as int = %p\n", current_match.con_id);
908 printf("criteria: window id = %s\n", $3);
910 long parsed = strtol($3, &end, 10);
911 if (parsed == LONG_MIN ||
912 parsed == LONG_MAX ||
914 (end && *end != '\0')) {
915 ELOG("Could not parse window id \"%s\"\n", $3);
917 current_match.id = parsed;
918 printf("window id as int = %d\n", current_match.id);
923 printf("criteria: mark = %s\n", $3);
924 current_match.mark = regex_new($3);
929 printf("criteria: title = %s\n", $3);
930 current_match.title = regex_new($3);
941 asprintf(&$$, "%d", $1);
946 TOKMODE QUOTEDSTRING '{' modelines '}'
948 if (strcasecmp($2, "default") == 0) {
949 printf("You cannot use the name \"default\" for your mode\n");
952 printf("\t now in mode %s\n", $2);
953 printf("\t current bindings = %p\n", current_bindings);
955 TAILQ_FOREACH(binding, current_bindings, bindings) {
956 printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
957 binding->mods, binding->keycode, binding->symbol, binding->command);
960 struct Mode *mode = scalloc(sizeof(struct Mode));
962 mode->bindings = current_bindings;
963 current_bindings = NULL;
964 SLIST_INSERT_HEAD(&modes, mode, modes);
978 if (current_bindings == NULL) {
979 current_bindings = scalloc(sizeof(struct bindings_head));
980 TAILQ_INIT(current_bindings);
983 TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
988 TOK_BAR '{' barlines '}'
990 printf("\t new bar configuration finished, saving.\n");
991 /* Generate a unique ID for this bar */
992 current_bar.id = sstrdup("bar-XXXXXX");
993 /* This works similar to mktemp in that it replaces the last six X with
994 * random letters, but without the restriction that the given buffer
995 * has to contain a valid path name. */
996 char *x = current_bar.id + strlen("bar-");
998 *(x++) = (rand() % 26) + 'a';
1001 /* Copy the current (static) structure into a dynamically allocated
1002 * one, then cleanup our static one. */
1003 Barconfig *bar_config = scalloc(sizeof(Barconfig));
1004 memcpy(bar_config, ¤t_bar, sizeof(Barconfig));
1005 TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
1007 memset(¤t_bar, '\0', sizeof(Barconfig));
1018 | bar_status_command
1024 | bar_workspace_buttons
1028 | bar_color_background
1029 | bar_color_statusline
1030 | bar_color_focused_workspace
1031 | bar_color_active_workspace
1032 | bar_color_inactive_workspace
1033 | bar_color_urgent_workspace
1037 TOK_BAR_STATUS_COMMAND STR
1039 DLOG("should add status command %s\n", $2);
1040 FREE(current_bar.status_command);
1041 current_bar.status_command = $2;
1048 DLOG("bar output %s\n", $2);
1049 int new_outputs = current_bar.num_outputs + 1;
1050 current_bar.outputs = srealloc(current_bar.outputs, sizeof(char*) * new_outputs);
1051 current_bar.outputs[current_bar.num_outputs] = $2;
1052 current_bar.num_outputs = new_outputs;
1057 TOK_BAR_TRAY_OUTPUT STR
1059 DLOG("tray %s\n", $2);
1060 FREE(current_bar.tray_output);
1061 current_bar.tray_output = $2;
1066 TOK_BAR_POSITION bar_position_position
1068 DLOG("position %d\n", $2);
1069 current_bar.position = $2;
1073 bar_position_position:
1074 TOK_BAR_TOP { $$ = P_TOP; }
1075 | TOK_BAR_BOTTOM { $$ = P_BOTTOM; }
1079 TOK_BAR_MODE bar_mode_mode
1081 DLOG("mode %d\n", $2);
1082 current_bar.mode = $2;
1087 TOK_BAR_HIDE { $$ = M_HIDE; }
1088 | TOK_BAR_DOCK { $$ = M_DOCK; }
1094 DLOG("font %s\n", $2);
1095 FREE(current_bar.font);
1096 current_bar.font = $2;
1100 bar_workspace_buttons:
1101 TOK_BAR_WORKSPACE_BUTTONS bool
1103 DLOG("workspace_buttons = %d\n", $2);
1104 /* We store this inverted to make the default setting right when
1105 * initializing the struct with zero. */
1106 current_bar.hide_workspace_buttons = !($2);
1111 TOK_BAR_VERBOSE bool
1113 DLOG("verbose = %d\n", $2);
1114 current_bar.verbose = $2;
1119 TOK_BAR_SOCKET_PATH STR
1121 DLOG("socket_path = %s\n", $2);
1122 FREE(current_bar.socket_path);
1123 current_bar.socket_path = $2;
1128 TOK_BAR_COLORS '{' barlines '}'
1130 /* At the moment, the TOK_BAR_COLORS token is only to make the config
1131 * friendlier for humans. We might change this in the future if it gets
1136 bar_color_background:
1137 TOK_BAR_COLOR_BACKGROUND HEXCOLOR
1139 DLOG("background = %s\n", $2);
1140 current_bar.colors.background = $2;
1144 bar_color_statusline:
1145 TOK_BAR_COLOR_STATUSLINE HEXCOLOR
1147 DLOG("statusline = %s\n", $2);
1148 current_bar.colors.statusline = $2;
1152 bar_color_focused_workspace:
1153 TOK_BAR_COLOR_FOCUSED_WORKSPACE HEXCOLOR HEXCOLOR
1155 DLOG("focused_ws = %s and %s\n", $2, $3);
1156 current_bar.colors.focused_workspace_text = $2;
1157 current_bar.colors.focused_workspace_bg = $3;
1161 bar_color_active_workspace:
1162 TOK_BAR_COLOR_ACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
1164 DLOG("active_ws = %s and %s\n", $2, $3);
1165 current_bar.colors.active_workspace_text = $2;
1166 current_bar.colors.active_workspace_bg = $3;
1170 bar_color_inactive_workspace:
1171 TOK_BAR_COLOR_INACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
1173 DLOG("inactive_ws = %s and %s\n", $2, $3);
1174 current_bar.colors.inactive_workspace_text = $2;
1175 current_bar.colors.inactive_workspace_bg = $3;
1179 bar_color_urgent_workspace:
1180 TOK_BAR_COLOR_URGENT_WORKSPACE HEXCOLOR HEXCOLOR
1182 DLOG("urgent_ws = %s and %s\n", $2, $3);
1183 current_bar.colors.urgent_workspace_text = $2;
1184 current_bar.colors.urgent_workspace_bg = $3;
1189 TOKFLOATING_MODIFIER binding_modifiers
1191 DLOG("floating modifier = %d\n", $2);
1192 config.floating_modifier = $2;
1197 TOK_ORIENTATION direction
1199 DLOG("New containers should start with split direction %d\n", $2);
1200 config.default_orientation = $2;
1205 TOK_HORIZ { $$ = HORIZ; }
1206 | TOK_VERT { $$ = VERT; }
1207 | TOK_AUTO { $$ = NO_ORIENTATION; }
1211 TOK_WORKSPACE_LAYOUT layout_mode
1213 DLOG("new containers will be in mode %d\n", $2);
1214 config.default_layout = $2;
1217 /* We also need to change the layout of the already existing
1218 * workspaces here. Workspaces may exist at this point because
1219 * of the other directives which are modifying workspaces
1220 * (setting the preferred screen or name). While the workspace
1221 * objects are already created, they have never been used.
1222 * Thus, the user very likely awaits the default container mode
1223 * to trigger in this case, regardless of where it is inside
1224 * his configuration file. */
1226 TAILQ_FOREACH(ws, workspaces, workspaces) {
1227 if (ws->table == NULL)
1229 switch_layout_mode(global_conn,
1231 config.container_mode);
1235 | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
1237 DLOG("stack-limit %d with val %d\n", $3, $4);
1238 config.container_stack_limit = $3;
1239 config.container_stack_limit_value = $4;
1242 /* See the comment above */
1244 TAILQ_FOREACH(ws, workspaces, workspaces) {
1245 if (ws->table == NULL)
1247 Container *con = ws->table[0][0];
1248 con->stack_limit = config.container_stack_limit;
1249 con->stack_limit_value = config.container_stack_limit_value;
1256 TOK_DEFAULT { $$ = L_DEFAULT; }
1257 | TOK_STACKING { $$ = L_STACKED; }
1258 | TOK_TABBED { $$ = L_TABBED; }
1262 TOKNEWWINDOW border_style
1264 DLOG("new windows should start with border style %d\n", $2);
1265 config.default_border = $2;
1270 TOKNEWFLOAT border_style
1272 DLOG("new floating windows should start with border style %d\n", $2);
1273 config.default_floating_border = $2;
1278 TOK_NORMAL { $$ = BS_NORMAL; }
1279 | TOK_NONE { $$ = BS_NONE; }
1280 | TOK_1PIXEL { $$ = BS_1PIXEL; }
1290 DLOG("checking word \"%s\"\n", $1);
1291 $$ = (strcasecmp($1, "yes") == 0 ||
1292 strcasecmp($1, "true") == 0 ||
1293 strcasecmp($1, "on") == 0 ||
1294 strcasecmp($1, "enable") == 0 ||
1295 strcasecmp($1, "active") == 0);
1299 focus_follows_mouse:
1300 TOKFOCUSFOLLOWSMOUSE bool
1302 DLOG("focus follows mouse = %d\n", $2);
1303 config.disable_focus_follows_mouse = !($2);
1307 force_focus_wrapping:
1308 TOK_FORCE_FOCUS_WRAPPING bool
1310 DLOG("force focus wrapping = %d\n", $2);
1311 config.force_focus_wrapping = $2;
1316 TOK_FORCE_XINERAMA bool
1318 DLOG("force xinerama = %d\n", $2);
1319 config.force_xinerama = $2;
1323 workspace_back_and_forth:
1324 TOK_WORKSPACE_AUTO_BAF bool
1326 DLOG("automatic workspace back-and-forth = %d\n", $2);
1327 config.workspace_auto_back_and_forth = $2;
1332 TOKWORKSPACEBAR bool
1334 DLOG("workspace bar = %d\n", $2);
1335 config.disable_workspace_bar = !($2);
1340 TOKWORKSPACE NUMBER TOKOUTPUT OUTPUT optional_workspace_name
1344 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1346 char *ws_name = NULL;
1348 asprintf(&ws_name, "%d", ws_num);
1353 DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
1354 /* Check for earlier assignments of the same workspace so that we
1355 * don’t have assignments of a single workspace to different
1357 struct Workspace_Assignment *assignment;
1358 bool duplicate = false;
1359 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
1360 if (strcasecmp(assignment->name, ws_name) == 0) {
1361 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
1363 assignment->output = $4;
1368 assignment = scalloc(sizeof(struct Workspace_Assignment));
1369 assignment->name = ws_name;
1370 assignment->output = $4;
1371 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
1375 | TOKWORKSPACE NUMBER workspace_name
1379 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1381 DLOG("workspace name to: %s\n", $3);
1383 if ($<string>3 != NULL) {
1384 workspace_set_name(workspace_get(ws_num - 1), $<string>3);
1392 optional_workspace_name:
1393 /* empty */ { $$ = NULL; }
1394 | workspace_name { $$ = $1; }
1398 QUOTEDSTRING { $$ = $1; }
1404 TOKASSIGN window_class STR
1406 /* This is the old, deprecated form of assignments. It’s provided for
1407 * compatibility in version (4.1, 4.2, 4.3) and will be removed
1408 * afterwards. It triggers an i3-nagbar warning starting from 4.1. */
1409 ELOG("You are using the old assign syntax (without criteria). "
1410 "Please see the User's Guide for the new syntax and fix "
1411 "your config file.\n");
1412 context->has_warnings = true;
1413 printf("assignment of %s to *%s*\n", $2, $3);
1414 char *workspace = $3;
1415 char *criteria = $2;
1417 Assignment *assignment = scalloc(sizeof(Assignment));
1418 Match *match = &(assignment->match);
1421 char *separator = NULL;
1422 if ((separator = strchr(criteria, '/')) != NULL) {
1423 *(separator++) = '\0';
1425 if (asprintf(&pattern, "(?i)%s", separator) == -1) {
1426 ELOG("asprintf failed\n");
1429 match->title = regex_new(pattern);
1431 printf(" title = %s\n", separator);
1433 if (*criteria != '\0') {
1435 if (asprintf(&pattern, "(?i)%s", criteria) == -1) {
1436 ELOG("asprintf failed\n");
1439 match->class = regex_new(pattern);
1441 printf(" class = %s\n", criteria);
1445 /* Compatibility with older versions: If the assignment target starts
1446 * with ~, we create the equivalent of:
1448 * for_window [class="foo"] floating enable
1450 if (*workspace == '~') {
1452 if (*workspace == '\0') {
1453 /* This assignment was *only* for floating */
1454 assignment->type = A_COMMAND;
1455 assignment->dest.command = sstrdup("floating enable");
1456 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1459 /* Create a new assignment and continue afterwards */
1460 Assignment *floating = scalloc(sizeof(Assignment));
1461 match_copy(&(floating->match), match);
1462 floating->type = A_COMMAND;
1463 floating->dest.command = sstrdup("floating enable");
1464 TAILQ_INSERT_TAIL(&assignments, floating, assignments);
1468 assignment->type = A_TO_WORKSPACE;
1469 assignment->dest.workspace = workspace;
1470 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1472 | TOKASSIGN match STR
1474 if (match_is_empty(¤t_match)) {
1475 ELOG("Match is empty, ignoring this assignment\n");
1478 printf("new assignment, using above criteria, to workspace %s\n", $3);
1479 Assignment *assignment = scalloc(sizeof(Assignment));
1480 assignment->match = current_match;
1481 assignment->type = A_TO_WORKSPACE;
1482 assignment->dest.workspace = $3;
1483 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1495 config.ipc_socket_path = $2;
1502 config.restart_state_path = $2;
1509 struct Autostart *new = smalloc(sizeof(struct Autostart));
1511 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
1518 struct Autostart *new = smalloc(sizeof(struct Autostart));
1520 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
1527 ELOG("The terminal option is DEPRECATED and has no effect. "
1528 "Please remove it from your configuration file.\n");
1535 config.font = load_font($2, true);
1536 printf("font %s\n", $2);
1542 TOKSINGLECOLOR colorpixel
1544 uint32_t *dest = $1;
1550 TOKCOLOR colorpixel colorpixel colorpixel
1552 struct Colortriple *dest = $1;
1555 dest->background = $3;
1563 $$ = get_colorpixel($1);
1570 /* NULL */ { $$ = 0; }
1572 | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
1573 | binding_modifiers '+' { $$ = $1; }
1577 MODIFIER { $$ = $1; }
1578 | TOKCONTROL { $$ = BIND_CONTROL; }
1579 | TOKSHIFT { $$ = BIND_SHIFT; }
1582 popup_during_fullscreen:
1583 TOK_POPUP_DURING_FULLSCREEN popup_setting
1585 DLOG("popup_during_fullscreen setting: %d\n", $2);
1586 config.popup_during_fullscreen = $2;
1591 TOK_IGNORE { $$ = PDF_IGNORE; }
1592 | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; }