implement property criteria

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

View file

@ -275,15 +275,23 @@ 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:
{
const char *class = view_get_class(cont->sway_view);
if (!class) {
break; break;
case CRIT_CON_ID: { }
if (crit->regex && regex_cmp(class, crit->regex) == 0) {
matches++;
}
break;
}
case CRIT_CON_ID:
{
char *endptr; char *endptr;
size_t crit_id = strtoul(crit->raw, &endptr, 10); size_t crit_id = strtoul(crit->raw, &endptr, 10);
@ -292,11 +300,14 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
} }
break; break;
} }
case CRIT_CON_MARK: // TODO case CRIT_CON_MARK:
// TODO
break; break;
case CRIT_FLOATING: // TODO case CRIT_FLOATING:
// TODO
break; break;
case CRIT_ID: // 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:
{
const char *instance = view_get_instance(cont->sway_view);
if (!instance) {
break; break;
case CRIT_TILING: // TODO }
break;
case CRIT_TITLE: if (crit->regex && regex_cmp(instance, crit->regex) == 0) {
if (!cont->name) {
// ignore
} else if (crit->regex && regex_cmp(cont->name, crit->regex) == 0) {
matches++; matches++;
} }
break; break;
case CRIT_URGENT: // "latest" or "oldest" }
case CRIT_TILING:
// TODO
break;
case CRIT_TITLE:
{
const char *title = view_get_title(cont->sway_view);
if (!title) {
break;
}
if (crit->regex && regex_cmp(title, crit->regex) == 0) {
matches++;
}
break;
}
case CRIT_URGENT:
// 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);