diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2017-01-19 03:58:31 +0200 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2017-01-19 03:58:31 +0200 |
commit | 28278864b4eef87782918f6ad76e2f0452d16f1a (patch) | |
tree | 9020a88b43e0f1514db4524dc5cdd1d7b82a7acb /sway/criteria.c | |
parent | Merge pull request #1051 from ametisf/master (diff) | |
download | sway-28278864b4eef87782918f6ad76e2f0452d16f1a.tar.gz sway-28278864b4eef87782918f6ad76e2f0452d16f1a.tar.zst sway-28278864b4eef87782918f6ad76e2f0452d16f1a.zip |
Support __focused__ as a valid criterion
This reflects i3 behavior (see i3/i3#1770)
Scrapping focused support will probably break some existing configs
Diffstat (limited to 'sway/criteria.c')
-rw-r--r-- | sway/criteria.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/sway/criteria.c b/sway/criteria.c index 739a183e..c4fe6ecc 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -205,7 +205,12 @@ static char *generate_regex(regex_t **regex, char *value) { | |||
205 | return NULL; | 205 | return NULL; |
206 | } | 206 | } |
207 | 207 | ||
208 | // Pouplate list with crit_tokens extracted from criteria string, returns error | 208 | // Test whether the criterion corresponds to the currently focused window |
209 | static bool crit_is_focused(const char *value) { | ||
210 | return !strcmp(value, "focused") || !strcmp(value, "__focused__"); | ||
211 | } | ||
212 | |||
213 | // Populate list with crit_tokens extracted from criteria string, returns error | ||
209 | // string or NULL if successful. | 214 | // string or NULL if successful. |
210 | char *extract_crit_tokens(list_t *tokens, const char * const criteria) { | 215 | char *extract_crit_tokens(list_t *tokens, const char * const criteria) { |
211 | int argc; | 216 | int argc; |
@@ -221,7 +226,7 @@ char *extract_crit_tokens(list_t *tokens, const char * const criteria) { | |||
221 | if ((error = parse_criteria_name(&token->type, name))) { | 226 | if ((error = parse_criteria_name(&token->type, name))) { |
222 | free_crit_token(token); | 227 | free_crit_token(token); |
223 | goto ect_cleanup; | 228 | goto ect_cleanup; |
224 | } else if (token->type == CRIT_URGENT || strcmp(value, "focused") == 0) { | 229 | } else if (token->type == CRIT_URGENT || crit_is_focused(value)) { |
225 | sway_log(L_DEBUG, "%s -> \"%s\"", name, value); | 230 | sway_log(L_DEBUG, "%s -> \"%s\"", name, value); |
226 | list_add(tokens, token); | 231 | list_add(tokens, token); |
227 | } else if((error = generate_regex(&token->regex, value))) { | 232 | } else if((error = generate_regex(&token->regex, value))) { |
@@ -250,7 +255,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
250 | case CRIT_CLASS: | 255 | case CRIT_CLASS: |
251 | if (!cont->class) { | 256 | if (!cont->class) { |
252 | // ignore | 257 | // ignore |
253 | } else if (strcmp(crit->raw, "focused") == 0) { | 258 | } else if (crit_is_focused(crit->raw)) { |
254 | swayc_t *focused = get_focused_view(&root_container); | 259 | swayc_t *focused = get_focused_view(&root_container); |
255 | if (focused->class && strcmp(cont->class, focused->class) == 0) { | 260 | if (focused->class && strcmp(cont->class, focused->class) == 0) { |
256 | matches++; | 261 | matches++; |
@@ -271,7 +276,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
271 | case CRIT_TITLE: | 276 | case CRIT_TITLE: |
272 | if (!cont->name) { | 277 | if (!cont->name) { |
273 | // ignore | 278 | // ignore |
274 | } else if (strcmp(crit->raw, "focused") == 0) { | 279 | } else if (crit_is_focused(crit->raw)) { |
275 | swayc_t *focused = get_focused_view(&root_container); | 280 | swayc_t *focused = get_focused_view(&root_container); |
276 | if (focused->name && strcmp(cont->name, focused->name) == 0) { | 281 | if (focused->name && strcmp(cont->name, focused->name) == 0) { |
277 | matches++; | 282 | matches++; |
@@ -291,7 +296,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
291 | swayc_t *cont_ws = swayc_parent_by_type(cont, C_WORKSPACE); | 296 | swayc_t *cont_ws = swayc_parent_by_type(cont, C_WORKSPACE); |
292 | if (!cont_ws || !cont_ws->name) { | 297 | if (!cont_ws || !cont_ws->name) { |
293 | // ignore | 298 | // ignore |
294 | } else if (strcmp(crit->raw, "focused") == 0) { | 299 | } else if (crit_is_focused(crit->raw)) { |
295 | swayc_t *focused_ws = swayc_active_workspace(); | 300 | swayc_t *focused_ws = swayc_active_workspace(); |
296 | if (focused_ws->name && strcmp(cont_ws->name, focused_ws->name) == 0) { | 301 | if (focused_ws->name && strcmp(cont_ws->name, focused_ws->name) == 0) { |
297 | matches++; | 302 | matches++; |