diff options
Diffstat (limited to 'sway/criteria.c')
-rw-r--r-- | sway/criteria.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sway/criteria.c b/sway/criteria.c index 97cf667e..e16b4fa8 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdlib.h> | 1 | #include <stdlib.h> |
3 | #include <stdio.h> | 2 | #include <stdio.h> |
4 | #include <stdbool.h> | 3 | #include <stdbool.h> |
@@ -19,6 +18,7 @@ | |||
19 | bool criteria_is_empty(struct criteria *criteria) { | 18 | bool criteria_is_empty(struct criteria *criteria) { |
20 | return !criteria->title | 19 | return !criteria->title |
21 | && !criteria->shell | 20 | && !criteria->shell |
21 | && !criteria->all | ||
22 | && !criteria->app_id | 22 | && !criteria->app_id |
23 | && !criteria->con_mark | 23 | && !criteria->con_mark |
24 | && !criteria->con_id | 24 | && !criteria->con_id |
@@ -96,7 +96,8 @@ void criteria_destroy(struct criteria *criteria) { | |||
96 | pattern_destroy(criteria->window_role); | 96 | pattern_destroy(criteria->window_role); |
97 | #endif | 97 | #endif |
98 | pattern_destroy(criteria->con_mark); | 98 | pattern_destroy(criteria->con_mark); |
99 | free(criteria->workspace); | 99 | pattern_destroy(criteria->workspace); |
100 | free(criteria->target); | ||
100 | free(criteria->cmdlist); | 101 | free(criteria->cmdlist); |
101 | free(criteria->raw); | 102 | free(criteria->raw); |
102 | free(criteria); | 103 | free(criteria); |
@@ -189,7 +190,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
189 | if (criteria->title) { | 190 | if (criteria->title) { |
190 | const char *title = view_get_title(view); | 191 | const char *title = view_get_title(view); |
191 | if (!title) { | 192 | if (!title) { |
192 | return false; | 193 | title = ""; |
193 | } | 194 | } |
194 | 195 | ||
195 | switch (criteria->title->match_type) { | 196 | switch (criteria->title->match_type) { |
@@ -209,7 +210,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
209 | if (criteria->shell) { | 210 | if (criteria->shell) { |
210 | const char *shell = view_get_shell(view); | 211 | const char *shell = view_get_shell(view); |
211 | if (!shell) { | 212 | if (!shell) { |
212 | return false; | 213 | shell = ""; |
213 | } | 214 | } |
214 | 215 | ||
215 | switch (criteria->shell->match_type) { | 216 | switch (criteria->shell->match_type) { |
@@ -229,7 +230,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
229 | if (criteria->app_id) { | 230 | if (criteria->app_id) { |
230 | const char *app_id = view_get_app_id(view); | 231 | const char *app_id = view_get_app_id(view); |
231 | if (!app_id) { | 232 | if (!app_id) { |
232 | return false; | 233 | app_id = ""; |
233 | } | 234 | } |
234 | 235 | ||
235 | switch (criteria->app_id->match_type) { | 236 | switch (criteria->app_id->match_type) { |
@@ -261,7 +262,7 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
261 | if (criteria->class) { | 262 | if (criteria->class) { |
262 | const char *class = view_get_class(view); | 263 | const char *class = view_get_class(view); |
263 | if (!class) { | 264 | if (!class) { |
264 | return false; | 265 | class = ""; |
265 | } | 266 | } |
266 | 267 | ||
267 | switch (criteria->class->match_type) { | 268 | switch (criteria->class->match_type) { |
@@ -281,12 +282,12 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
281 | if (criteria->instance) { | 282 | if (criteria->instance) { |
282 | const char *instance = view_get_instance(view); | 283 | const char *instance = view_get_instance(view); |
283 | if (!instance) { | 284 | if (!instance) { |
284 | return false; | 285 | instance = ""; |
285 | } | 286 | } |
286 | 287 | ||
287 | switch (criteria->instance->match_type) { | 288 | switch (criteria->instance->match_type) { |
288 | case PATTERN_FOCUSED: | 289 | case PATTERN_FOCUSED: |
289 | if (focused && strcmp(instance, view_get_instance(focused))) { | 290 | if (focused && lenient_strcmp(instance, view_get_instance(focused))) { |
290 | return false; | 291 | return false; |
291 | } | 292 | } |
292 | break; | 293 | break; |
@@ -301,12 +302,12 @@ static bool criteria_matches_view(struct criteria *criteria, | |||
301 | if (criteria->window_role) { | 302 | if (criteria->window_role) { |
302 | const char *window_role = view_get_window_role(view); | 303 | const char *window_role = view_get_window_role(view); |
303 | if (!window_role) { | 304 | if (!window_role) { |
304 | return false; | 305 | window_role = ""; |
305 | } | 306 | } |
306 | 307 | ||
307 | switch (criteria->window_role->match_type) { | 308 | switch (criteria->window_role->match_type) { |
308 | case PATTERN_FOCUSED: | 309 | case PATTERN_FOCUSED: |
309 | if (focused && strcmp(window_role, view_get_window_role(focused))) { | 310 | if (focused && lenient_strcmp(window_role, view_get_window_role(focused))) { |
310 | return false; | 311 | return false; |
311 | } | 312 | } |
312 | break; | 313 | break; |
@@ -455,6 +456,7 @@ static enum atom_name parse_window_type(const char *type) { | |||
455 | #endif | 456 | #endif |
456 | 457 | ||
457 | enum criteria_token { | 458 | enum criteria_token { |
459 | T_ALL, | ||
458 | T_APP_ID, | 460 | T_APP_ID, |
459 | T_CON_ID, | 461 | T_CON_ID, |
460 | T_CON_MARK, | 462 | T_CON_MARK, |
@@ -477,7 +479,9 @@ enum criteria_token { | |||
477 | }; | 479 | }; |
478 | 480 | ||
479 | static enum criteria_token token_from_name(char *name) { | 481 | static enum criteria_token token_from_name(char *name) { |
480 | if (strcmp(name, "app_id") == 0) { | 482 | if (strcmp(name, "all") == 0) { |
483 | return T_ALL; | ||
484 | } else if (strcmp(name, "app_id") == 0) { | ||
481 | return T_APP_ID; | 485 | return T_APP_ID; |
482 | } else if (strcmp(name, "con_id") == 0) { | 486 | } else if (strcmp(name, "con_id") == 0) { |
483 | return T_CON_ID; | 487 | return T_CON_ID; |
@@ -523,8 +527,8 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) { | |||
523 | return false; | 527 | return false; |
524 | } | 528 | } |
525 | 529 | ||
526 | // Require value, unless token is floating or tiled | 530 | // Require value, unless token is all, floating or tiled |
527 | if (!value && token != T_FLOATING && token != T_TILING) { | 531 | if (!value && token != T_ALL && token != T_FLOATING && token != T_TILING) { |
528 | const char *fmt = "Token '%s' requires a value"; | 532 | const char *fmt = "Token '%s' requires a value"; |
529 | int len = strlen(fmt) + strlen(name) - 1; | 533 | int len = strlen(fmt) + strlen(name) - 1; |
530 | error = malloc(len); | 534 | error = malloc(len); |
@@ -534,6 +538,9 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) { | |||
534 | 538 | ||
535 | char *endptr = NULL; | 539 | char *endptr = NULL; |
536 | switch (token) { | 540 | switch (token) { |
541 | case T_ALL: | ||
542 | criteria->all = true; | ||
543 | break; | ||
537 | case T_TITLE: | 544 | case T_TITLE: |
538 | pattern_create(&criteria->title, value); | 545 | pattern_create(&criteria->title, value); |
539 | break; | 546 | break; |