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;
244 * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
245 * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
248 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
249 if (configerror_pid != -1) {
250 LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", configerror_pid);
251 kill(configerror_pid, SIGKILL);
256 * Starts an i3-nagbar process which alerts the user that his configuration
257 * file contains one or more errors. Also offers two buttons: One to launch an
258 * $EDITOR on the config file and another one to launch a $PAGER on the error
262 static void start_configerror_nagbar(const char *config_path) {
263 fprintf(stderr, "Would start i3-nagscreen now\n");
264 configerror_pid = fork();
265 if (configerror_pid == -1) {
266 warn("Could not fork()");
271 if (configerror_pid == 0) {
274 if (asprintf(&editaction, TERM_EMU " -e sh -c \"${EDITOR:-vi} \"%s\" && i3-msg reload\"", config_path) == -1)
276 if (asprintf(&pageraction, TERM_EMU " -e sh -c \"${PAGER:-less} \"%s\"\"", errorfilename) == -1)
279 NULL, /* will be replaced by the executable path */
281 "You have an error in your i3 config file!",
285 (errorfilename ? "-b" : NULL),
290 exec_i3_utility("i3-nagbar", argv);
294 /* install a child watcher */
295 ev_child *child = smalloc(sizeof(ev_child));
296 ev_child_init(child, &nagbar_exited, configerror_pid, 0);
297 ev_child_start(main_loop, child);
299 /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
301 ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
302 ev_cleanup_init(cleanup, nagbar_cleanup);
303 ev_cleanup_start(main_loop, cleanup);
307 * Kills the configerror i3-nagbar process, if any.
309 * Called when reloading/restarting.
311 * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
312 * ev is assumed to handle it (reloading).
315 void kill_configerror_nagbar(bool wait_for_it) {
316 if (configerror_pid == -1)
319 if (kill(configerror_pid, SIGTERM) == -1)
320 warn("kill(configerror_nagbar) failed");
325 /* When restarting, we don’t enter the ev main loop anymore and after the
326 * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
327 * for us and we would end up with a <defunct> process. Therefore we
329 waitpid(configerror_pid, NULL, 0);
333 * Checks for duplicate key bindings (the same keycode or keysym is configured
334 * more than once). If a duplicate binding is found, a message is printed to
335 * stderr and the has_errors variable is set to true, which will start
339 static void check_for_duplicate_bindings(struct context *context) {
340 Binding *bind, *current;
341 TAILQ_FOREACH(current, bindings, bindings) {
342 TAILQ_FOREACH(bind, bindings, bindings) {
343 /* Abort when we reach the current keybinding, only check the
348 /* Check if one is using keysym while the other is using bindsym.
350 /* XXX: It should be checked at a later place (when translating the
351 * keysym to keycodes) if there are any duplicates */
352 if ((bind->symbol == NULL && current->symbol != NULL) ||
353 (bind->symbol != NULL && current->symbol == NULL))
356 /* If bind is NULL, current has to be NULL, too (see above).
357 * If the keycodes differ, it can't be a duplicate. */
358 if (bind->symbol != NULL &&
359 strcasecmp(bind->symbol, current->symbol) != 0)
362 /* Check if the keycodes or modifiers are different. If so, they
363 * can't be duplicate */
364 if (bind->keycode != current->keycode ||
365 bind->mods != current->mods)
367 context->has_errors = true;
368 if (current->keycode != 0) {
369 ELOG("Duplicate keybinding in config file:\n modmask %d with keycode %d, command \"%s\"\n",
370 current->mods, current->keycode, current->command);
372 ELOG("Duplicate keybinding in config file:\n modmask %d with keysym %s, command \"%s\"\n",
373 current->mods, current->symbol, current->command);
379 void parse_file(const char *f) {
380 SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
381 int fd, ret, read_bytes = 0;
385 char buffer[1026], key[512], value[512];
387 if ((fd = open(f, O_RDONLY)) == -1)
388 die("Could not open configuration file: %s\n", strerror(errno));
390 if (fstat(fd, &stbuf) == -1)
391 die("Could not fstat file: %s\n", strerror(errno));
393 buf = scalloc((stbuf.st_size + 1) * sizeof(char));
394 while (read_bytes < stbuf.st_size) {
395 if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
396 die("Could not read(): %s\n", strerror(errno));
400 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
401 die("Could not lseek: %s\n", strerror(errno));
403 if ((fstr = fdopen(fd, "r")) == NULL)
404 die("Could not fdopen: %s\n", strerror(errno));
406 while (!feof(fstr)) {
407 if (fgets(buffer, 1024, fstr) == NULL) {
410 die("Could not read configuration file\n");
413 /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
414 if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
415 key[0] == '#' || strlen(key) < 3)
418 if (strcasecmp(key, "set") == 0) {
419 if (value[0] != '$') {
420 ELOG("Malformed variable assignment, name has to start with $\n");
424 /* get key/value for this variable */
425 char *v_key = value, *v_value;
426 if ((v_value = strstr(value, " ")) == NULL &&
427 (v_value = strstr(value, "\t")) == NULL) {
428 ELOG("Malformed variable assignment, need a value\n");
434 struct Variable *new = scalloc(sizeof(struct Variable));
435 new->key = sstrdup(v_key);
436 new->value = sstrdup(v_value);
437 SLIST_INSERT_HEAD(&variables, new, variables);
438 DLOG("Got new variable %s = %s\n", v_key, v_value);
444 /* For every custom variable, see how often it occurs in the file and
445 * how much extra bytes it requires when replaced. */
446 struct Variable *current, *nearest;
448 /* We need to copy the buffer because we need to invalidate the
449 * variables (otherwise we will count them twice, which is bad when
450 * 'extra' is negative) */
451 char *bufcopy = sstrdup(buf);
452 SLIST_FOREACH(current, &variables, variables) {
453 int extra = (strlen(current->value) - strlen(current->key));
456 (next = strcasestr(bufcopy + (next - bufcopy), current->key)) != NULL;
457 next += strlen(current->key)) {
459 extra_bytes += extra;
464 /* Then, allocate a new buffer and copy the file over to the new one,
465 * but replace occurences of our variables */
466 char *walk = buf, *destwalk;
467 char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
469 while (walk < (buf + stbuf.st_size)) {
470 /* Find the next variable */
471 SLIST_FOREACH(current, &variables, variables)
472 current->next_match = strcasestr(walk, current->key);
474 int distance = stbuf.st_size;
475 SLIST_FOREACH(current, &variables, variables) {
476 if (current->next_match == NULL)
478 if ((current->next_match - walk) < distance) {
479 distance = (current->next_match - walk);
483 if (nearest == NULL) {
484 /* If there are no more variables, we just copy the rest */
485 strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
486 destwalk += (buf + stbuf.st_size) - walk;
490 /* Copy until the next variable, then copy its value */
491 strncpy(destwalk, walk, distance);
492 strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
493 walk += distance + strlen(nearest->key);
494 destwalk += distance + strlen(nearest->value);
498 /* analyze the string to find out whether this is an old config file (3.x)
499 * or a new config file (4.x). If it’s old, we run the converter script. */
500 int version = detect_version(buf);
502 /* We need to convert this v3 configuration */
503 char *converted = migrate_config(new, stbuf.st_size);
504 if (converted != NULL) {
506 printf("****************************************************************\n");
507 printf("NOTE: Automatically converted configuration file from v3 to v4.\n");
509 printf("Please convert your config file to v4. You can use this command:\n");
510 printf(" mv %s %s.O\n", f, f);
511 printf(" i3-migrate-config-to-v4 %s.O > %s\n", f, f);
512 printf("****************************************************************\n");
518 printf("**********************************************************************\n");
519 printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
520 printf("was not correctly installed on your system?\n");
521 printf("**********************************************************************\n");
526 /* now lex/parse it */
529 context = scalloc(sizeof(struct context));
530 context->filename = f;
532 if (yyparse() != 0) {
533 fprintf(stderr, "Could not parse configfile\n");
537 check_for_duplicate_bindings(context);
539 if (context->has_errors) {
540 start_configerror_nagbar(f);
544 FREE(context->line_copy);
549 while (!SLIST_EMPTY(&variables)) {
550 current = SLIST_FIRST(&variables);
552 FREE(current->value);
553 SLIST_REMOVE_HEAD(&variables, variables);
561 %lex-param { struct context *context }
566 uint32_t *single_color;
567 struct Colortriple *color;
569 struct Binding *binding;
572 %token <number> NUMBER "<number>"
573 %token <string> WORD "<word>"
574 %token <string> STR "<string>"
575 %token <string> STR_NG "<string (non-greedy)>"
576 %token <string> HEX "<hex>"
577 %token <string> OUTPUT "<RandR output>"
580 %token TOKCOMMENT "<comment>"
581 %token TOKFONT "font"
582 %token TOKBINDSYM "bindsym"
583 %token <number> MODIFIER "<modifier>"
584 %token TOKCONTROL "control"
585 %token TOKSHIFT "shift"
586 %token TOKFLOATING_MODIFIER "floating_modifier"
587 %token <string> QUOTEDSTRING "<quoted string>"
588 %token TOKWORKSPACE "workspace"
589 %token TOKOUTPUT "output"
590 %token TOKASSIGN "assign"
592 %token TOKIPCSOCKET "ipc_socket"
593 %token TOKRESTARTSTATE "restart_state"
594 %token TOKEXEC "exec"
595 %token TOKEXEC_ALWAYS "exec_always"
596 %token <single_color> TOKSINGLECOLOR
597 %token <color> TOKCOLOR
599 %token TOKMODE "mode"
600 %token TOK_ORIENTATION "default_orientation"
601 %token TOK_HORIZ "horizontal"
602 %token TOK_VERT "vertical"
603 %token TOK_AUTO "auto"
604 %token TOK_WORKSPACE_LAYOUT "workspace_layout"
605 %token TOKNEWWINDOW "new_window"
606 %token TOKNEWFLOAT "new_float"
607 %token TOK_NORMAL "normal"
608 %token TOK_NONE "none"
609 %token TOK_1PIXEL "1pixel"
610 %token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse"
611 %token TOK_FORCE_FOCUS_WRAPPING "force_focus_wrapping"
612 %token TOKWORKSPACEBAR "workspace_bar"
613 %token TOK_DEFAULT "default"
614 %token TOK_STACKING "stacking"
615 %token TOK_TABBED "tabbed"
616 %token <number> TOKSTACKLIMIT "stack-limit"
617 %token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
618 %token TOK_IGNORE "ignore"
619 %token TOK_LEAVE_FULLSCREEN "leave_fullscreen"
620 %token TOK_FOR_WINDOW "for_window"
622 %token TOK_MARK "mark"
623 %token TOK_CLASS "class"
624 %token TOK_INSTANCE "instance"
626 %token TOK_CON_ID "con_id"
627 %token TOK_TITLE "title"
629 %type <binding> binding
630 %type <binding> bindcode
631 %type <binding> bindsym
632 %type <number> binding_modifiers
633 %type <number> binding_modifier
634 %type <number> direction
635 %type <number> layout_mode
636 %type <number> border_style
637 %type <number> new_window
638 %type <number> new_float
639 %type <number> colorpixel
641 %type <number> popup_setting
642 %type <string> command
643 %type <string> word_or_number
644 %type <string> optional_workspace_name
645 %type <string> workspace_name
646 %type <string> window_class
664 | focus_follows_mouse
665 | force_focus_wrapping
678 | popup_during_fullscreen
692 TAILQ_INSERT_TAIL(bindings, $1, bindings);
697 TOKBINDCODE bindcode { $$ = $2; }
698 | TOKBINDSYM bindsym { $$ = $2; }
702 binding_modifiers NUMBER command
704 printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $3);
705 Binding *new = scalloc(sizeof(Binding));
716 binding_modifiers word_or_number command
718 printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $3);
719 Binding *new = scalloc(sizeof(Binding));
730 TOK_FOR_WINDOW match command
732 if (match_is_empty(¤t_match)) {
733 ELOG("Match is empty, ignoring this for_window statement\n");
736 printf("\t should execute command %s for the criteria mentioned above\n", $3);
737 Assignment *assignment = scalloc(sizeof(Assignment));
738 assignment->type = A_COMMAND;
739 assignment->match = current_match;
740 assignment->dest.command = $3;
741 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
746 | matchstart criteria matchend
748 printf("match parsed\n");
756 match_init(¤t_match);
763 printf("match specification finished\n");
775 printf("criteria: class = %s\n", $3);
776 current_match.class = regex_new($3);
779 | TOK_INSTANCE '=' STR
781 printf("criteria: instance = %s\n", $3);
782 current_match.instance = regex_new($3);
787 printf("criteria: id = %s\n", $3);
789 long parsed = strtol($3, &end, 10);
790 if (parsed == LONG_MIN ||
791 parsed == LONG_MAX ||
793 (end && *end != '\0')) {
794 ELOG("Could not parse con id \"%s\"\n", $3);
796 current_match.con_id = (Con*)parsed;
797 printf("id as int = %p\n", current_match.con_id);
802 printf("criteria: window id = %s\n", $3);
804 long parsed = strtol($3, &end, 10);
805 if (parsed == LONG_MIN ||
806 parsed == LONG_MAX ||
808 (end && *end != '\0')) {
809 ELOG("Could not parse window id \"%s\"\n", $3);
811 current_match.id = parsed;
812 printf("window id as int = %d\n", current_match.id);
817 printf("criteria: mark = %s\n", $3);
818 current_match.mark = regex_new($3);
823 printf("criteria: title = %s\n", $3);
824 current_match.title = regex_new($3);
835 asprintf(&$$, "%d", $1);
840 TOKMODE QUOTEDSTRING '{' modelines '}'
842 if (strcasecmp($2, "default") == 0) {
843 printf("You cannot use the name \"default\" for your mode\n");
846 printf("\t now in mode %s\n", $2);
847 printf("\t current bindings = %p\n", current_bindings);
849 TAILQ_FOREACH(binding, current_bindings, bindings) {
850 printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
851 binding->mods, binding->keycode, binding->symbol, binding->command);
854 struct Mode *mode = scalloc(sizeof(struct Mode));
856 mode->bindings = current_bindings;
857 current_bindings = NULL;
858 SLIST_INSERT_HEAD(&modes, mode, modes);
872 if (current_bindings == NULL) {
873 current_bindings = scalloc(sizeof(struct bindings_head));
874 TAILQ_INIT(current_bindings);
877 TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
882 TOKFLOATING_MODIFIER binding_modifiers
884 DLOG("floating modifier = %d\n", $2);
885 config.floating_modifier = $2;
890 TOK_ORIENTATION direction
892 DLOG("New containers should start with split direction %d\n", $2);
893 config.default_orientation = $2;
898 TOK_HORIZ { $$ = HORIZ; }
899 | TOK_VERT { $$ = VERT; }
900 | TOK_AUTO { $$ = NO_ORIENTATION; }
904 TOK_WORKSPACE_LAYOUT layout_mode
906 DLOG("new containers will be in mode %d\n", $2);
907 config.default_layout = $2;
910 /* We also need to change the layout of the already existing
911 * workspaces here. Workspaces may exist at this point because
912 * of the other directives which are modifying workspaces
913 * (setting the preferred screen or name). While the workspace
914 * objects are already created, they have never been used.
915 * Thus, the user very likely awaits the default container mode
916 * to trigger in this case, regardless of where it is inside
917 * his configuration file. */
919 TAILQ_FOREACH(ws, workspaces, workspaces) {
920 if (ws->table == NULL)
922 switch_layout_mode(global_conn,
924 config.container_mode);
928 | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
930 DLOG("stack-limit %d with val %d\n", $3, $4);
931 config.container_stack_limit = $3;
932 config.container_stack_limit_value = $4;
935 /* See the comment above */
937 TAILQ_FOREACH(ws, workspaces, workspaces) {
938 if (ws->table == NULL)
940 Container *con = ws->table[0][0];
941 con->stack_limit = config.container_stack_limit;
942 con->stack_limit_value = config.container_stack_limit_value;
949 TOK_DEFAULT { $$ = L_DEFAULT; }
950 | TOK_STACKING { $$ = L_STACKED; }
951 | TOK_TABBED { $$ = L_TABBED; }
955 TOKNEWWINDOW border_style
957 DLOG("new windows should start with border style %d\n", $2);
958 config.default_border = $2;
963 TOKNEWFLOAT border_style
965 DLOG("new floating windows should start with border style %d\n", $2);
966 config.default_floating_border = $2;
971 TOK_NORMAL { $$ = BS_NORMAL; }
972 | TOK_NONE { $$ = BS_NONE; }
973 | TOK_1PIXEL { $$ = BS_1PIXEL; }
983 DLOG("checking word \"%s\"\n", $1);
984 $$ = (strcasecmp($1, "yes") == 0 ||
985 strcasecmp($1, "true") == 0 ||
986 strcasecmp($1, "on") == 0 ||
987 strcasecmp($1, "enable") == 0 ||
988 strcasecmp($1, "active") == 0);
993 TOKFOCUSFOLLOWSMOUSE bool
995 DLOG("focus follows mouse = %d\n", $2);
996 config.disable_focus_follows_mouse = !($2);
1000 force_focus_wrapping:
1001 TOK_FORCE_FOCUS_WRAPPING bool
1003 DLOG("force focus wrapping = %d\n", $2);
1004 config.force_focus_wrapping = $2;
1009 TOKWORKSPACEBAR bool
1011 DLOG("workspace bar = %d\n", $2);
1012 config.disable_workspace_bar = !($2);
1017 TOKWORKSPACE NUMBER TOKOUTPUT OUTPUT optional_workspace_name
1021 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1023 char *ws_name = NULL;
1025 asprintf(&ws_name, "%d", ws_num);
1030 DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
1031 /* Check for earlier assignments of the same workspace so that we
1032 * don’t have assignments of a single workspace to different
1034 struct Workspace_Assignment *assignment;
1035 bool duplicate = false;
1036 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
1037 if (strcasecmp(assignment->name, ws_name) == 0) {
1038 ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
1040 assignment->output = $4;
1045 assignment = scalloc(sizeof(struct Workspace_Assignment));
1046 assignment->name = ws_name;
1047 assignment->output = $4;
1048 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
1052 | TOKWORKSPACE NUMBER workspace_name
1056 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1058 DLOG("workspace name to: %s\n", $3);
1060 if ($<string>3 != NULL) {
1061 workspace_set_name(workspace_get(ws_num - 1), $<string>3);
1069 optional_workspace_name:
1070 /* empty */ { $$ = NULL; }
1071 | workspace_name { $$ = $1; }
1075 QUOTEDSTRING { $$ = $1; }
1081 TOKASSIGN window_class STR
1083 /* This is the old, deprecated form of assignments. It’s provided for
1084 * compatibility in version (4.1, 4.2, 4.3) and will be removed
1085 * afterwards. It triggers an i3-nagbar warning starting from 4.1. */
1086 ELOG("You are using the old assign syntax (without criteria). "
1087 "Please see the User's Guide for the new syntax and fix "
1088 "your config file.\n");
1089 context->has_errors = true;
1090 printf("assignment of %s to *%s*\n", $2, $3);
1091 char *workspace = $3;
1092 char *criteria = $2;
1094 Assignment *assignment = scalloc(sizeof(Assignment));
1095 Match *match = &(assignment->match);
1098 char *separator = NULL;
1099 if ((separator = strchr(criteria, '/')) != NULL) {
1100 *(separator++) = '\0';
1102 if (asprintf(&pattern, "(?i)%s", separator) == -1) {
1103 ELOG("asprintf failed\n");
1106 match->title = regex_new(pattern);
1108 printf(" title = %s\n", separator);
1110 if (*criteria != '\0') {
1112 if (asprintf(&pattern, "(?i)%s", criteria) == -1) {
1113 ELOG("asprintf failed\n");
1116 match->class = regex_new(pattern);
1118 printf(" class = %s\n", criteria);
1122 /* Compatibility with older versions: If the assignment target starts
1123 * with ~, we create the equivalent of:
1125 * for_window [class="foo"] floating enable
1127 if (*workspace == '~') {
1129 if (*workspace == '\0') {
1130 /* This assignment was *only* for floating */
1131 assignment->type = A_COMMAND;
1132 assignment->dest.command = sstrdup("floating enable");
1133 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1136 /* Create a new assignment and continue afterwards */
1137 Assignment *floating = scalloc(sizeof(Assignment));
1138 match_copy(&(floating->match), match);
1139 floating->type = A_COMMAND;
1140 floating->dest.command = sstrdup("floating enable");
1141 TAILQ_INSERT_TAIL(&assignments, floating, assignments);
1145 assignment->type = A_TO_WORKSPACE;
1146 assignment->dest.workspace = workspace;
1147 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1149 | TOKASSIGN match STR
1151 if (match_is_empty(¤t_match)) {
1152 ELOG("Match is empty, ignoring this assignment\n");
1155 printf("new assignment, using above criteria, to workspace %s\n", $3);
1156 Assignment *assignment = scalloc(sizeof(Assignment));
1157 assignment->match = current_match;
1158 assignment->type = A_TO_WORKSPACE;
1159 assignment->dest.workspace = $3;
1160 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1172 config.ipc_socket_path = $2;
1179 config.restart_state_path = $2;
1186 struct Autostart *new = smalloc(sizeof(struct Autostart));
1188 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
1195 struct Autostart *new = smalloc(sizeof(struct Autostart));
1197 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
1204 ELOG("The terminal option is DEPRECATED and has no effect. "
1205 "Please remove it from your configuration file.\n");
1212 config.font = load_font($2, true);
1213 printf("font %s\n", $2);
1219 TOKSINGLECOLOR colorpixel
1221 uint32_t *dest = $1;
1227 TOKCOLOR colorpixel colorpixel colorpixel
1229 struct Colortriple *dest = $1;
1232 dest->background = $3;
1241 if (asprintf(&hex, "#%s", $2) == -1)
1244 $$ = get_colorpixel(hex);
1251 /* NULL */ { $$ = 0; }
1253 | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
1254 | binding_modifiers '+' { $$ = $1; }
1258 MODIFIER { $$ = $1; }
1259 | TOKCONTROL { $$ = BIND_CONTROL; }
1260 | TOKSHIFT { $$ = BIND_SHIFT; }
1263 popup_during_fullscreen:
1264 TOK_POPUP_DURING_FULLSCREEN popup_setting
1266 DLOG("popup_during_fullscreen setting: %d\n", $2);
1267 config.popup_during_fullscreen = $2;
1272 TOK_IGNORE { $$ = PDF_IGNORE; }
1273 | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; }