X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcfgparse.y;h=d706b4001b6157f2822fa3bd62ebabad87709065;hb=e101940c5edd3094463fea362fc21e924a46eca4;hp=7875f86ebaff72ce4335c87aaaf732cb1ace17c5;hpb=0e8b87e9da8e0a574cb2c2852773534f70292564;p=i3%2Fi3 diff --git a/src/cfgparse.y b/src/cfgparse.y index 7875f86e..d706b400 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -1,4 +1,8 @@ %{ +/* + * vim:ts=8:expandtab + * + */ #include #include #include @@ -15,10 +19,14 @@ #include "util.h" #include "queue.h" #include "table.h" +#include "workspace.h" +#include "xcb.h" extern int yylex(void); extern FILE *yyin; +static struct bindings_head *current_bindings; + int yydebug = 1; void yyerror(const char *str) { @@ -152,7 +160,8 @@ void parse_file(const char *f) { int number; char *string; struct Colortriple *color; - struct Assignment *assignment; + struct Assignment *assignment; + struct Binding *binding; } %token NUMBER @@ -179,6 +188,10 @@ void parse_file(const char *f) { %token TOKEXEC %token TOKCOLOR %token TOKARROW +%token TOKMODE +%token TOKNEWCONTAINER +%token TOKCONTAINERMODE +%token TOKSTACKLIMIT %% @@ -188,9 +201,10 @@ lines: /* empty */ ; line: - bind - | bindsym + bindline + | mode | floating_modifier + | new_container | workspace | assign | ipcsocket @@ -209,31 +223,85 @@ command: STR ; +bindline: + binding + { + TAILQ_INSERT_TAIL(bindings, $1, bindings); + } + ; + +binding: + TOKBIND WHITESPACE bind { $$ = $3; } + | TOKBINDSYM WHITESPACE bindsym { $$ = $3; } + ; + bind: - TOKBIND WHITESPACE binding_modifiers NUMBER WHITESPACE command + binding_modifiers NUMBER WHITESPACE command { - printf("\tFound binding mod%d with key %d and command %s\n", $3, $4, $6); + printf("\tFound binding mod%d with key %d and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->keycode = $4; - new->mods = $3; - new->command = sstrdup($6); + new->keycode = $2; + new->mods = $1; + new->command = sstrdup($4); - TAILQ_INSERT_TAIL(&bindings, new, bindings); + $$ = new; } ; bindsym: - TOKBINDSYM WHITESPACE binding_modifiers WORD WHITESPACE command + binding_modifiers WORD WHITESPACE command { - printf("\tFound symbolic mod%d with key %s and command %s\n", $3, $4, $6); + printf("\tFound symbolic mod%d with key %s and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->symbol = sstrdup($4); - new->mods = $3; - new->command = sstrdup($6); + new->symbol = sstrdup($2); + new->mods = $1; + new->command = sstrdup($4); + + $$ = new; + } + ; + +mode: + TOKMODE WHITESPACE QUOTEDSTRING WHITESPACE '{' modelines '}' + { + if (strcasecmp($3, "default") == 0) { + printf("You cannot use the name \"default\" for your mode\n"); + exit(1); + } + printf("\t now in mode %s\n", $3); + printf("\t current bindings = %p\n", current_bindings); + Binding *binding; + TAILQ_FOREACH(binding, current_bindings, bindings) { + printf("got binding on mods %d, keycode %d, symbol %s, command %s\n", + binding->mods, binding->keycode, binding->symbol, binding->command); + } + + struct Mode *mode = scalloc(sizeof(struct Mode)); + mode->name = strdup($3); + mode->bindings = current_bindings; + current_bindings = NULL; + SLIST_INSERT_HEAD(&modes, mode, modes); + } + ; + +modelines: + /* empty */ + | modelines WHITESPACE modeline + | modelines modeline + ; + +modeline: + comment + | binding + { + if (current_bindings == NULL) { + current_bindings = scalloc(sizeof(struct bindings_head)); + TAILQ_INIT(current_bindings); + } - TAILQ_INSERT_TAIL(&bindings, new, bindings); + TAILQ_INSERT_TAIL(current_bindings, $1, bindings); } ; @@ -245,28 +313,68 @@ floating_modifier: } ; +new_container: + TOKNEWCONTAINER WHITESPACE TOKCONTAINERMODE + { + LOG("new containers will be in mode %d\n", $3); + config.container_mode = $3; + + /* We also need to change the layout of the already existing + * workspaces here. Workspaces may exist at this point because + * of the other directives which are modifying workspaces + * (setting the preferred screen or name). While the workspace + * objects are already created, they have never been used. + * Thus, the user very likely awaits the default container mode + * to trigger in this case, regardless of where it is inside + * his configuration file. */ + for (int c = 0; c < num_workspaces; c++) { + if (workspaces[c].table == NULL) + continue; + switch_layout_mode(global_conn, + workspaces[c].table[0][0], + config.container_mode); + } + } + | TOKNEWCONTAINER WHITESPACE TOKSTACKLIMIT WHITESPACE TOKSTACKLIMIT WHITESPACE NUMBER + { + LOG("stack-limit %d with val %d\n", $5, $7); + config.container_stack_limit = $5; + config.container_stack_limit_value = $7; + + /* See the comment above */ + for (int c = 0; c < num_workspaces; c++) { + if (workspaces[c].table == NULL) + continue; + Container *con = workspaces[c].table[0][0]; + con->stack_limit = config.container_stack_limit; + con->stack_limit_value = config.container_stack_limit_value; + } + } + ; + workspace: TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen workspace_name { int ws_num = $3; - if (ws_num < 1 || ws_num > 10) { + if (ws_num < 1) { LOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { - workspaces[ws_num - 1].preferred_screen = sstrdup($7); + Workspace *ws = workspace_get(ws_num - 1); + ws->preferred_screen = sstrdup($7); if ($8 != NULL) - workspace_set_name(&(workspaces[ws_num - 1]), $8); + workspace_set_name(ws, $8); } } - | TOKWORKSPACE WHITESPACE NUMBER workspace_name - { + | TOKWORKSPACE WHITESPACE NUMBER workspace_name + { int ws_num = $3; - if (ws_num < 1 || ws_num > 10) { + if (ws_num < 1) { LOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { - if ($4 != NULL) - workspace_set_name(&(workspaces[ws_num - 1]), $4); - } - } + if ($4 != NULL) + workspace_set_name(workspace_get(ws_num - 1), $4); + } + } ; workspace_name: @@ -287,34 +395,34 @@ assign: { printf("assignment of %s to %d\n", $3, $6); - struct Assignment *new = $6; - new->windowclass_title = strdup($3); - TAILQ_INSERT_TAIL(&assignments, new, assignments); + struct Assignment *new = $6; + new->windowclass_title = strdup($3); + TAILQ_INSERT_TAIL(&assignments, new, assignments); } ; assign_target: - NUMBER - { - struct Assignment *new = scalloc(sizeof(struct Assignment)); - new->workspace = $1; - new->floating = ASSIGN_FLOATING_NO; - $$ = new; - } - | '~' - { - struct Assignment *new = scalloc(sizeof(struct Assignment)); - new->floating = ASSIGN_FLOATING_ONLY; - $$ = new; - } - | '~' NUMBER - { - struct Assignment *new = scalloc(sizeof(struct Assignment)); - new->workspace = $2; - new->floating = ASSIGN_FLOATING; - $$ = new; - } - ; + NUMBER + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->workspace = $1; + new->floating = ASSIGN_FLOATING_NO; + $$ = new; + } + | '~' + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->floating = ASSIGN_FLOATING_ONLY; + $$ = new; + } + | '~' NUMBER + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->workspace = $2; + new->floating = ASSIGN_FLOATING; + $$ = new; + } + ; window_class: QUOTEDSTRING