3 * vim:ts=4:sw=4:expandtab
14 static pid_t configerror_pid = -1;
16 static Match current_match;
18 typedef struct yy_buffer_state *YY_BUFFER_STATE;
19 extern int yylex(struct context *context);
20 extern int yyparse(void);
21 extern int yylex_destroy(void);
23 YY_BUFFER_STATE yy_scan_string(const char *);
25 static struct bindings_head *current_bindings;
26 static struct context *context;
28 /* We don’t need yydebug for now, as we got decent error messages using
29 * yyerror(). Should you ever want to extend the parser, it might be handy
30 * to just comment it in again, so it stays here. */
33 void yyerror(const char *error_message) {
34 context->has_errors = true;
37 ELOG("CONFIG: %s\n", error_message);
38 ELOG("CONFIG: in file \"%s\", line %d:\n",
39 context->filename, context->line_number);
40 ELOG("CONFIG: %s\n", context->line_copy);
41 char buffer[context->last_column+1];
42 buffer[context->last_column] = '\0';
43 for (int c = 1; c <= context->last_column; c++)
44 buffer[c-1] = (c >= context->first_column ? '^' : ' ');
45 ELOG("CONFIG: %s\n", buffer);
54 * Goes through each line of buf (separated by \n) and checks for statements /
55 * commands which only occur in i3 v4 configuration files. If it finds any, it
56 * returns version 4, otherwise it returns version 3.
59 static int detect_version(char *buf) {
62 while (*walk != '\0') {
68 /* check for some v4-only statements */
69 if (strncasecmp(line, "bindcode", strlen("bindcode")) == 0 ||
70 strncasecmp(line, "force_focus_wrapping", strlen("force_focus_wrapping")) == 0 ||
71 strncasecmp(line, "# i3 config file (v4)", strlen("# i3 config file (v4)")) == 0 ||
72 strncasecmp(line, "workspace_layout", strlen("workspace_layout")) == 0) {
73 printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
77 /* if this is a bind statement, we can check the command */
78 if (strncasecmp(line, "bind", strlen("bind")) == 0) {
79 char *bind = strchr(line, ' ');
82 while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
86 if ((bind = strchr(bind, ' ')) == NULL)
88 while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
92 if (strncasecmp(bind, "layout", strlen("layout")) == 0 ||
93 strncasecmp(bind, "floating", strlen("floating")) == 0 ||
94 strncasecmp(bind, "workspace", strlen("workspace")) == 0 ||
95 strncasecmp(bind, "focus left", strlen("focus left")) == 0 ||
96 strncasecmp(bind, "focus right", strlen("focus right")) == 0 ||
97 strncasecmp(bind, "focus up", strlen("focus up")) == 0 ||
98 strncasecmp(bind, "focus down", strlen("focus down")) == 0 ||
99 strncasecmp(bind, "border normal", strlen("border normal")) == 0 ||
100 strncasecmp(bind, "border 1pixel", strlen("border 1pixel")) == 0 ||
101 strncasecmp(bind, "border borderless", strlen("border borderless")) == 0) {
102 printf("deciding for version 4 due to this line: %.*s\n", (int)(walk-line), line);
108 /* advance to the next line */
117 * Calls i3-migrate-config-to-v4 to migrate a configuration file (input
120 * Returns the converted config file or NULL if there was an error (for
121 * example the script could not be found in $PATH or the i3 executable’s
125 static char *migrate_config(char *input, off_t size) {
129 if (pipe(writepipe) != 0 ||
130 pipe(readpipe) != 0) {
131 warn("migrate_config: Could not create pipes");
137 warn("Could not fork()");
143 /* close writing end of writepipe, connect reading side to stdin */
145 dup2(writepipe[0], 0);
147 /* close reading end of readpipe, connect writing side to stdout */
149 dup2(readpipe[1], 1);
151 static char *argv[] = {
152 NULL, /* will be replaced by the executable path */
155 exec_i3_utility("i3-migrate-config-to-v4", argv);
160 /* close reading end of the writepipe (connected to the script’s stdin) */
163 /* write the whole config file to the pipe, the script will read everything
167 while (written < size) {
168 if ((ret = write(writepipe[1], input + written, size - written)) < 0) {
169 warn("Could not write to pipe");
176 /* close writing end of the readpipe (connected to the script’s stdout) */
179 /* read the script’s output */
180 int conv_size = 65535;
181 char *converted = malloc(conv_size);
184 if (read_bytes == conv_size) {
186 converted = realloc(converted, conv_size);
188 ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
190 warn("Cannot read from pipe");
197 /* get the returncode */
200 if (!WIFEXITED(status)) {
201 fprintf(stderr, "Child did not terminate normally, using old config file (will lead to broken behaviour)\n");
205 int returncode = WEXITSTATUS(status);
206 if (returncode != 0) {
207 fprintf(stderr, "Migration process exit code was != 0\n");
208 if (returncode == 2) {
209 fprintf(stderr, "could not start the migration script\n");
210 /* TODO: script was not found. tell the user to fix his system or create a v4 config */
211 } else if (returncode == 1) {
212 fprintf(stderr, "This already was a v4 config. Please add the following line to your config file:\n");
213 fprintf(stderr, "# i3 config file (v4)\n");
214 /* TODO: nag the user with a message to include a hint for i3 in his config file */
223 * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
224 * it exited (or could not be started, depending on the exit code).
227 static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
228 ev_child_stop(EV_A_ watcher);
229 if (!WIFEXITED(watcher->rstatus)) {
230 fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
234 int exitcode = WEXITSTATUS(watcher->rstatus);
235 printf("i3-nagbar process exited with status %d\n", exitcode);
237 fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
240 configerror_pid = -1;
243 /* We need ev >= 4 for the following code. Since it is not *that* important (it
244 * only makes sure that there are no i3-nagbar instances left behind) we still
245 * support old systems with libev 3. */
246 #if EV_VERSION_MAJOR >= 4
248 * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
249 * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
252 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
253 if (configerror_pid != -1) {
254 LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", configerror_pid);
255 kill(configerror_pid, SIGKILL);
261 * Starts an i3-nagbar process which alerts the user that his configuration
262 * file contains one or more errors. Also offers two buttons: One to launch an
263 * $EDITOR on the config file and another one to launch a $PAGER on the error
267 static void start_configerror_nagbar(const char *config_path) {
268 fprintf(stderr, "Would start i3-nagscreen now\n");
269 configerror_pid = fork();
270 if (configerror_pid == -1) {
271 warn("Could not fork()");
276 if (configerror_pid == 0) {
279 if (asprintf(&editaction, TERM_EMU " -e sh -c \"${EDITOR:-vi} \"%s\" && i3-msg reload\"", config_path) == -1)
281 if (asprintf(&pageraction, TERM_EMU " -e sh -c \"${PAGER:-less} \"%s\"\"", errorfilename) == -1)
284 NULL, /* will be replaced by the executable path */
286 "You have an error in your i3 config file!",
290 (errorfilename ? "-b" : NULL),
295 exec_i3_utility("i3-nagbar", argv);
299 /* install a child watcher */
300 ev_child *child = smalloc(sizeof(ev_child));
301 ev_child_init(child, &nagbar_exited, configerror_pid, 0);
302 ev_child_start(main_loop, child);
304 /* We need ev >= 4 for the following code. Since it is not *that* important (it
305 * only makes sure that there are no i3-nagbar instances left behind) we still
306 * support old systems with libev 3. */
307 #if EV_VERSION_MAJOR >= 4
308 /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
310 ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
311 ev_cleanup_init(cleanup, nagbar_cleanup);
312 ev_cleanup_start(main_loop, cleanup);
317 * Kills the configerror i3-nagbar process, if any.
319 * Called when reloading/restarting.
321 * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
322 * ev is assumed to handle it (reloading).
325 void kill_configerror_nagbar(bool wait_for_it) {
326 if (configerror_pid == -1)
329 if (kill(configerror_pid, SIGTERM) == -1)
330 warn("kill(configerror_nagbar) failed");
335 /* When restarting, we don’t enter the ev main loop anymore and after the
336 * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
337 * for us and we would end up with a <defunct> process. Therefore we
339 waitpid(configerror_pid, NULL, 0);
343 * Checks for duplicate key bindings (the same keycode or keysym is configured
344 * more than once). If a duplicate binding is found, a message is printed to
345 * stderr and the has_errors variable is set to true, which will start
349 static void check_for_duplicate_bindings(struct context *context) {
350 Binding *bind, *current;
351 TAILQ_FOREACH(current, bindings, bindings) {
352 TAILQ_FOREACH(bind, bindings, bindings) {
353 /* Abort when we reach the current keybinding, only check the
358 /* Check if one is using keysym while the other is using bindsym.
360 /* XXX: It should be checked at a later place (when translating the
361 * keysym to keycodes) if there are any duplicates */
362 if ((bind->symbol == NULL && current->symbol != NULL) ||
363 (bind->symbol != NULL && current->symbol == NULL))
366 /* If bind is NULL, current has to be NULL, too (see above).
367 * If the keycodes differ, it can't be a duplicate. */
368 if (bind->symbol != NULL &&
369 strcasecmp(bind->symbol, current->symbol) != 0)
372 /* Check if the keycodes or modifiers are different. If so, they
373 * can't be duplicate */
374 if (bind->keycode != current->keycode ||
375 bind->mods != current->mods)
377 context->has_errors = true;
378 if (current->keycode != 0) {
379 ELOG("Duplicate keybinding in config file:\n modmask %d with keycode %d, command \"%s\"\n",
380 current->mods, current->keycode, current->command);
382 ELOG("Duplicate keybinding in config file:\n modmask %d with keysym %s, command \"%s\"\n",
383 current->mods, current->symbol, current->command);
389 void parse_file(const char *f) {
390 SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
391 int fd, ret, read_bytes = 0;
395 char buffer[1026], key[512], value[512];
397 if ((fd = open(f, O_RDONLY)) == -1)
398 die("Could not open configuration file: %s\n", strerror(errno));
400 if (fstat(fd, &stbuf) == -1)
401 die("Could not fstat file: %s\n", strerror(errno));
403 buf = scalloc((stbuf.st_size + 1) * sizeof(char));
404 while (read_bytes < stbuf.st_size) {
405 if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
406 die("Could not read(): %s\n", strerror(errno));
410 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
411 die("Could not lseek: %s\n", strerror(errno));
413 if ((fstr = fdopen(fd, "r")) == NULL)
414 die("Could not fdopen: %s\n", strerror(errno));
416 while (!feof(fstr)) {
417 if (fgets(buffer, 1024, fstr) == NULL) {
420 die("Could not read configuration file\n");
423 /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
424 if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
425 key[0] == '#' || strlen(key) < 3)
428 if (strcasecmp(key, "set") == 0) {
429 if (value[0] != '$') {
430 ELOG("Malformed variable assignment, name has to start with $\n");
434 /* get key/value for this variable */
435 char *v_key = value, *v_value;
436 if ((v_value = strstr(value, " ")) == NULL &&
437 (v_value = strstr(value, "\t")) == NULL) {
438 ELOG("Malformed variable assignment, need a value\n");
444 struct Variable *new = scalloc(sizeof(struct Variable));
445 new->key = sstrdup(v_key);
446 new->value = sstrdup(v_value);
447 SLIST_INSERT_HEAD(&variables, new, variables);
448 DLOG("Got new variable %s = %s\n", v_key, v_value);
454 /* For every custom variable, see how often it occurs in the file and
455 * how much extra bytes it requires when replaced. */
456 struct Variable *current, *nearest;
458 /* We need to copy the buffer because we need to invalidate the
459 * variables (otherwise we will count them twice, which is bad when
460 * 'extra' is negative) */
461 char *bufcopy = sstrdup(buf);
462 SLIST_FOREACH(current, &variables, variables) {
463 int extra = (strlen(current->value) - strlen(current->key));
466 (next = strcasestr(bufcopy + (next - bufcopy), current->key)) != NULL;
467 next += strlen(current->key)) {
469 extra_bytes += extra;
474 /* Then, allocate a new buffer and copy the file over to the new one,
475 * but replace occurences of our variables */
476 char *walk = buf, *destwalk;
477 char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
479 while (walk < (buf + stbuf.st_size)) {
480 /* Find the next variable */
481 SLIST_FOREACH(current, &variables, variables)
482 current->next_match = strcasestr(walk, current->key);
484 int distance = stbuf.st_size;
485 SLIST_FOREACH(current, &variables, variables) {
486 if (current->next_match == NULL)
488 if ((current->next_match - walk) < distance) {
489 distance = (current->next_match - walk);
493 if (nearest == NULL) {
494 /* If there are no more variables, we just copy the rest */
495 strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
496 destwalk += (buf + stbuf.st_size) - walk;
500 /* Copy until the next variable, then copy its value */
501 strncpy(destwalk, walk, distance);
502 strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
503 walk += distance + strlen(nearest->key);
504 destwalk += distance + strlen(nearest->value);
508 /* analyze the string to find out whether this is an old config file (3.x)
509 * or a new config file (4.x). If it’s old, we run the converter script. */
510 int version = detect_version(buf);
512 /* We need to convert this v3 configuration */
513 char *converted = migrate_config(new, stbuf.st_size);
514 if (converted != NULL) {
516 printf("****************************************************************\n");
517 printf("NOTE: Automatically converted configuration file from v3 to v4.\n");
519 printf("Please convert your config file to v4. You can use this command:\n");
520 printf(" mv %s %s.O\n", f, f);
521 printf(" i3-migrate-config-to-v4 %s.O > %s\n", f, f);
522 printf("****************************************************************\n");
528 printf("**********************************************************************\n");
529 printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
530 printf("was not correctly installed on your system?\n");
531 printf("**********************************************************************\n");
536 /* now lex/parse it */
539 context = scalloc(sizeof(struct context));
540 context->filename = f;
542 if (yyparse() != 0) {
543 fprintf(stderr, "Could not parse configfile\n");
547 check_for_duplicate_bindings(context);
549 if (context->has_errors) {
550 start_configerror_nagbar(f);
554 FREE(context->line_copy);
559 while (!SLIST_EMPTY(&variables)) {
560 current = SLIST_FIRST(&variables);
562 FREE(current->value);
563 SLIST_REMOVE_HEAD(&variables, variables);
571 %lex-param { struct context *context }
576 uint32_t *single_color;
577 struct Colortriple *color;
579 struct Binding *binding;
582 %token <number> NUMBER "<number>"
583 %token <string> WORD "<word>"
584 %token <string> STR "<string>"
585 %token <string> STR_NG "<string (non-greedy)>"
586 %token <string> HEX "<hex>"
587 %token <string> OUTPUT "<RandR output>"
590 %token TOKCOMMENT "<comment>"
591 %token TOKFONT "font"
592 %token TOKBINDSYM "bindsym"
593 %token <number> MODIFIER "<modifier>"
594 %token TOKCONTROL "control"
595 %token TOKSHIFT "shift"
596 %token TOKFLOATING_MODIFIER "floating_modifier"
597 %token <string> QUOTEDSTRING "<quoted string>"
598 %token TOKWORKSPACE "workspace"
599 %token TOKOUTPUT "output"
600 %token TOKASSIGN "assign"
602 %token TOKIPCSOCKET "ipc_socket"
603 %token TOKRESTARTSTATE "restart_state"
604 %token TOKEXEC "exec"
605 %token TOKEXEC_ALWAYS "exec_always"
606 %token <single_color> TOKSINGLECOLOR
607 %token <color> TOKCOLOR
609 %token TOKMODE "mode"
610 %token TOK_ORIENTATION "default_orientation"
611 %token TOK_HORIZ "horizontal"
612 %token TOK_VERT "vertical"
613 %token TOK_AUTO "auto"
614 %token TOK_WORKSPACE_LAYOUT "workspace_layout"
615 %token TOKNEWWINDOW "new_window"
616 %token TOKNEWFLOAT "new_float"
617 %token TOK_NORMAL "normal"
618 %token TOK_NONE "none"
619 %token TOK_1PIXEL "1pixel"
620 %token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse"
621 %token TOK_FORCE_FOCUS_WRAPPING "force_focus_wrapping"
622 %token TOKWORKSPACEBAR "workspace_bar"
623 %token TOK_DEFAULT "default"
624 %token TOK_STACKING "stacking"
625 %token TOK_TABBED "tabbed"
626 %token <number> TOKSTACKLIMIT "stack-limit"
627 %token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
628 %token TOK_IGNORE "ignore"
629 %token TOK_LEAVE_FULLSCREEN "leave_fullscreen"
630 %token TOK_FOR_WINDOW "for_window"
632 %token TOK_MARK "mark"
633 %token TOK_CLASS "class"
634 %token TOK_INSTANCE "instance"
636 %token TOK_CON_ID "con_id"
637 %token TOK_TITLE "title"
639 %type <binding> binding
640 %type <binding> bindcode
641 %type <binding> bindsym
642 %type <number> binding_modifiers
643 %type <number> binding_modifier
644 %type <number> direction
645 %type <number> layout_mode
646 %type <number> border_style
647 %type <number> new_window
648 %type <number> new_float
649 %type <number> colorpixel
651 %type <number> popup_setting
652 %type <string> command
653 %type <string> word_or_number
654 %type <string> optional_workspace_name
655 %type <string> workspace_name
656 %type <string> window_class
674 | focus_follows_mouse
675 | force_focus_wrapping
688 | popup_during_fullscreen
702 TAILQ_INSERT_TAIL(bindings, $1, bindings);
707 TOKBINDCODE bindcode { $$ = $2; }
708 | TOKBINDSYM bindsym { $$ = $2; }
712 binding_modifiers NUMBER command
714 printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $3);
715 Binding *new = scalloc(sizeof(Binding));
726 binding_modifiers word_or_number command
728 printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $3);
729 Binding *new = scalloc(sizeof(Binding));
740 TOK_FOR_WINDOW match command
742 if (match_is_empty(¤t_match)) {
743 ELOG("Match is empty, ignoring this for_window statement\n");
746 printf("\t should execute command %s for the criteria mentioned above\n", $3);
747 Assignment *assignment = scalloc(sizeof(Assignment));
748 assignment->type = A_COMMAND;
749 assignment->match = current_match;
750 assignment->dest.command = $3;
751 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
756 | matchstart criteria matchend
758 printf("match parsed\n");
766 match_init(¤t_match);
773 printf("match specification finished\n");
785 printf("criteria: class = %s\n", $3);
786 current_match.class = regex_new($3);
789 | TOK_INSTANCE '=' STR
791 printf("criteria: instance = %s\n", $3);
792 current_match.instance = regex_new($3);
797 printf("criteria: id = %s\n", $3);
799 long parsed = strtol($3, &end, 10);
800 if (parsed == LONG_MIN ||
801 parsed == LONG_MAX ||
803 (end && *end != '\0')) {
804 ELOG("Could not parse con id \"%s\"\n", $3);
806 current_match.con_id = (Con*)parsed;
807 printf("id as int = %p\n", current_match.con_id);
812 printf("criteria: window id = %s\n", $3);
814 long parsed = strtol($3, &end, 10);
815 if (parsed == LONG_MIN ||
816 parsed == LONG_MAX ||
818 (end && *end != '\0')) {
819 ELOG("Could not parse window id \"%s\"\n", $3);
821 current_match.id = parsed;
822 printf("window id as int = %d\n", current_match.id);
827 printf("criteria: mark = %s\n", $3);
828 current_match.mark = regex_new($3);
833 printf("criteria: title = %s\n", $3);
834 current_match.title = regex_new($3);
845 asprintf(&$$, "%d", $1);
850 TOKMODE QUOTEDSTRING '{' modelines '}'
852 if (strcasecmp($2, "default") == 0) {
853 printf("You cannot use the name \"default\" for your mode\n");
856 printf("\t now in mode %s\n", $2);
857 printf("\t current bindings = %p\n", current_bindings);
859 TAILQ_FOREACH(binding, current_bindings, bindings) {
860 printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
861 binding->mods, binding->keycode, binding->symbol, binding->command);
864 struct Mode *mode = scalloc(sizeof(struct Mode));
866 mode->bindings = current_bindings;
867 current_bindings = NULL;
868 SLIST_INSERT_HEAD(&modes, mode, modes);
882 if (current_bindings == NULL) {
883 current_bindings = scalloc(sizeof(struct bindings_head));
884 TAILQ_INIT(current_bindings);
887 TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
892 TOKFLOATING_MODIFIER binding_modifiers
894 DLOG("floating modifier = %d\n", $2);
895 config.floating_modifier = $2;
900 TOK_ORIENTATION direction
902 DLOG("New containers should start with split direction %d\n", $2);
903 config.default_orientation = $2;
908 TOK_HORIZ { $$ = HORIZ; }
909 | TOK_VERT { $$ = VERT; }
910 | TOK_AUTO { $$ = NO_ORIENTATION; }
914 TOK_WORKSPACE_LAYOUT layout_mode
916 DLOG("new containers will be in mode %d\n", $2);
917 config.default_layout = $2;
920 /* We also need to change the layout of the already existing
921 * workspaces here. Workspaces may exist at this point because
922 * of the other directives which are modifying workspaces
923 * (setting the preferred screen or name). While the workspace
924 * objects are already created, they have never been used.
925 * Thus, the user very likely awaits the default container mode
926 * to trigger in this case, regardless of where it is inside
927 * his configuration file. */
929 TAILQ_FOREACH(ws, workspaces, workspaces) {
930 if (ws->table == NULL)
932 switch_layout_mode(global_conn,
934 config.container_mode);
938 | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
940 DLOG("stack-limit %d with val %d\n", $3, $4);
941 config.container_stack_limit = $3;
942 config.container_stack_limit_value = $4;
945 /* See the comment above */
947 TAILQ_FOREACH(ws, workspaces, workspaces) {
948 if (ws->table == NULL)
950 Container *con = ws->table[0][0];
951 con->stack_limit = config.container_stack_limit;
952 con->stack_limit_value = config.container_stack_limit_value;
959 TOK_DEFAULT { $$ = L_DEFAULT; }
960 | TOK_STACKING { $$ = L_STACKED; }
961 | TOK_TABBED { $$ = L_TABBED; }
965 TOKNEWWINDOW border_style
967 DLOG("new windows should start with border style %d\n", $2);
968 config.default_border = $2;
973 TOKNEWFLOAT border_style
975 DLOG("new floating windows should start with border style %d\n", $2);
976 config.default_floating_border = $2;
981 TOK_NORMAL { $$ = BS_NORMAL; }
982 | TOK_NONE { $$ = BS_NONE; }
983 | TOK_1PIXEL { $$ = BS_1PIXEL; }
993 DLOG("checking word \"%s\"\n", $1);
994 $$ = (strcasecmp($1, "yes") == 0 ||
995 strcasecmp($1, "true") == 0 ||
996 strcasecmp($1, "on") == 0 ||
997 strcasecmp($1, "enable") == 0 ||
998 strcasecmp($1, "active") == 0);
1002 focus_follows_mouse:
1003 TOKFOCUSFOLLOWSMOUSE bool
1005 DLOG("focus follows mouse = %d\n", $2);
1006 config.disable_focus_follows_mouse = !($2);
1010 force_focus_wrapping:
1011 TOK_FORCE_FOCUS_WRAPPING bool
1013 DLOG("force focus wrapping = %d\n", $2);
1014 config.force_focus_wrapping = $2;
1019 TOKWORKSPACEBAR bool
1021 DLOG("workspace bar = %d\n", $2);
1022 config.disable_workspace_bar = !($2);
1027 TOKWORKSPACE NUMBER TOKOUTPUT OUTPUT optional_workspace_name
1031 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1033 char *ws_name = NULL;
1035 asprintf(&ws_name, "%d", ws_num);
1040 DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
1041 /* Check for earlier assignments of the same workspace so that we
1042 * don’t have assignments of a single workspace to different
1044 struct Workspace_Assignment *assignment;
1045 bool duplicate = false;
1046 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
1047 if (strcasecmp(assignment->name, ws_name) == 0) {
1048 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
1050 assignment->output = $4;
1055 assignment = scalloc(sizeof(struct Workspace_Assignment));
1056 assignment->name = ws_name;
1057 assignment->output = $4;
1058 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
1062 | TOKWORKSPACE NUMBER workspace_name
1066 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1068 DLOG("workspace name to: %s\n", $3);
1070 if ($<string>3 != NULL) {
1071 workspace_set_name(workspace_get(ws_num - 1), $<string>3);
1079 optional_workspace_name:
1080 /* empty */ { $$ = NULL; }
1081 | workspace_name { $$ = $1; }
1085 QUOTEDSTRING { $$ = $1; }
1091 TOKASSIGN window_class STR
1093 /* This is the old, deprecated form of assignments. It’s provided for
1094 * compatibility in version (4.1, 4.2, 4.3) and will be removed
1095 * afterwards. It triggers an i3-nagbar warning starting from 4.1. */
1096 ELOG("You are using the old assign syntax (without criteria). "
1097 "Please see the User's Guide for the new syntax and fix "
1098 "your config file.\n");
1099 context->has_errors = true;
1100 printf("assignment of %s to *%s*\n", $2, $3);
1101 char *workspace = $3;
1102 char *criteria = $2;
1104 Assignment *assignment = scalloc(sizeof(Assignment));
1105 Match *match = &(assignment->match);
1108 char *separator = NULL;
1109 if ((separator = strchr(criteria, '/')) != NULL) {
1110 *(separator++) = '\0';
1112 if (asprintf(&pattern, "(?i)%s", separator) == -1) {
1113 ELOG("asprintf failed\n");
1116 match->title = regex_new(pattern);
1118 printf(" title = %s\n", separator);
1120 if (*criteria != '\0') {
1122 if (asprintf(&pattern, "(?i)%s", criteria) == -1) {
1123 ELOG("asprintf failed\n");
1126 match->class = regex_new(pattern);
1128 printf(" class = %s\n", criteria);
1132 /* Compatibility with older versions: If the assignment target starts
1133 * with ~, we create the equivalent of:
1135 * for_window [class="foo"] floating enable
1137 if (*workspace == '~') {
1139 if (*workspace == '\0') {
1140 /* This assignment was *only* for floating */
1141 assignment->type = A_COMMAND;
1142 assignment->dest.command = sstrdup("floating enable");
1143 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1146 /* Create a new assignment and continue afterwards */
1147 Assignment *floating = scalloc(sizeof(Assignment));
1148 match_copy(&(floating->match), match);
1149 floating->type = A_COMMAND;
1150 floating->dest.command = sstrdup("floating enable");
1151 TAILQ_INSERT_TAIL(&assignments, floating, assignments);
1155 assignment->type = A_TO_WORKSPACE;
1156 assignment->dest.workspace = workspace;
1157 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1159 | TOKASSIGN match STR
1161 if (match_is_empty(¤t_match)) {
1162 ELOG("Match is empty, ignoring this assignment\n");
1165 printf("new assignment, using above criteria, to workspace %s\n", $3);
1166 Assignment *assignment = scalloc(sizeof(Assignment));
1167 assignment->match = current_match;
1168 assignment->type = A_TO_WORKSPACE;
1169 assignment->dest.workspace = $3;
1170 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1182 config.ipc_socket_path = $2;
1189 config.restart_state_path = $2;
1196 struct Autostart *new = smalloc(sizeof(struct Autostart));
1198 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
1205 struct Autostart *new = smalloc(sizeof(struct Autostart));
1207 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
1214 ELOG("The terminal option is DEPRECATED and has no effect. "
1215 "Please remove it from your configuration file.\n");
1222 config.font = load_font($2, true);
1223 printf("font %s\n", $2);
1229 TOKSINGLECOLOR colorpixel
1231 uint32_t *dest = $1;
1237 TOKCOLOR colorpixel colorpixel colorpixel
1239 struct Colortriple *dest = $1;
1242 dest->background = $3;
1251 if (asprintf(&hex, "#%s", $2) == -1)
1254 $$ = get_colorpixel(hex);
1261 /* NULL */ { $$ = 0; }
1263 | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
1264 | binding_modifiers '+' { $$ = $1; }
1268 MODIFIER { $$ = $1; }
1269 | TOKCONTROL { $$ = BIND_CONTROL; }
1270 | TOKSHIFT { $$ = BIND_SHIFT; }
1273 popup_during_fullscreen:
1274 TOK_POPUP_DURING_FULLSCREEN popup_setting
1276 DLOG("popup_during_fullscreen setting: %d\n", $2);
1277 config.popup_during_fullscreen = $2;
1282 TOK_IGNORE { $$ = PDF_IGNORE; }
1283 | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; }