commit cb33701f5ee742b659afd660fa98c294f6faf5a8
parent 08142c3f3ab41320cffe4d6cc03c09a9c6c53ce8
Author: Simon Ser <contact@emersion.fr>
Date: Thu, 10 Jul 2025 16:45:29 +0200
Add xdg_toplevel tag to criteria
Diffstat:
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/include/sway/criteria.h b/include/sway/criteria.h
@@ -56,6 +56,7 @@ struct criteria {
struct pattern *sandbox_engine;
struct pattern *sandbox_app_id;
struct pattern *sandbox_instance_id;
+ struct pattern *tag;
};
bool criteria_is_empty(struct criteria *criteria);
diff --git a/sway/criteria.c b/sway/criteria.c
@@ -37,7 +37,8 @@ bool criteria_is_empty(struct criteria *criteria) {
&& !criteria->pid
&& !criteria->sandbox_engine
&& !criteria->sandbox_app_id
- && !criteria->sandbox_instance_id;
+ && !criteria->sandbox_instance_id
+ && !criteria->tag;
}
// The error pointer is used for parsing functions, and saves having to pass it
@@ -104,6 +105,7 @@ void criteria_destroy(struct criteria *criteria) {
pattern_destroy(criteria->sandbox_engine);
pattern_destroy(criteria->sandbox_app_id);
pattern_destroy(criteria->sandbox_instance_id);
+ pattern_destroy(criteria->tag);
free(criteria->target);
free(criteria->cmdlist);
free(criteria->raw);
@@ -314,6 +316,26 @@ static bool criteria_matches_view(struct criteria *criteria,
}
}
+ if (criteria->tag) {
+ const char *tag = view_get_tag(view);
+ if (!tag) {
+ return false;
+ }
+
+ switch (criteria->tag->match_type) {
+ case PATTERN_FOCUSED:
+ if (focused && lenient_strcmp(tag, view_get_tag(focused))) {
+ return false;
+ }
+ break;
+ case PATTERN_PCRE2:
+ if (regex_cmp(tag, criteria->tag->regex) < 0) {
+ return false;
+ }
+ break;
+ }
+ }
+
if (!criteria_matches_container(criteria, view->container)) {
return false;
}
@@ -544,6 +566,7 @@ enum criteria_token {
T_SANDBOX_ENGINE,
T_SANDBOX_APP_ID,
T_SANDBOX_INSTANCE_ID,
+ T_TAG,
T_INVALID,
};
@@ -589,6 +612,8 @@ static enum criteria_token token_from_name(char *name) {
return T_SANDBOX_APP_ID;
} else if (strcmp(name, "sandbox_instance_id") == 0) {
return T_SANDBOX_INSTANCE_ID;
+ } else if (strcmp(name, "tag") == 0) {
+ return T_TAG;
}
return T_INVALID;
}
@@ -700,6 +725,9 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
case T_SANDBOX_INSTANCE_ID:
pattern_create(&criteria->sandbox_instance_id, value);
break;
+ case T_TAG:
+ pattern_create(&criteria->tag, value);
+ break;
case T_INVALID:
break;
}
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
@@ -1055,6 +1055,9 @@ The following attributes may be matched with:
Can be a regular expression. If value is \_\_focused\_\_, then the shell
must be the same as that of the currently focused window.
+*tag*
+ Compare value against the tag. _tag_ is specific to Wayland applications.
+
*tiling*
Matches tiling windows.