diff options
author | 2017-01-18 22:54:19 -0500 | |
---|---|---|
committer | 2017-01-18 22:54:19 -0500 | |
commit | 7cc6f288d9cdb85eead948f78237848b2d479004 (patch) | |
tree | 9c2767b010da4451f53491356c7fee1ab53a6c74 /sway | |
parent | Merge pull request #1052 from Hummer12007/instance (diff) | |
parent | Support __focused__ as a valid criterion (diff) | |
download | sway-7cc6f288d9cdb85eead948f78237848b2d479004.tar.gz sway-7cc6f288d9cdb85eead948f78237848b2d479004.tar.zst sway-7cc6f288d9cdb85eead948f78237848b2d479004.zip |
Merge pull request #1053 from Hummer12007/__focused__
Support __focused__ as a valid criterion
Diffstat (limited to 'sway')
-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 fd1ea64b..5c305193 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -204,7 +204,12 @@ static char *generate_regex(regex_t **regex, char *value) { | |||
204 | return NULL; | 204 | return NULL; |
205 | } | 205 | } |
206 | 206 | ||
207 | // Pouplate list with crit_tokens extracted from criteria string, returns error | 207 | // Test whether the criterion corresponds to the currently focused window |
208 | static bool crit_is_focused(const char *value) { | ||
209 | return !strcmp(value, "focused") || !strcmp(value, "__focused__"); | ||
210 | } | ||
211 | |||
212 | // Populate list with crit_tokens extracted from criteria string, returns error | ||
208 | // string or NULL if successful. | 213 | // string or NULL if successful. |
209 | char *extract_crit_tokens(list_t *tokens, const char * const criteria) { | 214 | char *extract_crit_tokens(list_t *tokens, const char * const criteria) { |
210 | int argc; | 215 | int argc; |
@@ -220,7 +225,7 @@ char *extract_crit_tokens(list_t *tokens, const char * const criteria) { | |||
220 | if ((error = parse_criteria_name(&token->type, name))) { | 225 | if ((error = parse_criteria_name(&token->type, name))) { |
221 | free_crit_token(token); | 226 | free_crit_token(token); |
222 | goto ect_cleanup; | 227 | goto ect_cleanup; |
223 | } else if (token->type == CRIT_URGENT || strcmp(value, "focused") == 0) { | 228 | } else if (token->type == CRIT_URGENT || crit_is_focused(value)) { |
224 | sway_log(L_DEBUG, "%s -> \"%s\"", name, value); | 229 | sway_log(L_DEBUG, "%s -> \"%s\"", name, value); |
225 | list_add(tokens, token); | 230 | list_add(tokens, token); |
226 | } else if((error = generate_regex(&token->regex, value))) { | 231 | } else if((error = generate_regex(&token->regex, value))) { |
@@ -249,7 +254,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
249 | case CRIT_CLASS: | 254 | case CRIT_CLASS: |
250 | if (!cont->class) { | 255 | if (!cont->class) { |
251 | // ignore | 256 | // ignore |
252 | } else if (strcmp(crit->raw, "focused") == 0) { | 257 | } else if (crit_is_focused(crit->raw)) { |
253 | swayc_t *focused = get_focused_view(&root_container); | 258 | swayc_t *focused = get_focused_view(&root_container); |
254 | if (focused->class && strcmp(cont->class, focused->class) == 0) { | 259 | if (focused->class && strcmp(cont->class, focused->class) == 0) { |
255 | matches++; | 260 | matches++; |
@@ -280,7 +285,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
280 | case CRIT_TITLE: | 285 | case CRIT_TITLE: |
281 | if (!cont->name) { | 286 | if (!cont->name) { |
282 | // ignore | 287 | // ignore |
283 | } else if (strcmp(crit->raw, "focused") == 0) { | 288 | } else if (crit_is_focused(crit->raw)) { |
284 | swayc_t *focused = get_focused_view(&root_container); | 289 | swayc_t *focused = get_focused_view(&root_container); |
285 | if (focused->name && strcmp(cont->name, focused->name) == 0) { | 290 | if (focused->name && strcmp(cont->name, focused->name) == 0) { |
286 | matches++; | 291 | matches++; |
@@ -300,7 +305,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
300 | swayc_t *cont_ws = swayc_parent_by_type(cont, C_WORKSPACE); | 305 | swayc_t *cont_ws = swayc_parent_by_type(cont, C_WORKSPACE); |
301 | if (!cont_ws || !cont_ws->name) { | 306 | if (!cont_ws || !cont_ws->name) { |
302 | // ignore | 307 | // ignore |
303 | } else if (strcmp(crit->raw, "focused") == 0) { | 308 | } else if (crit_is_focused(crit->raw)) { |
304 | swayc_t *focused_ws = swayc_active_workspace(); | 309 | swayc_t *focused_ws = swayc_active_workspace(); |
305 | if (focused_ws->name && strcmp(cont_ws->name, focused_ws->name) == 0) { | 310 | if (focused_ws->name && strcmp(cont_ws->name, focused_ws->name) == 0) { |
306 | matches++; | 311 | matches++; |