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");
196 /* get the returncode */
199 if (!WIFEXITED(status)) {
200 fprintf(stderr, "Child did not terminate normally, using old config file (will lead to broken behaviour)\n");
204 int returncode = WEXITSTATUS(status);
205 if (returncode != 0) {
206 fprintf(stderr, "Migration process exit code was != 0\n");
207 if (returncode == 2) {
208 fprintf(stderr, "could not start the migration script\n");
209 /* TODO: script was not found. tell the user to fix his system or create a v4 config */
210 } else if (returncode == 1) {
211 fprintf(stderr, "This already was a v4 config. Please add the following line to your config file:\n");
212 fprintf(stderr, "# i3 config file (v4)\n");
213 /* TODO: nag the user with a message to include a hint for i3 in his config file */
222 * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
223 * it exited (or could not be started, depending on the exit code).
226 static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
227 ev_child_stop(EV_A_ watcher);
228 if (!WIFEXITED(watcher->rstatus)) {
229 fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
233 int exitcode = WEXITSTATUS(watcher->rstatus);
234 printf("i3-nagbar process exited with status %d\n", exitcode);
236 fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
239 configerror_pid = -1;
243 * Starts an i3-nagbar process which alerts the user that his configuration
244 * file contains one or more errors. Also offers two buttons: One to launch an
245 * $EDITOR on the config file and another one to launch a $PAGER on the error
249 static void start_configerror_nagbar(const char *config_path) {
250 fprintf(stderr, "Would start i3-nagscreen now\n");
251 configerror_pid = fork();
252 if (configerror_pid == -1) {
253 warn("Could not fork()");
258 if (configerror_pid == 0) {
261 if (asprintf(&editaction, TERM_EMU " -e sh -c \"${EDITOR:-vi} \"%s\" && i3-msg reload\"", config_path) == -1)
263 if (asprintf(&pageraction, TERM_EMU " -e sh -c \"${PAGER:-less} \"%s\"\"", errorfilename) == -1)
266 NULL, /* will be replaced by the executable path */
268 "You have an error in your i3 config file!",
272 (errorfilename ? "-b" : NULL),
277 exec_i3_utility("i3-nagbar", argv);
281 /* install a child watcher */
282 ev_child *child = smalloc(sizeof(ev_child));
283 ev_child_init(child, &nagbar_exited, configerror_pid, 0);
284 ev_child_start(main_loop, child);
288 * Kills the configerror i3-nagbar process, if any.
290 * Called when reloading/restarting.
292 * If wait_for_it is set (restarting), this function will waitpid(), otherwise,
293 * ev is assumed to handle it (reloading).
296 void kill_configerror_nagbar(bool wait_for_it) {
297 if (configerror_pid == -1)
300 if (kill(configerror_pid, SIGTERM) == -1)
301 warn("kill(configerror_nagbar) failed");
306 /* When restarting, we don’t enter the ev main loop anymore and after the
307 * exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
308 * for us and we would end up with a <defunct> process. Therefore we
310 waitpid(configerror_pid, NULL, 0);
314 * Checks for duplicate key bindings (the same keycode or keysym is configured
315 * more than once). If a duplicate binding is found, a message is printed to
316 * stderr and the has_errors variable is set to true, which will start
320 static void check_for_duplicate_bindings(struct context *context) {
321 Binding *bind, *current;
322 TAILQ_FOREACH(current, bindings, bindings) {
323 TAILQ_FOREACH(bind, bindings, bindings) {
324 /* Abort when we reach the current keybinding, only check the
329 /* Check if one is using keysym while the other is using bindsym.
331 /* XXX: It should be checked at a later place (when translating the
332 * keysym to keycodes) if there are any duplicates */
333 if ((bind->symbol == NULL && current->symbol != NULL) ||
334 (bind->symbol != NULL && current->symbol == NULL))
337 /* If bind is NULL, current has to be NULL, too (see above).
338 * If the keycodes differ, it can't be a duplicate. */
339 if (bind->symbol != NULL &&
340 strcasecmp(bind->symbol, current->symbol) != 0)
343 /* Check if the keycodes or modifiers are different. If so, they
344 * can't be duplicate */
345 if (bind->keycode != current->keycode ||
346 bind->mods != current->mods)
348 context->has_errors = true;
349 if (current->keycode != 0) {
350 ELOG("Duplicate keybinding in config file:\n modmask %d with keycode %d, command \"%s\"\n",
351 current->mods, current->keycode, current->command);
353 ELOG("Duplicate keybinding in config file:\n modmask %d with keysym %s, command \"%s\"\n",
354 current->mods, current->symbol, current->command);
360 void parse_file(const char *f) {
361 SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables);
362 int fd, ret, read_bytes = 0;
366 char buffer[1026], key[512], value[512];
368 if ((fd = open(f, O_RDONLY)) == -1)
369 die("Could not open configuration file: %s\n", strerror(errno));
371 if (fstat(fd, &stbuf) == -1)
372 die("Could not fstat file: %s\n", strerror(errno));
374 buf = scalloc((stbuf.st_size + 1) * sizeof(char));
375 while (read_bytes < stbuf.st_size) {
376 if ((ret = read(fd, buf + read_bytes, (stbuf.st_size - read_bytes))) < 0)
377 die("Could not read(): %s\n", strerror(errno));
381 if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
382 die("Could not lseek: %s\n", strerror(errno));
384 if ((fstr = fdopen(fd, "r")) == NULL)
385 die("Could not fdopen: %s\n", strerror(errno));
387 while (!feof(fstr)) {
388 if (fgets(buffer, 1024, fstr) == NULL) {
391 die("Could not read configuration file\n");
394 /* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
395 if (sscanf(buffer, "%s %[^\n]", key, value) < 1 ||
396 key[0] == '#' || strlen(key) < 3)
399 if (strcasecmp(key, "set") == 0) {
401 die("Malformed variable assignment, name has to start with $\n");
403 /* get key/value for this variable */
404 char *v_key = value, *v_value;
405 if ((v_value = strstr(value, " ")) == NULL)
406 die("Malformed variable assignment, need a value\n");
410 struct Variable *new = scalloc(sizeof(struct Variable));
411 new->key = sstrdup(v_key);
412 new->value = sstrdup(v_value);
413 SLIST_INSERT_HEAD(&variables, new, variables);
414 DLOG("Got new variable %s = %s\n", v_key, v_value);
420 /* For every custom variable, see how often it occurs in the file and
421 * how much extra bytes it requires when replaced. */
422 struct Variable *current, *nearest;
424 /* We need to copy the buffer because we need to invalidate the
425 * variables (otherwise we will count them twice, which is bad when
426 * 'extra' is negative) */
427 char *bufcopy = sstrdup(buf);
428 SLIST_FOREACH(current, &variables, variables) {
429 int extra = (strlen(current->value) - strlen(current->key));
432 (next = strcasestr(bufcopy + (next - bufcopy), current->key)) != NULL;
433 next += strlen(current->key)) {
435 extra_bytes += extra;
440 /* Then, allocate a new buffer and copy the file over to the new one,
441 * but replace occurences of our variables */
442 char *walk = buf, *destwalk;
443 char *new = smalloc((stbuf.st_size + extra_bytes + 1) * sizeof(char));
445 while (walk < (buf + stbuf.st_size)) {
446 /* Find the next variable */
447 SLIST_FOREACH(current, &variables, variables)
448 current->next_match = strcasestr(walk, current->key);
450 int distance = stbuf.st_size;
451 SLIST_FOREACH(current, &variables, variables) {
452 if (current->next_match == NULL)
454 if ((current->next_match - walk) < distance) {
455 distance = (current->next_match - walk);
459 if (nearest == NULL) {
460 /* If there are no more variables, we just copy the rest */
461 strncpy(destwalk, walk, (buf + stbuf.st_size) - walk);
462 destwalk += (buf + stbuf.st_size) - walk;
466 /* Copy until the next variable, then copy its value */
467 strncpy(destwalk, walk, distance);
468 strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
469 walk += distance + strlen(nearest->key);
470 destwalk += distance + strlen(nearest->value);
474 /* analyze the string to find out whether this is an old config file (3.x)
475 * or a new config file (4.x). If it’s old, we run the converter script. */
476 int version = detect_version(buf);
478 /* We need to convert this v3 configuration */
479 char *converted = migrate_config(new, stbuf.st_size);
480 if (converted != NULL) {
482 printf("****************************************************************\n");
483 printf("NOTE: Automatically converted configuration file from v3 to v4.\n");
485 printf("Please convert your config file to v4. You can use this command:\n");
486 printf(" mv %s %s.O\n", f, f);
487 printf(" i3-migrate-config-to-v4 %s.O > %s\n", f, f);
488 printf("****************************************************************\n");
494 printf("**********************************************************************\n");
495 printf("ERROR: Could not convert config file. Maybe i3-migrate-config-to-v4\n");
496 printf("was not correctly installed on your system?\n");
497 printf("**********************************************************************\n");
502 /* now lex/parse it */
505 context = scalloc(sizeof(struct context));
506 context->filename = f;
508 if (yyparse() != 0) {
509 fprintf(stderr, "Could not parse configfile\n");
513 check_for_duplicate_bindings(context);
515 if (context->has_errors) {
516 start_configerror_nagbar(f);
520 FREE(context->line_copy);
525 while (!SLIST_EMPTY(&variables)) {
526 current = SLIST_FIRST(&variables);
528 FREE(current->value);
529 SLIST_REMOVE_HEAD(&variables, variables);
537 %lex-param { struct context *context }
542 uint32_t *single_color;
543 struct Colortriple *color;
545 struct Binding *binding;
548 %token <number> NUMBER "<number>"
549 %token <string> WORD "<word>"
550 %token <string> STR "<string>"
551 %token <string> STR_NG "<string (non-greedy)>"
552 %token <string> HEX "<hex>"
553 %token <string> OUTPUT "<RandR output>"
556 %token TOKCOMMENT "<comment>"
557 %token TOKFONT "font"
558 %token TOKBINDSYM "bindsym"
559 %token <number> MODIFIER "<modifier>"
560 %token TOKCONTROL "control"
561 %token TOKSHIFT "shift"
562 %token TOKFLOATING_MODIFIER "floating_modifier"
563 %token <string> QUOTEDSTRING "<quoted string>"
564 %token TOKWORKSPACE "workspace"
565 %token TOKOUTPUT "output"
566 %token TOKASSIGN "assign"
568 %token TOKIPCSOCKET "ipc_socket"
569 %token TOKRESTARTSTATE "restart_state"
570 %token TOKEXEC "exec"
571 %token TOKEXEC_ALWAYS "exec_always"
572 %token <single_color> TOKSINGLECOLOR
573 %token <color> TOKCOLOR
575 %token TOKMODE "mode"
576 %token TOK_ORIENTATION "default_orientation"
577 %token TOK_HORIZ "horizontal"
578 %token TOK_VERT "vertical"
579 %token TOK_AUTO "auto"
580 %token TOK_WORKSPACE_LAYOUT "workspace_layout"
581 %token TOKNEWWINDOW "new_window"
582 %token TOKNEWFLOAT "new_float"
583 %token TOK_NORMAL "normal"
584 %token TOK_NONE "none"
585 %token TOK_1PIXEL "1pixel"
586 %token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse"
587 %token TOK_FORCE_FOCUS_WRAPPING "force_focus_wrapping"
588 %token TOKWORKSPACEBAR "workspace_bar"
589 %token TOK_DEFAULT "default"
590 %token TOK_STACKING "stacking"
591 %token TOK_TABBED "tabbed"
592 %token <number> TOKSTACKLIMIT "stack-limit"
593 %token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen"
594 %token TOK_IGNORE "ignore"
595 %token TOK_LEAVE_FULLSCREEN "leave_fullscreen"
596 %token TOK_FOR_WINDOW "for_window"
598 %token TOK_MARK "mark"
599 %token TOK_CLASS "class"
600 %token TOK_INSTANCE "instance"
602 %token TOK_CON_ID "con_id"
603 %token TOK_TITLE "title"
605 %type <binding> binding
606 %type <binding> bindcode
607 %type <binding> bindsym
608 %type <number> binding_modifiers
609 %type <number> binding_modifier
610 %type <number> direction
611 %type <number> layout_mode
612 %type <number> border_style
613 %type <number> new_window
614 %type <number> new_float
615 %type <number> colorpixel
617 %type <number> popup_setting
618 %type <string> command
619 %type <string> word_or_number
620 %type <string> optional_workspace_name
621 %type <string> workspace_name
622 %type <string> window_class
640 | focus_follows_mouse
641 | force_focus_wrapping
654 | popup_during_fullscreen
668 TAILQ_INSERT_TAIL(bindings, $1, bindings);
673 TOKBINDCODE bindcode { $$ = $2; }
674 | TOKBINDSYM bindsym { $$ = $2; }
678 binding_modifiers NUMBER command
680 printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $3);
681 Binding *new = scalloc(sizeof(Binding));
692 binding_modifiers word_or_number command
694 printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $3);
695 Binding *new = scalloc(sizeof(Binding));
706 TOK_FOR_WINDOW match command
708 printf("\t should execute command %s for the criteria mentioned above\n", $3);
709 Assignment *assignment = scalloc(sizeof(Assignment));
710 assignment->type = A_COMMAND;
711 assignment->match = current_match;
712 assignment->dest.command = $3;
713 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
718 | matchstart criteria matchend
720 printf("match parsed\n");
728 match_init(¤t_match);
735 printf("match specification finished\n");
747 printf("criteria: class = %s\n", $3);
748 current_match.class = $3;
750 | TOK_INSTANCE '=' STR
752 printf("criteria: instance = %s\n", $3);
753 current_match.instance = $3;
757 printf("criteria: id = %s\n", $3);
759 long parsed = strtol($3, &end, 10);
760 if (parsed == LONG_MIN ||
761 parsed == LONG_MAX ||
763 (end && *end != '\0')) {
764 ELOG("Could not parse con id \"%s\"\n", $3);
766 current_match.con_id = (Con*)parsed;
767 printf("id as int = %p\n", current_match.con_id);
772 printf("criteria: window id = %s\n", $3);
774 long parsed = strtol($3, &end, 10);
775 if (parsed == LONG_MIN ||
776 parsed == LONG_MAX ||
778 (end && *end != '\0')) {
779 ELOG("Could not parse window id \"%s\"\n", $3);
781 current_match.id = parsed;
782 printf("window id as int = %d\n", current_match.id);
787 printf("criteria: mark = %s\n", $3);
788 current_match.mark = $3;
792 printf("criteria: title = %s\n", $3);
793 current_match.title = $3;
803 asprintf(&$$, "%d", $1);
808 TOKMODE QUOTEDSTRING '{' modelines '}'
810 if (strcasecmp($2, "default") == 0) {
811 printf("You cannot use the name \"default\" for your mode\n");
814 printf("\t now in mode %s\n", $2);
815 printf("\t current bindings = %p\n", current_bindings);
817 TAILQ_FOREACH(binding, current_bindings, bindings) {
818 printf("got binding on mods %d, keycode %d, symbol %s, command %s\n",
819 binding->mods, binding->keycode, binding->symbol, binding->command);
822 struct Mode *mode = scalloc(sizeof(struct Mode));
824 mode->bindings = current_bindings;
825 current_bindings = NULL;
826 SLIST_INSERT_HEAD(&modes, mode, modes);
840 if (current_bindings == NULL) {
841 current_bindings = scalloc(sizeof(struct bindings_head));
842 TAILQ_INIT(current_bindings);
845 TAILQ_INSERT_TAIL(current_bindings, $1, bindings);
850 TOKFLOATING_MODIFIER binding_modifiers
852 DLOG("floating modifier = %d\n", $2);
853 config.floating_modifier = $2;
858 TOK_ORIENTATION direction
860 DLOG("New containers should start with split direction %d\n", $2);
861 config.default_orientation = $2;
866 TOK_HORIZ { $$ = HORIZ; }
867 | TOK_VERT { $$ = VERT; }
868 | TOK_AUTO { $$ = NO_ORIENTATION; }
872 TOK_WORKSPACE_LAYOUT layout_mode
874 DLOG("new containers will be in mode %d\n", $2);
875 config.default_layout = $2;
878 /* We also need to change the layout of the already existing
879 * workspaces here. Workspaces may exist at this point because
880 * of the other directives which are modifying workspaces
881 * (setting the preferred screen or name). While the workspace
882 * objects are already created, they have never been used.
883 * Thus, the user very likely awaits the default container mode
884 * to trigger in this case, regardless of where it is inside
885 * his configuration file. */
887 TAILQ_FOREACH(ws, workspaces, workspaces) {
888 if (ws->table == NULL)
890 switch_layout_mode(global_conn,
892 config.container_mode);
896 | TOK_WORKSPACE_LAYOUT TOKSTACKLIMIT TOKSTACKLIMIT NUMBER
898 DLOG("stack-limit %d with val %d\n", $3, $4);
899 config.container_stack_limit = $3;
900 config.container_stack_limit_value = $4;
903 /* See the comment above */
905 TAILQ_FOREACH(ws, workspaces, workspaces) {
906 if (ws->table == NULL)
908 Container *con = ws->table[0][0];
909 con->stack_limit = config.container_stack_limit;
910 con->stack_limit_value = config.container_stack_limit_value;
917 TOK_DEFAULT { $$ = L_DEFAULT; }
918 | TOK_STACKING { $$ = L_STACKED; }
919 | TOK_TABBED { $$ = L_TABBED; }
923 TOKNEWWINDOW border_style
925 DLOG("new windows should start with border style %d\n", $2);
926 config.default_border = $2;
931 TOKNEWFLOAT border_style
933 DLOG("new floating windows should start with border style %d\n", $2);
934 config.default_floating_border = $2;
939 TOK_NORMAL { $$ = BS_NORMAL; }
940 | TOK_NONE { $$ = BS_NONE; }
941 | TOK_1PIXEL { $$ = BS_1PIXEL; }
951 DLOG("checking word \"%s\"\n", $1);
952 $$ = (strcasecmp($1, "yes") == 0 ||
953 strcasecmp($1, "true") == 0 ||
954 strcasecmp($1, "on") == 0 ||
955 strcasecmp($1, "enable") == 0 ||
956 strcasecmp($1, "active") == 0);
961 TOKFOCUSFOLLOWSMOUSE bool
963 DLOG("focus follows mouse = %d\n", $2);
964 config.disable_focus_follows_mouse = !($2);
968 force_focus_wrapping:
969 TOK_FORCE_FOCUS_WRAPPING bool
971 DLOG("force focus wrapping = %d\n", $2);
972 config.force_focus_wrapping = $2;
979 DLOG("workspace bar = %d\n", $2);
980 config.disable_workspace_bar = !($2);
985 TOKWORKSPACE NUMBER TOKOUTPUT OUTPUT optional_workspace_name
989 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
991 char *ws_name = NULL;
993 asprintf(&ws_name, "%d", ws_num);
998 DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
999 struct Workspace_Assignment *assignment = scalloc(sizeof(struct Workspace_Assignment));
1000 assignment->name = ws_name;
1001 assignment->output = $4;
1002 TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
1005 | TOKWORKSPACE NUMBER workspace_name
1009 DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
1011 DLOG("workspace name to: %s\n", $3);
1013 if ($<string>3 != NULL) {
1014 workspace_set_name(workspace_get(ws_num - 1), $<string>3);
1022 optional_workspace_name:
1023 /* empty */ { $$ = NULL; }
1024 | workspace_name { $$ = $1; }
1028 QUOTEDSTRING { $$ = $1; }
1034 TOKASSIGN window_class STR
1036 printf("assignment of %s to *%s*\n", $2, $3);
1037 char *workspace = $3;
1038 char *criteria = $2;
1040 Assignment *assignment = scalloc(sizeof(Assignment));
1041 Match *match = &(assignment->match);
1044 char *separator = NULL;
1045 if ((separator = strchr(criteria, '/')) != NULL) {
1046 *(separator++) = '\0';
1047 match->title = sstrdup(separator);
1049 if (*criteria != '\0')
1050 match->class = sstrdup(criteria);
1053 printf(" class = %s\n", match->class);
1054 printf(" title = %s\n", match->title);
1056 /* Compatibility with older versions: If the assignment target starts
1057 * with ~, we create the equivalent of:
1059 * for_window [class="foo"] floating enable
1061 if (*workspace == '~') {
1063 if (*workspace == '\0') {
1064 /* This assignment was *only* for floating */
1065 assignment->type = A_COMMAND;
1066 assignment->dest.command = sstrdup("floating enable");
1067 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1070 /* Create a new assignment and continue afterwards */
1071 Assignment *floating = scalloc(sizeof(Assignment));
1072 match_copy(&(floating->match), match);
1073 floating->type = A_COMMAND;
1074 floating->dest.command = sstrdup("floating enable");
1075 TAILQ_INSERT_TAIL(&assignments, floating, assignments);
1079 assignment->type = A_TO_WORKSPACE;
1080 assignment->dest.workspace = workspace;
1081 TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
1093 config.ipc_socket_path = $2;
1100 config.restart_state_path = $2;
1107 struct Autostart *new = smalloc(sizeof(struct Autostart));
1109 TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
1116 struct Autostart *new = smalloc(sizeof(struct Autostart));
1118 TAILQ_INSERT_TAIL(&autostarts_always, new, autostarts_always);
1125 ELOG("The terminal option is DEPRECATED and has no effect. "
1126 "Please remove it from your configuration file.\n");
1133 config.font = load_font($2, true);
1134 printf("font %s\n", $2);
1140 TOKSINGLECOLOR colorpixel
1142 uint32_t *dest = $1;
1148 TOKCOLOR colorpixel colorpixel colorpixel
1150 struct Colortriple *dest = $1;
1153 dest->background = $3;
1162 if (asprintf(&hex, "#%s", $2) == -1)
1165 $$ = get_colorpixel(hex);
1172 /* NULL */ { $$ = 0; }
1174 | binding_modifiers '+' binding_modifier { $$ = $1 | $3; }
1175 | binding_modifiers '+' { $$ = $1; }
1179 MODIFIER { $$ = $1; }
1180 | TOKCONTROL { $$ = BIND_CONTROL; }
1181 | TOKSHIFT { $$ = BIND_SHIFT; }
1184 popup_during_fullscreen:
1185 TOK_POPUP_DURING_FULLSCREEN popup_setting
1187 DLOG("popup_during_fullscreen setting: %d\n", $2);
1188 config.popup_during_fullscreen = $2;
1193 TOK_IGNORE { $$ = PDF_IGNORE; }
1194 | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; }