diff options
author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-07-26 12:30:04 -0700 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-07-27 03:53:05 +0300 |
commit | e4bba906b68b9347c085a7833f6dbc7ddb1a41b4 (patch) | |
tree | b5291ecfd217807534a8fd537d6243a02ff2d34b /sway/criteria.c | |
parent | arrange: remove gaps for workspace location deltas (diff) | |
download | sway-e4bba906b68b9347c085a7833f6dbc7ddb1a41b4.tar.gz sway-e4bba906b68b9347c085a7833f6dbc7ddb1a41b4.tar.zst sway-e4bba906b68b9347c085a7833f6dbc7ddb1a41b4.zip |
Avoid adding duplicate criteria for no_focus and command
Diffstat (limited to 'sway/criteria.c')
-rw-r--r-- | sway/criteria.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sway/criteria.c b/sway/criteria.c index 11b41f35..b2582851 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -685,3 +685,36 @@ cleanup: | |||
685 | criteria_destroy(criteria); | 685 | criteria_destroy(criteria); |
686 | return NULL; | 686 | return NULL; |
687 | } | 687 | } |
688 | |||
689 | bool criteria_is_equal(struct criteria *left, struct criteria *right) { | ||
690 | if (left->type != right->type) { | ||
691 | return false; | ||
692 | } | ||
693 | // XXX Only implemented for CT_NO_FOCUS for now. | ||
694 | if (left->type == CT_NO_FOCUS) { | ||
695 | return strcmp(left->raw, right->raw) == 0; | ||
696 | } | ||
697 | if (left->type == CT_COMMAND) { | ||
698 | return strcmp(left->raw, right->raw) == 0 | ||
699 | && strcmp(left->cmdlist, right->cmdlist) == 0; | ||
700 | } | ||
701 | return false; | ||
702 | } | ||
703 | |||
704 | bool criteria_already_exists(struct criteria *criteria) { | ||
705 | // XXX Only implemented for CT_NO_FOCUS and CT_COMMAND for now. | ||
706 | // While criteria_is_equal also obeys this limitation, this is a shortcut | ||
707 | // to avoid processing the list. | ||
708 | if (criteria->type != CT_NO_FOCUS && criteria->type != CT_COMMAND) { | ||
709 | return false; | ||
710 | } | ||
711 | |||
712 | list_t *criterias = config->criteria; | ||
713 | for (int i = 0; i < criterias->length; ++i) { | ||
714 | struct criteria *existing = criterias->items[i]; | ||
715 | if (criteria_is_equal(criteria, existing)) { | ||
716 | return true; | ||
717 | } | ||
718 | } | ||
719 | return false; | ||
720 | } | ||