Implement new criterion 'workspace'.

If the match expression is a plain number (e.g., '99'), the number of a workspace will be compared strictly. Otherwise, the match expression is taken as a regular expression and compared against the workspace's name.
This allows all of the following:

for_window [workspace=5] ...
for_window [workspace="5:foo"] ...
for_window [workspace="foo"] ...

fixes #1769
This commit is contained in:
Ingo Bürk
2015-06-29 23:58:48 +02:00
parent 8df7e4ecb9
commit be406d036d
8 changed files with 55 additions and 2 deletions

View File

@ -48,6 +48,7 @@ bool match_is_empty(Match *match) {
match->class == NULL &&
match->instance == NULL &&
match->window_role == NULL &&
match->workspace == NULL &&
match->urgent == U_DONTCHECK &&
match->id == XCB_NONE &&
match->window_type == UINT32_MAX &&
@ -78,6 +79,7 @@ void match_copy(Match *dest, Match *src) {
DUPLICATE_REGEX(class);
DUPLICATE_REGEX(instance);
DUPLICATE_REGEX(window_role);
DUPLICATE_REGEX(workspace);
}
/*
@ -172,6 +174,19 @@ bool match_matches_window(Match *match, i3Window *window) {
LOG("urgent matches oldest\n");
}
if (match->workspace != NULL) {
Con *con = con_by_window_id(window->id);
assert(con != NULL);
Con *ws = con_get_workspace(con);
assert(ws != NULL);
if (regex_matches(match->workspace, ws->name)) {
LOG("workspace matches (%s)\n", ws->name);
} else {
return false;
}
}
if (match->dock != M_DONTCHECK) {
if ((window->dock == W_DOCK_TOP && match->dock == M_DOCK_TOP) ||
(window->dock == W_DOCK_BOTTOM && match->dock == M_DOCK_BOTTOM) ||