]> git.sur5r.net Git - i3/i3/commitdiff
Parse multiple criteria in commands (+test), better error message for 'focus'
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 8 Jun 2011 21:34:08 +0000 (23:34 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 8 Jun 2011 21:34:08 +0000 (23:34 +0200)
src/cmdparse.l
src/cmdparse.y
testcases/t/11-goto.t

index 91aed5e349da5b9f74eb8c4e19a260d543d6dad0..ba2789f267d9ec4a1363b15806efa8ef24c6d474 100644 (file)
@@ -143,6 +143,7 @@ class                           { BEGIN(WANT_QSTRING); return TOK_CLASS; }
 id                              { BEGIN(WANT_QSTRING); return TOK_ID; }
 con_id                          { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
 con_mark                        { BEGIN(WANT_QSTRING); return TOK_MARK; }
+title                           { BEGIN(WANT_QSTRING); return TOK_TITLE; }
 
 [0-9]+                          { cmdyylval.number = atoi(yytext); return NUMBER; }
 
index 08f02c615b8cb52483926b617d0c8eb19ae8a5af..c33a145b3be513af74ff2c6f5db3fe29e3937110 100644 (file)
@@ -162,6 +162,7 @@ char *parse_cmd(const char *new) {
 %token              TOK_CLASS           "class"
 %token              TOK_ID              "id"
 %token              TOK_CON_ID          "con_id"
+%token              TOK_TITLE           "title"
 
 %token  <string>    STR                 "<string>"
 %token  <number>    NUMBER              "<number>"
@@ -271,6 +272,11 @@ matchend:
     ;
 
 criteria:
+    criteria criterion
+    | criterion
+    ;
+
+criterion:
     TOK_CLASS '=' STR
     {
         printf("criteria: class = %s\n", $3);
@@ -311,6 +317,11 @@ criteria:
         printf("criteria: mark = %s\n", $3);
         current_match.mark = $3;
     }
+    | TOK_TITLE '=' STR
+    {
+        printf("criteria: title = %s\n", $3);
+        current_match.title = $3;
+    }
     ;
 
 operations:
@@ -381,20 +392,26 @@ focus:
     {
         owindow *current;
 
-        printf("should focus\n");
         if (match_is_empty(&current_match)) {
-            /* TODO: better error message */
-            LOG("Error: The focus command requires you to use some criteria.\n");
+            ELOG("You have to specify which window/container should be focused.\n");
+            ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
+
+            asprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
+                     "specify which window/container should be focused\"}");
             break;
         }
 
-        /* TODO: warning if the match contains more than one entry. does not
-         * make so much sense when focusing */
+        int count = 0;
         TAILQ_FOREACH(current, &owindows, owindows) {
             LOG("focusing %p / %s\n", current->con, current->con->name);
             con_focus(current->con);
+            count++;
         }
 
+        if (count > 1)
+            LOG("WARNING: Your criteria for the focus command matches %d containers, "
+                "while only exactly one container can be focused at a time.\n", count);
+
         tree_render();
     }
     | TOK_FOCUS direction
index 7aebc880bb31ee97b478ed12439d0f66ad9e136b..4eedb56c370f426f06184de3f2afbc434a79463b 100644 (file)
@@ -1,7 +1,7 @@
 #!perl
 # vim:ts=4:sw=4:expandtab
 
-use i3test tests => 6;
+use i3test;
 use X11::XCB qw(:all);
 use Digest::SHA1 qw(sha1_base64);
 
@@ -65,4 +65,13 @@ is($focus, $top->id, "Top window focused");
 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
 is($focus, $mid->id, "goto worked");
 
+# check that we can specify multiple criteria
+
+$focus = focus_after('focus left');
+is($focus, $top->id, "Top window focused");
+
+$focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
+is($focus, $mid->id, "goto worked");
+
+
 done_testing;