1
1
mirror of https://github.com/swaywm/sway synced 2024-11-18 04:33:59 +01:00

implement property criteria

This commit is contained in:
Tony Crisci 2018-01-21 09:17:51 -05:00
parent 0e3eae4baa
commit 6b03b1205d

@ -275,28 +275,39 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
if (cont->type != C_VIEW) { if (cont->type != C_VIEW) {
return false; return false;
} }
struct sway_view *view = cont->sway_view;
int matches = 0; int matches = 0;
for (int i = 0; i < tokens->length; i++) { for (int i = 0; i < tokens->length; i++) {
struct crit_token *crit = tokens->items[i]; struct crit_token *crit = tokens->items[i];
switch (crit->type) { switch (crit->type) {
case CRIT_CLASS: // TODO case CRIT_CLASS:
break; {
case CRIT_CON_ID: { const char *class = view_get_class(cont->sway_view);
char *endptr; if (!class) {
size_t crit_id = strtoul(crit->raw, &endptr, 10); break;
}
if (*endptr == 0 && cont->id == crit_id) { if (crit->regex && regex_cmp(class, crit->regex) == 0) {
++matches; matches++;
}
break;
} }
case CRIT_CON_ID:
{
char *endptr;
size_t crit_id = strtoul(crit->raw, &endptr, 10);
if (*endptr == 0 && cont->id == crit_id) {
++matches;
}
break;
}
case CRIT_CON_MARK:
// TODO
break; break;
} case CRIT_FLOATING:
case CRIT_CON_MARK: // TODO // TODO
break; break;
case CRIT_FLOATING: // TODO case CRIT_ID:
break; // TODO
case CRIT_ID: // TODO
break; break;
case CRIT_APP_ID: case CRIT_APP_ID:
{ {
@ -310,24 +321,44 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
} }
break; break;
} }
case CRIT_INSTANCE: // TODO case CRIT_INSTANCE:
break; {
case CRIT_TILING: // TODO const char *instance = view_get_instance(cont->sway_view);
if (!instance) {
break;
}
if (crit->regex && regex_cmp(instance, crit->regex) == 0) {
matches++;
}
break;
}
case CRIT_TILING:
// TODO
break; break;
case CRIT_TITLE: case CRIT_TITLE:
if (!cont->name) { {
// ignore const char *title = view_get_title(cont->sway_view);
} else if (crit->regex && regex_cmp(cont->name, crit->regex) == 0) { if (!title) {
matches++; break;
}
if (crit->regex && regex_cmp(title, crit->regex) == 0) {
matches++;
}
break;
} }
break; case CRIT_URGENT:
case CRIT_URGENT: // "latest" or "oldest" // TODO "latest" or "oldest"
break; break;
case CRIT_WINDOW_ROLE: case CRIT_WINDOW_ROLE:
// TODO
break; break;
case CRIT_WINDOW_TYPE: case CRIT_WINDOW_TYPE:
// TODO
break; break;
case CRIT_WORKSPACE: // TODO case CRIT_WORKSPACE:
// TODO
break; break;
default: default:
sway_abort("Invalid criteria type (%i)", crit->type); sway_abort("Invalid criteria type (%i)", crit->type);