diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 59f57f94f..a99a7f28b 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -35,6 +35,7 @@ struct criteria { struct pattern *shell; struct pattern *app_id; struct pattern *con_mark; + struct pattern *cli_label; uint32_t con_id; // internal ID #if HAVE_XWAYLAND struct pattern *class; diff --git a/sway/criteria.c b/sway/criteria.c index 4711a1659..741f54e17 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -21,6 +21,7 @@ bool criteria_is_empty(struct criteria *criteria) { && !criteria->shell && !criteria->app_id && !criteria->con_mark + && !criteria->cli_label && !criteria->con_id #if HAVE_XWAYLAND && !criteria->class @@ -96,6 +97,7 @@ void criteria_destroy(struct criteria *criteria) { pattern_destroy(criteria->window_role); #endif pattern_destroy(criteria->con_mark); + pattern_destroy(criteria->cli_label); free(criteria->workspace); free(criteria->cmdlist); free(criteria->raw); @@ -246,6 +248,26 @@ static bool criteria_matches_view(struct criteria *criteria, } } + if (criteria->cli_label) { + const char *cli_label = view_get_conn_label(view); + if (!cli_label) { + return false; + } + + switch (criteria->cli_label->match_type) { + case PATTERN_FOCUSED: + if (focused && lenient_strcmp(cli_label, view_get_conn_label(focused))) { + return false; + } + break; + case PATTERN_PCRE2: + if (regex_cmp(cli_label, criteria->cli_label->regex) != 0) { + return false; + } + break; + } + } + if (!criteria_matches_container(criteria, view->container)) { return false; } @@ -458,6 +480,7 @@ enum criteria_token { T_APP_ID, T_CON_ID, T_CON_MARK, + T_CLI_LABEL, T_FLOATING, #if HAVE_XWAYLAND T_CLASS, @@ -483,6 +506,8 @@ static enum criteria_token token_from_name(char *name) { return T_CON_ID; } else if (strcmp(name, "con_mark") == 0) { return T_CON_MARK; + } else if (strcmp(name, "cli_label") == 0) { + return T_CLI_LABEL; #if HAVE_XWAYLAND } else if (strcmp(name, "class") == 0) { return T_CLASS; @@ -559,6 +584,9 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) { case T_CON_MARK: pattern_create(&criteria->con_mark, value); break; + case T_CLI_LABEL: + pattern_create(&criteria->cli_label, value); + break; #if HAVE_XWAYLAND case T_CLASS: pattern_create(&criteria->class, value); diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 8357ae04e..3e9cf8165 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -495,6 +495,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_object_add(object, "app_id", app_id ? json_object_new_string(app_id) : NULL); + const char *label = view_get_conn_label(c->view); + json_object_object_add(object, "cli_label", + label ? json_object_new_string(label) : NULL); + bool visible = view_is_visible(c->view); json_object_object_add(object, "visible", json_object_new_boolean(visible));