move criteria "instance", "class" and "window_role" inside HAVE_XWAYLAND ifdefs"

This commit is contained in:
Pascal Pascher 2018-09-03 14:25:48 +02:00
parent f998601821
commit 93673095f0
2 changed files with 53 additions and 53 deletions

View file

@ -23,15 +23,15 @@ struct criteria {
pcre *title; pcre *title;
pcre *shell; pcre *shell;
pcre *app_id; pcre *app_id;
pcre *class;
pcre *instance;
pcre *con_mark; pcre *con_mark;
uint32_t con_id; // internal ID uint32_t con_id; // internal ID
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
pcre *class;
uint32_t id; // X11 window ID uint32_t id; // X11 window ID
pcre *instance;
pcre *window_role;
enum atom_name window_type; enum atom_name window_type;
#endif #endif
pcre *window_role;
bool floating; bool floating;
bool tiling; bool tiling;
char urgent; // 'l' for latest or 'o' for oldest char urgent; // 'l' for latest or 'o' for oldest

View file

@ -18,15 +18,15 @@ bool criteria_is_empty(struct criteria *criteria) {
return !criteria->title return !criteria->title
&& !criteria->shell && !criteria->shell
&& !criteria->app_id && !criteria->app_id
&& !criteria->class
&& !criteria->instance
&& !criteria->con_mark && !criteria->con_mark
&& !criteria->con_id && !criteria->con_id
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
&& !criteria->class
&& !criteria->id && !criteria->id
&& !criteria->instance
&& !criteria->window_role
&& criteria->window_type == ATOM_LAST && criteria->window_type == ATOM_LAST
#endif #endif
&& !criteria->window_role
&& !criteria->floating && !criteria->floating
&& !criteria->tiling && !criteria->tiling
&& !criteria->urgent && !criteria->urgent
@ -37,10 +37,12 @@ void criteria_destroy(struct criteria *criteria) {
pcre_free(criteria->title); pcre_free(criteria->title);
pcre_free(criteria->shell); pcre_free(criteria->shell);
pcre_free(criteria->app_id); pcre_free(criteria->app_id);
#ifdef HAVE_XWAYLAND
pcre_free(criteria->class); pcre_free(criteria->class);
pcre_free(criteria->instance); pcre_free(criteria->instance);
pcre_free(criteria->con_mark);
pcre_free(criteria->window_role); pcre_free(criteria->window_role);
#endif
pcre_free(criteria->con_mark);
free(criteria->workspace); free(criteria->workspace);
free(criteria->cmdlist); free(criteria->cmdlist);
free(criteria->raw); free(criteria->raw);
@ -115,21 +117,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false; return false;
} }
} }
if (criteria->class) {
const char *class = view_get_class(view);
if (!class || regex_cmp(class, criteria->class) != 0) {
return false;
}
}
if (criteria->instance) {
const char *instance = view_get_instance(view);
if (!instance || regex_cmp(instance, criteria->instance) != 0) {
return false;
}
}
if (criteria->con_mark) { if (criteria->con_mark) {
bool exists = false; bool exists = false;
for (int i = 0; i < view->marks->length; ++i) { for (int i = 0; i < view->marks->length; ++i) {
@ -156,13 +144,25 @@ static bool criteria_matches_view(struct criteria *criteria,
return false; return false;
} }
} }
#endif
if (criteria->class) {
const char *class = view_get_class(view);
if (!class || regex_cmp(class, criteria->class) != 0) {
return false;
}
}
if (criteria->instance) {
const char *instance = view_get_instance(view);
if (!instance || regex_cmp(instance, criteria->instance) != 0) {
return false;
}
}
if (criteria->window_role) { if (criteria->window_role) {
// TODO // TODO
} }
#ifdef HAVE_XWAYLAND
if (criteria->window_type != ATOM_LAST) { if (criteria->window_type != ATOM_LAST) {
if (!view_has_window_type(view, criteria->window_type)) { if (!view_has_window_type(view, criteria->window_type)) {
return false; return false;
@ -292,20 +292,20 @@ static enum atom_name parse_window_type(const char *type) {
enum criteria_token { enum criteria_token {
T_APP_ID, T_APP_ID,
T_CLASS,
T_CON_ID, T_CON_ID,
T_CON_MARK, T_CON_MARK,
T_FLOATING, T_FLOATING,
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
T_CLASS,
T_ID, T_ID,
T_INSTANCE,
T_WINDOW_ROLE,
T_WINDOW_TYPE, T_WINDOW_TYPE,
#endif #endif
T_INSTANCE,
T_SHELL, T_SHELL,
T_TILING, T_TILING,
T_TITLE, T_TITLE,
T_URGENT, T_URGENT,
T_WINDOW_ROLE,
T_WORKSPACE, T_WORKSPACE,
T_INVALID, T_INVALID,
@ -314,28 +314,28 @@ enum criteria_token {
static enum criteria_token token_from_name(char *name) { static enum criteria_token token_from_name(char *name) {
if (strcmp(name, "app_id") == 0) { if (strcmp(name, "app_id") == 0) {
return T_APP_ID; return T_APP_ID;
} else if (strcmp(name, "class") == 0) {
return T_CLASS;
} else if (strcmp(name, "con_id") == 0) { } else if (strcmp(name, "con_id") == 0) {
return T_CON_ID; return T_CON_ID;
} else if (strcmp(name, "con_mark") == 0) { } else if (strcmp(name, "con_mark") == 0) {
return T_CON_MARK; return T_CON_MARK;
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
} else if (strcmp(name, "class") == 0) {
return T_CLASS;
} else if (strcmp(name, "id") == 0) { } else if (strcmp(name, "id") == 0) {
return T_ID; return T_ID;
} else if (strcmp(name, "instance") == 0) {
return T_INSTANCE;
} else if (strcmp(name, "window_role") == 0) {
return T_WINDOW_ROLE;
} else if (strcmp(name, "window_type") == 0) { } else if (strcmp(name, "window_type") == 0) {
return T_WINDOW_TYPE; return T_WINDOW_TYPE;
#endif #endif
} else if (strcmp(name, "instance") == 0) {
return T_INSTANCE;
} else if (strcmp(name, "shell") == 0) { } else if (strcmp(name, "shell") == 0) {
return T_SHELL; return T_SHELL;
} else if (strcmp(name, "title") == 0) { } else if (strcmp(name, "title") == 0) {
return T_TITLE; return T_TITLE;
} else if (strcmp(name, "urgent") == 0) { } else if (strcmp(name, "urgent") == 0) {
return T_URGENT; return T_URGENT;
} else if (strcmp(name, "window_role") == 0) {
return T_WINDOW_ROLE;
} else if (strcmp(name, "workspace") == 0) { } else if (strcmp(name, "workspace") == 0) {
return T_WORKSPACE; return T_WORKSPACE;
} }
@ -364,21 +364,12 @@ static char *get_focused_prop(enum criteria_token token) {
case T_APP_ID: case T_APP_ID:
value = view_get_app_id(view); value = view_get_app_id(view);
break; break;
case T_CLASS:
value = view_get_class(view);
break;
case T_INSTANCE:
value = view_get_instance(view);
break;
case T_SHELL: case T_SHELL:
value = view_get_shell(view); value = view_get_shell(view);
break; break;
case T_TITLE: case T_TITLE:
value = view_get_class(view); value = view_get_class(view);
break; break;
case T_WINDOW_ROLE:
value = view_get_class(view);
break;
case T_WORKSPACE: case T_WORKSPACE:
{ {
struct sway_container *ws = container_parent(focus, C_WORKSPACE); struct sway_container *ws = container_parent(focus, C_WORKSPACE);
@ -400,7 +391,16 @@ static char *get_focused_prop(enum criteria_token token) {
case T_CON_MARK: // These do not support __focused__ case T_CON_MARK: // These do not support __focused__
case T_FLOATING: case T_FLOATING:
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
case T_CLASS:
value = view_get_class(view);
break;
case T_ID: case T_ID:
case T_INSTANCE:
value = view_get_instance(view);
break;
case T_WINDOW_ROLE:
value = view_get_class(view);
break;
case T_WINDOW_TYPE: case T_WINDOW_TYPE:
#endif #endif
case T_TILING: case T_TILING:
@ -451,12 +451,6 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
case T_APP_ID: case T_APP_ID:
generate_regex(&criteria->app_id, effective_value); generate_regex(&criteria->app_id, effective_value);
break; break;
case T_CLASS:
generate_regex(&criteria->class, effective_value);
break;
case T_INSTANCE:
generate_regex(&criteria->instance, effective_value);
break;
case T_CON_ID: case T_CON_ID:
criteria->con_id = strtoul(effective_value, &endptr, 10); criteria->con_id = strtoul(effective_value, &endptr, 10);
if (*endptr != 0) { if (*endptr != 0) {
@ -466,12 +460,9 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
case T_CON_MARK: case T_CON_MARK:
generate_regex(&criteria->con_mark, effective_value); generate_regex(&criteria->con_mark, effective_value);
break; break;
case T_WINDOW_ROLE:
generate_regex(&criteria->window_role, effective_value);
break;
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
case T_WINDOW_TYPE: case T_CLASS:
criteria->window_type = parse_window_type(effective_value); generate_regex(&criteria->class, effective_value);
break; break;
case T_ID: case T_ID:
criteria->id = strtoul(effective_value, &endptr, 10); criteria->id = strtoul(effective_value, &endptr, 10);
@ -479,6 +470,15 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
error = strdup("The value for 'id' should be numeric"); error = strdup("The value for 'id' should be numeric");
} }
break; break;
case T_INSTANCE:
generate_regex(&criteria->instance, effective_value);
break;
case T_WINDOW_ROLE:
generate_regex(&criteria->window_role, effective_value);
break;
case T_WINDOW_TYPE:
criteria->window_type = parse_window_type(effective_value);
break;
#endif #endif
case T_FLOATING: case T_FLOATING:
criteria->floating = true; criteria->floating = true;