]> git.sur5r.net Git - i3/i3/commitdiff
Introduce a new syntax for the 'assign' command:
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 11 Sep 2011 20:54:13 +0000 (21:54 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 11 Sep 2011 20:54:13 +0000 (21:54 +0100)
Instead of using a quoted string to specify the class / title, the assign
command now uses criteria, just like the for_window command or the command
scopes.

An example comes here:

    # Assign all Chromium windows (including popups) to workspace 1: www
    assign [class="^Chromium$"] → 1: www

    # Make the main browser window borderless
    for_window [class="^Chromium$" title=" - Chromium$"] border none

This gives you more control over the matching process due to various reasons:

1) Criteria work case-sensitive by default. Use the (?i) option if you want a
   case-insensitive match, like this:
   assign [class="(?i)^ChroMIUM$"] → 1

2) class and instance of WM_CLASS can now be matched separately. For example,
   when starting urxvt -name irssi, xprop will report this:
   WM_CLASS(STRING) = "irssi", "URxvt"
   The first part of this is the instance ("irssi"), the second part is the
   class ("URxvt").
   An appropriate assignment looks like this:
   assign [class="^URxvt$" instance="irssi"] → 2

3) You can now freely use a forward slash (/) in all strings since that is no
   longer used to separate class from title (in-band signaling is bad, mhkay?).

src/cfgparse.l
src/cfgparse.y

index e29f6efc1466ec0438ea9d2f681b65c0a179de1f..12840f26b0c21a543461f628bd2d348e4d11541a 100644 (file)
@@ -75,6 +75,14 @@ EOL     (\r?\n)
 
 
 <FOR_WINDOW_COND>"]"            { yy_pop_state(); return ']'; }
+<ASSIGN_COND>"["                {
+                                  /* this is the case for the new assign syntax
+                                   * that uses criteria */
+                                  yy_pop_state();
+                                  yy_push_state(FOR_WINDOW_COND);
+                                  /* afterwards we will be in ASSIGN_TARGET_COND */
+                                  return '[';
+                                }
 <EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
 <WANT_QSTRING>\"[^\"]+\"        {
                                   yy_pop_state();
@@ -194,7 +202,7 @@ title                           { yy_push_state(WANT_QSTRING); return TOK_TITLE;
                                   yylval.string = copy;
                                   return QUOTEDSTRING;
                                 }
-<ASSIGN_COND>[^ \t\"]+          { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
+<ASSIGN_COND>[^ \t\"\[]+        { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
 <BINDSYM_COND>[a-zA-Z0-9_]+     { yylval.string = sstrdup(yytext); return WORD; }
 [a-zA-Z]+                       { yylval.string = sstrdup(yytext); return WORD; }
 .                               { return (int)yytext[0]; }
index ca2d0710d5f937048ea1c876a46d51645df87b95..53d23815caf9145ac431fccf076ee6920449bf23 100644 (file)
@@ -1137,6 +1137,15 @@ assign:
         assignment->dest.workspace = workspace;
         TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
     }
+    | TOKASSIGN match STR
+    {
+        printf("new assignment, using above criteria, to workspace %s\n", $3);
+        Assignment *assignment = scalloc(sizeof(Assignment));
+        assignment->match = current_match;
+        assignment->type = A_TO_WORKSPACE;
+        assignment->dest.workspace = $3;
+        TAILQ_INSERT_TAIL(&assignments, assignment, assignments);
+    }
     ;
 
 window_class: