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 sasprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path);
284 sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
286 NULL, /* will be replaced by the executable path */
288 (context->has_errors ? "error" : "warning"),
290 (context->has_errors ?
291 "You have an error in your i3 config file!" :
292 "Your config is outdated. Please fix the warnings to make sure everything works."),
296 (errorfilename ? "-b" : NULL),
297 (context->has_errors ? "show errors" : "show warnings"),
301 exec_i3_utility("i3-nagbar", argv);
305 /* install a child watcher */
306 ev_child *child = smalloc(sizeof(ev_child));
307 ev_child_init(child, &nagbar_exited, configerror_pid, 0);
308 ev_child_start(main_loop, child);
310 /* We need ev >= 4 for the following code. Since it is not *that* important (it
311 * only makes sure that there are no i3-nagbar instances left behind) we still
312 * support old systems with libev 3. */
313 #if EV_VERSION_MAJOR >= 4
314 /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
316 ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
317 ev_cleanup_init(cleanup, nagbar_cleanup);
318 ev_cleanup_start(main_loop, cleanup);
323 * Kills the configerror i3-nagbar process, if any.
325 * Called when reloading/restarting.
327 * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
328 * ev is assumed to handle it (reloading).
331 void kill_configerror_nagbar(bool wait_for_it) {
332 if (configerror_pid == -1)
335 if (kill(configerror_pid, SIGTERM) == -1)
336 warn("kill(configerror_nagbar) failed");
341 /* When restarting, we don’t enter the ev main loop anymore and after the
342 * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
343 * for us and we would end up with a <defunct> process. Therefore we
345 waitpid(configerror_pid, NULL, 0);
349 * Checks for duplicate key bindings (the same keycode or keysym is configured
350 * more than once). If a duplicate binding is found, a message is printed to
351 * stderr and the has_errors variable is set to true, which will start
355 static void check_for_duplicate_bindings(struct context *context) {
356 Binding *bind, *current;
357 TAILQ_FOREACH(current, bindings, bindings) {
358 TAILQ_FOREACH(bind, bindings, bindings) {
359 /* Abort when we reach the current keybinding, only check the
364 /* Check if one is using keysym while the other is using bindsym.
366 /* XXX: It should be checked at a later place (when translating the
367 * keysym to keycodes) if there are any duplicates */
368 if ((bind->symbol == NULL && current->symbol != NULL) ||
369 (bind->symbol != NULL && current->symbol == NULL))
372 /* If bind is NULL, current has to be NULL, too (see above).
373 * If the keycodes differ, it can't be a duplicate. */
374 if (bind->symbol != NULL &&
375 strcasecmp(bind->symbol, current->symbol) != 0)
378 /* Check if the keycodes or modifiers are different. If so, they
379 * can't be duplicate */
380 if (bind->keycode != current->keycode ||
381 bind->mods != current->mods)
383 context->has_errors = true;
384 if (current->keycode != 0) {
385 ELOG("Duplicate keybinding in config file:\n modmask %d with keycode %d, command \"%s\"\n",
386 current->mods, current->keycode, current->command);
388 ELOG("Duplicate keybinding in config file:\n modmask %d with keysym %s, command \"%s\"\n",
389 current->mods, current->symbol, current->command);
395 static void migrate_i3bar_exec(struct Autostart *exec) {
396 ELOG("**********************************************************************\n");
397 ELOG("IGNORING exec command: %s\n", exec->command);
398 ELOG("It contains \"i3bar\". Since i3 v4.1, i3bar will be automatically started\n");
399 ELOG("for each 'bar' configuration block in your i3 config. Please remove the exec\n");
400 ELOG("line and add the following to your i3 config:\n");
403 ELOG(" status_command i3status\n");
405 ELOG("**********************************************************************\n");
407 /* Generate a dummy bar configuration */
408 Barconfig *bar_config = scalloc(sizeof(Barconfig));
409 /* The hard-coded ID is not a problem. It does not conflict with the
410 * auto-generated bar IDs and having multiple hard-coded IDs is irrelevant
411 * – they all just contain status_command = i3status */
412 bar_config->id = sstrdup("migrate-bar");
413 bar_config->status_command = sstrdup("i3status");
414 TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
416 /* Trigger an i3-nagbar */
417 context->has_warnings = true;
420 void parse_file(const char *f) {
421 SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
422 int fd, ret, read_bytes = 0;
426 char buffer[1026], key[512], value[512];
428 if ((fd = open(f, O_RDONLY)) == -1)
429 die("Could not open configuration file: %s\n", strerror(errno));
431 if (fstat(fd, &stbuf) == -1)
432 die("Could not fstat file: %s\n", strerror(errno));
434 buf = scalloc((stbuf.st_size + 1) * sizeof(char));
435 while (read_bytes < stbuf.st_size) {
436 if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
437 die("Could not read(): %s\n", strerror(errno));
441 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
442 die("Could not lseek: %s\n", strerror(errno));
444 if ((fstr = fdopen(fd, "r")) == NULL)
445 die("Could not fdopen: %s\n", strerror(errno));
447 while (!feof(fstr)) {
448 if (fgets(buffer, 1024, fstr) == NULL) {
451 die("Could not read configuration file\n");
454 /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
455 if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
456 key[0] == '#' || strlen(key) < 3)
459 if (strcasecmp(key, "set") == 0) {
460 if (value[0] != '$') {
461 ELOG("Malformed variable assignment, name has to start with $\n");
465 /* get key/value for this variable */
466 char *v_key = value, *v_value;
467 if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) {
468 ELOG("Malformed variable assignment, need a value\n");
472 if (!(v_value = strstr(value, " ")))
473 v_value = strstr(value, "\t");
477 struct Variable *new = scalloc(sizeof(struct Variable));
478 new->key = sstrdup(v_key);
479 new->value = sstrdup(v_value);
480 SLIST_INSERT_HEAD(&variables, new, variables);
481 DLOG("Got new variable %s = %s\n", v_key, v_value);
487 /* For every custom variable, see how often it occurs in the file and
488 * how much extra bytes it requires when replaced. */
489 struct Variable *current, *nearest;
491 /* We need to copy the buffer because we need to invalidate the
492 * variables (otherwise we will count them twice, which is bad when
493 * 'extra' is negative) */
494 char *bufcopy = sstrdup(buf);
495 SLIST_FOREACH(current, &variables, variables) {
496 int extra = (strlen(current->value) - strlen(current->key));
499 next < (bufcopy + stbuf.st_size) &&
500 (next = strcasestr(next, current->key)) != NULL;
501 next += strlen(current->key)) {
503 extra_bytes += extra;
508 /* Then, allocate a new buffer and copy the file over to the new one,
509 * but replace occurences of our variables */
510 char *walk = buf, *destwalk;
511 char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
513 while (walk < (buf + stbuf.st_size)) {
514 /* Find the next variable */
515 SLIST_FOREACH(current, &variables, variables)
516 current->next_match = strcasestr(walk, current->key);
518 int distance = stbuf.st_size;
519 SLIST_FOREACH(current, &variables, variables) {
520 if (current->next_match == NULL)
522 if ((current->next_match - walk) < distance) {
523 distance = (current->next_match - walk);
527 if (nearest == NULL) {
528 /* If there are no more variables, we just copy the rest */
529 strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
530 destwalk += (buf + stbuf.st_size) - walk;
534 /* Copy until the next variable, then copy its value */
535 strncpy(destwalk, walk, distance);
536 strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
537 walk += distance + strlen(nearest->key);
538 destwalk += distance + strlen(nearest->value);
542 /* analyze the string to find out whether this is an old config file (3.x)
543 * or a new config file (4.x). If it’s old, we run the converter script. */
544 int version = detect_version(buf);
546 /* We need to convert this v3 configuration */
547 char *converted = migrate_config(new, stbuf.st_size);
548 if (converted != NULL) {
550 printf("****************************************************************\n");
551 printf("NOTE: Automatically converted configuration file from v3 to v4.\n");
553 printf("Please convert your config file to v4. You can use this command:\n");
554 printf(" mv %s %s.O\n", f, f);
555 printf(" i3-migrate-config-to-v4 %s.O > %s\n", f, f);
556 printf("****************************************************************\n");
562 printf("**********************************************************************\n");
563 printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
564 printf("was not correctly installed on your system?\n");
565 printf("**********************************************************************\n");
570 /* now lex/parse it */
573 context = scalloc(sizeof(struct context));
574 context->filename = f;
576 if (yyparse() != 0) {
577 fprintf(stderr, "Could not parse configfile\n");
581 check_for_duplicate_bindings(context);
583 /* XXX: The following code will be removed in i3 v4.3 (three releases from
584 * now, as of 2011-10-22) */
585 /* Check for any exec or exec_always lines starting i3bar. We remove these
586 * and add a bar block instead. Additionally, a i3-nagbar warning (not an
587 * error) will be displayed so that users update their config file. */
588 struct Autostart *exec, *next;
589 for (exec = TAILQ_FIRST(&autostarts); exec; ) {
590 next = TAILQ_NEXT(exec, autostarts);
591 if (strstr(exec->command, "i3bar") != NULL) {
592 migrate_i3bar_exec(exec);
593 TAILQ_REMOVE(&autostarts, exec, autostarts);
598 for (exec = TAILQ_FIRST(&autostarts_always); exec; ) {
599 next = TAILQ_NEXT(exec, autostarts_always);
600 if (strstr(exec->command, "i3bar") != NULL) {
601 migrate_i3bar_exec(exec);
602 TAILQ_REMOVE(&autostarts_always, exec, autostarts_always);
607 if (context->has_errors || context->has_warnings) {
608 start_configerror_nagbar(f);
612 FREE(context->line_copy);
617 while (!SLIST_EMPTY(&variables)) {
618 current = SLIST_FIRST(&variables);
620 FREE(current->value);
621 SLIST_REMOVE_HEAD(&variables, variables);
629 %lex-param { struct context *context }
634 uint32_t *single_color;
635 struct Colortriple *color;
637 struct Binding *binding;
640 %token <number> NUMBER "<number>"
641 %token <string> WORD "<word>"
642 %token <string> STR "<string>"
643 %token <string> STR_NG "<string (non-greedy)>"
644 %token <string> HEXCOLOR "#<hex>"
645 %token <string> OUTPUT "<RandR output>"
648 %token TOKCOMMENT "<comment>"
649 %token TOKFONT "font"
650 %token TOKBINDSYM "bindsym"
651 %token <number> MODIFIER "<modifier>"
652 %token TOKCONTROL "control"
653 %token TOKSHIFT "shift"
654 %token TOKFLOATING_MODIFIER "floating_modifier"
655 %token <string> QUOTEDSTRING "<quoted string>"
656 %token TOKWORKSPACE "workspace"
657 %token TOKOUTPUT "output"
658 %token TOKASSIGN "assign"
660 %token TOKIPCSOCKET "ipc_socket"
661 %token TOKRESTARTSTATE "restart_state"
662 %token TOKEXEC "exec"
663 %token TOKEXEC_ALWAYS "exec_always"
664 %token <single_color> TOKSINGLECOLOR
665 %token <color> TOKCOLOR
667 %token TOKMODE "mode"
669 %token TOK_ORIENTATION "default_orientation"
670 %token TOK_HORIZ "horizontal"
671 %token TOK_VERT "vertical"
672 %token TOK_AUTO "auto"
673 %token TOK_WORKSPACE_LAYOUT "workspace_layout"
674 %token TOKNEWWINDOW "new_window"
675 %token TOKNEWFLOAT "new_float"
676 %token TOK_NORMAL "normal"
677 %token TOK_NONE "none"
678 %token TOK_1PIXEL "1pixel"
679 %token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse"
680 %token TOK_FORCE_FOCUS_WRAPPING "force_focus_wrapping"
681 %token TOK_FORCE_XINERAMA "force_xinerama"
682 %token TOK_WORKSPACE_AUTO_BAF "workspace_auto_back_and_forth"
683 %token TOKWORKSPACEBAR "workspace_bar"
684 %token TOK_DEFAULT "default"
685 %token TOK_STACKING "stacking"
686 %token TOK_TABBED "tabbed"
687 %token <number> TOKSTACKLIMIT "stack-limit"
688 %token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
689 %token TOK_IGNORE "ignore"
690 %token TOK_LEAVE_FULLSCREEN "leave_fullscreen"
691 %token TOK_FOR_WINDOW "for_window"
693 %token TOK_BAR_OUTPUT "output (bar)"
694 %token TOK_BAR_TRAY_OUTPUT "tray_output"
695 %token TOK_BAR_SOCKET_PATH "socket_path"
696 %token TOK_BAR_MODE "mode (bar)"
697 %token TOK_BAR_HIDE "hide"
698 %token TOK_BAR_DOCK "dock"
699 %token TOK_BAR_POSITION "position"
700 %token TOK_BAR_BOTTOM "bottom"
701 %token TOK_BAR_TOP "top"
702 %token TOK_BAR_STATUS_COMMAND "status_command"
703 %token TOK_BAR_FONT "font (bar)"
704 %token TOK_BAR_WORKSPACE_BUTTONS "workspace_buttons"
705 %token TOK_BAR_VERBOSE "verbose"
706 %token TOK_BAR_COLORS "colors"
707 %token TOK_BAR_COLOR_BACKGROUND "background"
708 %token TOK_BAR_COLOR_STATUSLINE "statusline"
709 %token TOK_BAR_COLOR_FOCUSED_WORKSPACE "focused_workspace"
710 %token TOK_BAR_COLOR_ACTIVE_WORKSPACE "active_workspace"
711 %token TOK_BAR_COLOR_INACTIVE_WORKSPACE "inactive_workspace"
712 %token TOK_BAR_COLOR_URGENT_WORKSPACE "urgent_workspace"
714 %token TOK_MARK "mark"
715 %token TOK_CLASS "class"
716 %token TOK_INSTANCE "instance"
717 %token TOK_WINDOW_ROLE "window_role"
719 %token TOK_CON_ID "con_id"
720 %token TOK_TITLE "title"
722 %type <binding> binding
723 %type <binding> bindcode
724 %type <binding> bindsym
725 %type <number> binding_modifiers
726 %type <number> binding_modifier
727 %type <number> direction
728 %type <number> layout_mode
729 %type <number> border_style
730 %type <number> new_window
731 %type <number> new_float
732 %type <number> colorpixel
734 %type <number> popup_setting
735 %type <number> bar_position_position
736 %type <number> bar_mode_mode
737 %type <string> command
738 %type <string> word_or_number
739 %type <string> optional_workspace_name
740 %type <string> workspace_name
741 %type <string> window_class
760 | focus_follows_mouse
761 | force_focus_wrapping
763 | workspace_back_and_forth
776 | popup_during_fullscreen
790 TAILQ_INSERT_TAIL(bindings, $1, bindings);
795 TOKBINDCODE bindcode { $$ = $2; }
796 | TOKBINDSYM bindsym { $$ = $2; }
800 binding_modifiers NUMBER command
802 printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $3);
803 Binding *new = scalloc(sizeof(Binding));
814 binding_modifiers word_or_number command
816 printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $3);
817 Binding *new = scalloc(sizeof(Binding));
828 TOK_FOR_WINDOW match command
830 if (match_is_empty(¤t_match)) {
831 ELOG("Match is empty, ignoring this for_window statement\n");
834 printf("\t should execute command %s for the criteria mentioned above\n", $3);
835 Assignment *assignment = scalloc(sizeof(Assignment));
836 assignment->type = A_COMMAND;
837 assignment->match = current_match;
838 assignment->dest.command = $3;
839 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
844 | matchstart criteria matchend
846 printf("match parsed\n");
854 match_init(¤t_match);
861 printf("match specification finished\n");
873 printf("criteria: class = %s\n", $3);
874 current_match.class = regex_new($3);
877 | TOK_INSTANCE '=' STR
879 printf("criteria: instance = %s\n", $3);
880 current_match.instance = regex_new($3);
883 | TOK_WINDOW_ROLE '=' STR
885 printf("criteria: window_role = %s\n", $3);
886 current_match.role = regex_new($3);
891 printf("criteria: id = %s\n", $3);
893 long parsed = strtol($3, &end, 10);
894 if (parsed == LONG_MIN ||
895 parsed == LONG_MAX ||
897 (end && *end != '\0')) {
898 ELOG("Could not parse con id \"%s\"\n", $3);
900 current_match.con_id = (Con*)parsed;
901 printf("id as int = %p\n", current_match.con_id);
906 printf("criteria: window id = %s\n", $3);
908 long parsed = strtol($3, &end, 10);
909 if (parsed == LONG_MIN ||
910 parsed == LONG_MAX ||
912 (end && *end != '\0')) {
913 ELOG("Could not parse window id \"%s\"\n", $3);
915 current_match.id = parsed;
916 printf("window id as int = %d\n", current_match.id);
921 printf("criteria: mark = %s\n", $3);
922 current_match.mark = regex_new($3);
927 printf("criteria: title = %s\n", $3);
928 current_match.title = regex_new($3);
939 sasprintf(&$$, "%d", $1);
944 TOKMODE QUOTEDSTRING '{' modelines '}'
946 if (strcasecmp($2, "default") == 0) {
947 printf("You cannot use the name \"default\" for your mode\n");
950 printf("\t now in mode %s\n", $2);
951 printf("\t current bindings = %p\n", current_bindings);
953 TAILQ_FOREACH(binding, current_bindings, bindings) {
954 printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
955 binding->mods, binding->keycode, binding->symbol, binding->command);
958 struct Mode *mode = scalloc(sizeof(struct Mode));
960 mode->bindings = current_bindings;
961 current_bindings = NULL;
962 SLIST_INSERT_HEAD(&modes, mode, modes);
976 if (current_bindings == NULL) {
977 current_bindings = scalloc(sizeof(struct bindings_head));
978 TAILQ_INIT(current_bindings);
981 TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
986 TOK_BAR '{' barlines '}'
988 printf("\t new bar configuration finished, saving.\n");
989 /* Generate a unique ID for this bar */
990 current_bar.id = sstrdup("bar-XXXXXX");
991 /* This works similar to mktemp in that it replaces the last six X with
992 * random letters, but without the restriction that the given buffer
993 * has to contain a valid path name. */
994 char *x = current_bar.id + strlen("bar-");
996 *(x++) = (rand() % 26) + 'a';
999 /* Copy the current (static) structure into a dynamically allocated
1000 * one, then cleanup our static one. */
1001 Barconfig *bar_config = scalloc(sizeof(Barconfig));
1002 memcpy(bar_config, ¤t_bar, sizeof(Barconfig));
1003 TAILQ_INSERT_TAIL(&barconfigs, bar_config, configs);
1005 memset(¤t_bar, '\0', sizeof(Barconfig));
1016 | bar_status_command
1022 | bar_workspace_buttons
1026 | bar_color_background
1027 | bar_color_statusline
1028 | bar_color_focused_workspace
1029 | bar_color_active_workspace
1030 | bar_color_inactive_workspace
1031 | bar_color_urgent_workspace
1035 TOK_BAR_STATUS_COMMAND STR
1037 DLOG("should add status command %s\n", $2);
1038 FREE(current_bar.status_command);
1039 current_bar.status_command = $2;
1046 DLOG("bar output %s\n", $2);
1047 int new_outputs = current_bar.num_outputs + 1;
1048 current_bar.outputs = srealloc(current_bar.outputs, sizeof(char*) * new_outputs);
1049 current_bar.outputs[current_bar.num_outputs] = $2;
1050 current_bar.num_outputs = new_outputs;
1055 TOK_BAR_TRAY_OUTPUT STR
1057 DLOG("tray %s\n", $2);
1058 FREE(current_bar.tray_output);
1059 current_bar.tray_output = $2;
1064 TOK_BAR_POSITION bar_position_position
1066 DLOG("position %d\n", $2);
1067 current_bar.position = $2;
1071 bar_position_position:
1072 TOK_BAR_TOP { $$ = P_TOP; }
1073 | TOK_BAR_BOTTOM { $$ = P_BOTTOM; }
1077 TOK_BAR_MODE bar_mode_mode
1079 DLOG("mode %d\n", $2);
1080 current_bar.mode = $2;
1085 TOK_BAR_HIDE { $$ = M_HIDE; }
1086 | TOK_BAR_DOCK { $$ = M_DOCK; }
1092 DLOG("font %s\n", $2);
1093 FREE(current_bar.font);
1094 current_bar.font = $2;
1098 bar_workspace_buttons:
1099 TOK_BAR_WORKSPACE_BUTTONS bool
1101 DLOG("workspace_buttons = %d\n", $2);
1102 /* We store this inverted to make the default setting right when
1103 * initializing the struct with zero. */
1104 current_bar.hide_workspace_buttons = !($2);
1109 TOK_BAR_VERBOSE bool
1111 DLOG("verbose = %d\n", $2);
1112 current_bar.verbose = $2;
1117 TOK_BAR_SOCKET_PATH STR
1119 DLOG("socket_path = %s\n", $2);
1120 FREE(current_bar.socket_path);
1121 current_bar.socket_path = $2;
1126 TOK_BAR_COLORS '{' barlines '}'
1128 /* At the moment, the TOK_BAR_COLORS token is only to make the config
1129 * friendlier for humans. We might change this in the future if it gets
1134 bar_color_background:
1135 TOK_BAR_COLOR_BACKGROUND HEXCOLOR
1137 DLOG("background = %s\n", $2);
1138 current_bar.colors.background = $2;
1142 bar_color_statusline:
1143 TOK_BAR_COLOR_STATUSLINE HEXCOLOR
1145 DLOG("statusline = %s\n", $2);
1146 current_bar.colors.statusline = $2;
1150 bar_color_focused_workspace:
1151 TOK_BAR_COLOR_FOCUSED_WORKSPACE HEXCOLOR HEXCOLOR
1153 DLOG("focused_ws = %s and %s\n", $2, $3);
1154 current_bar.colors.focused_workspace_text = $2;
1155 current_bar.colors.focused_workspace_bg = $3;
1159 bar_color_active_workspace:
1160 TOK_BAR_COLOR_ACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
1162 DLOG("active_ws = %s and %s\n", $2, $3);
1163 current_bar.colors.active_workspace_text = $2;
1164 current_bar.colors.active_workspace_bg = $3;
1168 bar_color_inactive_workspace:
1169 TOK_BAR_COLOR_INACTIVE_WORKSPACE HEXCOLOR HEXCOLOR
1171 DLOG("inactive_ws = %s and %s\n", $2, $3);
1172 current_bar.colors.inactive_workspace_text = $2;
1173 current_bar.colors.inactive_workspace_bg = $3;
1177 bar_color_urgent_workspace:
1178 TOK_BAR_COLOR_URGENT_WORKSPACE HEXCOLOR HEXCOLOR
1180 DLOG("urgent_ws = %s and %s\n", $2, $3);
1181 current_bar.colors.urgent_workspace_text = $2;
1182 current_bar.colors.urgent_workspace_bg = $3;
1187 TOKFLOATING_MODIFIER binding_modifiers
1189 DLOG("floating modifier = %d\n", $2);
1190 config.floating_modifier = $2;
1195 TOK_ORIENTATION direction
1197 DLOG("New containers should start with split direction %d\n", $2);
1198 config.default_orientation = $2;
1203 TOK_HORIZ { $$ = HORIZ; }
1204 | TOK_VERT { $$ = VERT; }
1205 | TOK_AUTO { $$ = NO_ORIENTATION; }
1209 TOK_WORKSPACE_LAYOUT layout_mode
1211 DLOG("new containers will be in mode %d\n", $2);
1212 config.default_layout = $2;
1215 /* We also need to change the layout of the already existing
1216 * workspaces here. Workspaces may exist at this point because
1217 * of the other directives which are modifying workspaces
1218 * (setting the preferred screen or name). While the workspace
1219 * objects are already created, they have never been used.
1220 * Thus, the user very likely awaits the default container mode
1221 * to trigger in this case, regardless of where it is inside
1222 * his configuration file. */
1224 TAILQ_FOREACH(ws, workspaces, workspaces) {
1225 if (ws->table == NULL)
1227 switch_layout_mode(global_conn,
1229 config.container_mode);
1233 | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
1235 DLOG("stack-limit %d with val %d\n", $3, $4);
1236 config.container_stack_limit = $3;
1237 config.container_stack_limit_value = $4;
1240 /* See the comment above */
1242 TAILQ_FOREACH(ws, workspaces, workspaces) {
1243 if (ws->table == NULL)
1245 Container *con = ws->table[0][0];
1246 con->stack_limit = config.container_stack_limit;
1247 con->stack_limit_value = config.container_stack_limit_value;
1254 TOK_DEFAULT { $$ = L_DEFAULT; }
1255 | TOK_STACKING { $$ = L_STACKED; }
1256 | TOK_TABBED { $$ = L_TABBED; }
1260 TOKNEWWINDOW border_style
1262 DLOG("new windows should start with border style %d\n", $2);
1263 config.default_border = $2;
1268 TOKNEWFLOAT border_style
1270 DLOG("new floating windows should start with border style %d\n", $2);
1271 config.default_floating_border = $2;
1276 TOK_NORMAL { $$ = BS_NORMAL; }
1277 | TOK_NONE { $$ = BS_NONE; }
1278 | TOK_1PIXEL { $$ = BS_1PIXEL; }
1288 DLOG("checking word \"%s\"\n", $1);
1289 $$ = (strcasecmp($1, "yes") == 0 ||
1290 strcasecmp($1, "true") == 0 ||
1291 strcasecmp($1, "on") == 0 ||
1292 strcasecmp($1, "enable") == 0 ||
1293 strcasecmp($1, "active") == 0);
1297 focus_follows_mouse:
1298 TOKFOCUSFOLLOWSMOUSE bool
1300 DLOG("focus follows mouse = %d\n", $2);
1301 config.disable_focus_follows_mouse = !($2);
1305 force_focus_wrapping:
1306 TOK_FORCE_FOCUS_WRAPPING bool
1308 DLOG("force focus wrapping = %d\n", $2);
1309 config.force_focus_wrapping = $2;
1314 TOK_FORCE_XINERAMA bool
1316 DLOG("force xinerama = %d\n", $2);
1317 config.force_xinerama = $2;
1321 workspace_back_and_forth:
1322 TOK_WORKSPACE_AUTO_BAF bool
1324 DLOG("automatic workspace back-and-forth = %d\n", $2);
1325 config.workspace_auto_back_and_forth = $2;
1330 TOKWORKSPACEBAR bool
1332 DLOG("workspace bar = %d\n", $2);
1333 config.disable_workspace_bar = !($2);
1338 TOKWORKSPACE NUMBER TOKOUTPUT OUTPUT optional_workspace_name
1342 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1344 char *ws_name = NULL;
1346 sasprintf(&ws_name, "%d", ws_num);
1351 DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
1352 /* Check for earlier assignments of the same workspace so that we
1353 * don’t have assignments of a single workspace to different
1355 struct Workspace_Assignment *assignment;
1356 bool duplicate = false;
1357 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
1358 if (strcasecmp(assignment->name, ws_name) == 0) {
1359 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
1361 assignment->output = $4;
1366 assignment = scalloc(sizeof(struct Workspace_Assignment));
1367 assignment->name = ws_name;
1368 assignment->output = $4;
1369 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
1373 | TOKWORKSPACE NUMBER workspace_name
1377 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1379 DLOG("workspace name to: %s\n", $3);
1381 if ($<string>3 != NULL) {
1382 workspace_set_name(workspace_get(ws_num - 1), $<string>3);
1390 optional_workspace_name:
1391 /* empty */ { $$ = NULL; }
1392 | workspace_name { $$ = $1; }
1396 QUOTEDSTRING { $$ = $1; }
1402 TOKASSIGN window_class STR
1404 /* This is the old, deprecated form of assignments. It’s provided for
1405 * compatibility in version (4.1, 4.2, 4.3) and will be removed
1406 * afterwards. It triggers an i3-nagbar warning starting from 4.1. */
1407 ELOG("You are using the old assign syntax (without criteria). "
1408 "Please see the User's Guide for the new syntax and fix "
1409 "your config file.\n");
1410 context->has_warnings = true;
1411 printf("assignment of %s to *%s*\n", $2, $3);
1412 char *workspace = $3;
1413 char *criteria = $2;
1415 Assignment *assignment = scalloc(sizeof(Assignment));
1416 Match *match = &(assignment->match);
1419 char *separator = NULL;
1420 if ((separator = strchr(criteria, '/')) != NULL) {
1421 *(separator++) = '\0';
1423 sasprintf(&pattern, "(?i)%s", separator);
1424 match->title = regex_new(pattern);
1426 printf(" title = %s\n", separator);
1428 if (*criteria != '\0') {
1430 sasprintf(&pattern, "(?i)%s", criteria);
1431 match->class = regex_new(pattern);
1433 printf(" class = %s\n", criteria);
1437 /* Compatibility with older versions: If the assignment target starts
1438 * with ~, we create the equivalent of:
1440 * for_window [class="foo"] floating enable
1442 if (*workspace == '~') {
1444 if (*workspace == '\0') {
1445 /* This assignment was *only* for floating */
1446 assignment->type = A_COMMAND;
1447 assignment->dest.command = sstrdup("floating enable");
1448 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1451 /* Create a new assignment and continue afterwards */
1452 Assignment *floating = scalloc(sizeof(Assignment));
1453 match_copy(&(floating->match), match);
1454 floating->type = A_COMMAND;
1455 floating->dest.command = sstrdup("floating enable");
1456 TAILQ_INSERT_TAIL(&assignments, floating, assignments);
1460 assignment->type = A_TO_WORKSPACE;
1461 assignment->dest.workspace = workspace;
1462 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1464 | TOKASSIGN match STR
1466 if (match_is_empty(¤t_match)) {
1467 ELOG("Match is empty, ignoring this assignment\n");
1470 printf("new assignment, using above criteria, to workspace %s\n", $3);
1471 Assignment *assignment = scalloc(sizeof(Assignment));
1472 assignment->match = current_match;
1473 assignment->type = A_TO_WORKSPACE;
1474 assignment->dest.workspace = $3;
1475 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1487 config.ipc_socket_path = $2;
1494 config.restart_state_path = $2;
1501 struct Autostart *new = smalloc(sizeof(struct Autostart));
1503 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
1510 struct Autostart *new = smalloc(sizeof(struct Autostart));
1512 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
1519 ELOG("The terminal option is DEPRECATED and has no effect. "
1520 "Please remove it from your configuration file.\n");
1527 config.font = load_font($2, true);
1528 printf("font %s\n", $2);
1534 TOKSINGLECOLOR colorpixel
1536 uint32_t *dest = $1;
1542 TOKCOLOR colorpixel colorpixel colorpixel
1544 struct Colortriple *dest = $1;
1547 dest->background = $3;
1555 $$ = get_colorpixel($1);
1562 /* NULL */ { $$ = 0; }
1564 | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
1565 | binding_modifiers '+' { $$ = $1; }
1569 MODIFIER { $$ = $1; }
1570 | TOKCONTROL { $$ = BIND_CONTROL; }
1571 | TOKSHIFT { $$ = BIND_SHIFT; }
1574 popup_during_fullscreen:
1575 TOK_POPUP_DURING_FULLSCREEN popup_setting
1577 DLOG("popup_during_fullscreen setting: %d\n", $2);
1578 config.popup_during_fullscreen = $2;
1583 TOK_IGNORE { $$ = PDF_IGNORE; }
1584 | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; }