]> git.sur5r.net Git - i3/i3/blobdiff - src/cfgparse.y
Bugfix: Ignore for_window commands with empty (invalid) criteria (+test) (Thanks...
[i3/i3] / src / cfgparse.y
index 06d9c664a2161caebdd9a1115fdb7c0c813e291f..10ca48ccf609a4d9efff608e21b6843860ada305 100644 (file)
@@ -8,7 +8,6 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <limits.h>
 
 #include "all.h"
 
@@ -189,6 +188,7 @@ static char *migrate_config(char *input, off_t size) {
         ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes);
         if (ret == -1) {
             warn("Cannot read from pipe");
+            FREE(converted);
             return NULL;
         }
         read_bytes += ret;
@@ -351,13 +351,18 @@ void parse_file(const char *f) {
             continue;
 
         if (strcasecmp(key, "set") == 0) {
-            if (value[0] != '$')
-                die("Malformed variable assignment, name has to start with $\n");
+            if (value[0] != '$') {
+                ELOG("Malformed variable assignment, name has to start with $\n");
+                continue;
+            }
 
             /* get key/value for this variable */
             char *v_key = value, *v_value;
-            if ((v_value = strstr(value, " ")) == NULL)
-                die("Malformed variable assignment, need a value\n");
+            if ((v_value = strstr(value, " ")) == NULL &&
+                (v_value = strstr(value, "\t")) == NULL) {
+                ELOG("Malformed variable assignment, need a value\n");
+                continue;
+            }
 
             *(v_value++) = '\0';
 
@@ -548,6 +553,7 @@ void parse_file(const char *f) {
 
 %token              TOK_MARK            "mark"
 %token              TOK_CLASS           "class"
+%token              TOK_INSTANCE        "instance"
 %token              TOK_ID              "id"
 %token              TOK_CON_ID          "con_id"
 %token              TOK_TITLE           "title"
@@ -653,6 +659,10 @@ bindsym:
 for_window:
     TOK_FOR_WINDOW match command
     {
+        if (match_is_empty(&current_match)) {
+            ELOG("Match is empty, ignoring this for_window statement\n");
+            break;
+        }
         printf("\t should execute command %s for the criteria mentioned above\n", $3);
         Assignment *assignment = scalloc(sizeof(Assignment));
         assignment->type = A_COMMAND;
@@ -695,6 +705,11 @@ criterion:
         printf("criteria: class = %s\n", $3);
         current_match.class = $3;
     }
+    | TOK_INSTANCE '=' STR
+    {
+        printf("criteria: instance = %s\n", $3);
+        current_match.instance = $3;
+    }
     | TOK_CON_ID '=' STR
     {
         printf("criteria: id = %s\n", $3);
@@ -931,10 +946,25 @@ workspace:
             }
 
             DLOG("Should assign workspace %s to output %s\n", ws_name, $4);
-            struct Workspace_Assignment *assignment = scalloc(sizeof(struct Workspace_Assignment));
-            assignment->name = ws_name;
-            assignment->output = $4;
-            TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
+            /* Check for earlier assignments of the same workspace so that we
+             * don’t have assignments of a single workspace to different
+             * outputs */
+            struct Workspace_Assignment *assignment;
+            bool duplicate = false;
+            TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
+                if (strcasecmp(assignment->name, ws_name) == 0) {
+                    ELOG("You have a duplicate workspace assignment for workspace \"%s\"\n",
+                         ws_name);
+                    assignment->output = $4;
+                    duplicate = true;
+                }
+            }
+            if (!duplicate) {
+                assignment = scalloc(sizeof(struct Workspace_Assignment));
+                assignment->name = ws_name;
+                assignment->output = $4;
+                TAILQ_INSERT_TAIL(&ws_assignments, assignment, ws_assignments);
+            }
         }
     }
     | TOKWORKSPACE NUMBER workspace_name
@@ -1096,6 +1126,7 @@ colorpixel:
         char *hex;
         if (asprintf(&hex, "#%s", $2) == -1)
             die("asprintf()");
+        free($2);
         $$ = get_colorpixel(hex);
         free(hex);
     }