]> git.sur5r.net Git - i3/i3/blobdiff - src/cfgparse.y
Implement options to change the default mode of containers
[i3/i3] / src / cfgparse.y
index 15f0df8b8b302d03771e731878de6d853d214197..d706b4001b6157f2822fa3bd62ebabad87709065 100644 (file)
@@ -189,6 +189,9 @@ void parse_file(const char *f) {
 %token TOKCOLOR
 %token TOKARROW
 %token TOKMODE
+%token TOKNEWCONTAINER
+%token TOKCONTAINERMODE
+%token TOKSTACKLIMIT
 
 %%
 
@@ -201,6 +204,7 @@ line:
         bindline
         | mode
         | floating_modifier
+        | new_container
         | workspace
         | assign
         | ipcsocket
@@ -222,7 +226,7 @@ command:
 bindline:
         binding
         {
-                TAILQ_INSERT_TAIL(&bindings, $<binding>1, bindings);
+                TAILQ_INSERT_TAIL(bindings, $<binding>1, bindings);
         }
         ;
 
@@ -262,8 +266,23 @@ bindsym:
 mode:
         TOKMODE WHITESPACE QUOTEDSTRING WHITESPACE '{' modelines '}'
         {
+                if (strcasecmp($<string>3, "default") == 0) {
+                        printf("You cannot use the name \"default\" for your mode\n");
+                        exit(1);
+                }
                 printf("\t now in mode %s\n", $<string>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($<string>3);
+                mode->bindings = current_bindings;
+                current_bindings = NULL;
+                SLIST_INSERT_HEAD(&modes, mode, modes);
         }
         ;
 
@@ -294,26 +313,66 @@ floating_modifier:
         }
         ;
 
+new_container:
+        TOKNEWCONTAINER WHITESPACE TOKCONTAINERMODE
+        {
+                LOG("new containers will be in mode %d\n", $<number>3);
+                config.container_mode = $<number>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", $<number>5, $<number>7);
+                config.container_stack_limit = $<number>5;
+                config.container_stack_limit_value = $<number>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 = $<number>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($<string>7);
+                        Workspace *ws = workspace_get(ws_num - 1);
+                        ws->preferred_screen = sstrdup($<string>7);
                         if ($<string>8 != NULL)
-                                workspace_set_name(&(workspaces[ws_num - 1]), $<string>8);
+                                workspace_set_name(ws, $<string>8);
                 }
         }
         | TOKWORKSPACE WHITESPACE NUMBER workspace_name
         {
                 int ws_num = $<number>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 ($<string>4 != NULL)
-                                        workspace_set_name(&(workspaces[ws_num - 1]), $<string>4);
+                                workspace_set_name(workspace_get(ws_num - 1), $<string>4);
                 }
         }
         ;