Merge pull request #2564 from ppascher/master

Fix window_type with disabled xwayland support
master
Drew DeVault 6 years ago committed by GitHub
commit 0b61bae8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -18,15 +18,15 @@ bool criteria_is_empty(struct criteria *criteria) {
return !criteria->title
&& !criteria->shell
&& !criteria->app_id
&& !criteria->class
&& !criteria->instance
&& !criteria->con_mark
&& !criteria->con_id
#ifdef HAVE_XWAYLAND
&& !criteria->class
&& !criteria->id
#endif
&& !criteria->instance
&& !criteria->window_role
&& criteria->window_type == ATOM_LAST
#endif
&& !criteria->floating
&& !criteria->tiling
&& !criteria->urgent
@ -37,10 +37,12 @@ void criteria_destroy(struct criteria *criteria) {
pcre_free(criteria->title);
pcre_free(criteria->shell);
pcre_free(criteria->app_id);
#ifdef HAVE_XWAYLAND
pcre_free(criteria->class);
pcre_free(criteria->instance);
pcre_free(criteria->con_mark);
pcre_free(criteria->window_role);
#endif
pcre_free(criteria->con_mark);
free(criteria->workspace);
free(criteria->cmdlist);
free(criteria->raw);
@ -51,8 +53,8 @@ static int regex_cmp(const char *item, const pcre *regex) {
return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
}
static bool view_has_window_type(struct sway_view *view, enum atom_name name) {
#ifdef HAVE_XWAYLAND
static bool view_has_window_type(struct sway_view *view, enum atom_name name) {
if (view->type != SWAY_VIEW_XWAYLAND) {
return false;
}
@ -64,9 +66,9 @@ static bool view_has_window_type(struct sway_view *view, enum atom_name name) {
return true;
}
}
#endif
return false;
}
#endif
static int cmp_urgent(const void *_a, const void *_b) {
struct sway_view *a = *(void **)_a;
@ -115,21 +117,7 @@ static bool criteria_matches_view(struct criteria *criteria,
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) {
bool exists = false;
for (int i = 0; i < view->marks->length; ++i) {
@ -156,7 +144,20 @@ static bool criteria_matches_view(struct criteria *criteria,
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) {
// TODO
@ -167,6 +168,7 @@ static bool criteria_matches_view(struct criteria *criteria,
return false;
}
}
#endif
if (criteria->floating) {
if (!container_is_floating(view->swayc)) {
@ -271,6 +273,7 @@ static bool generate_regex(pcre **regex, char *value) {
return true;
}
#ifdef HAVE_XWAYLAND
static enum atom_name parse_window_type(const char *type) {
if (strcasecmp(type, "normal") == 0) {
return NET_WM_WINDOW_TYPE_NORMAL;
@ -285,23 +288,24 @@ static enum atom_name parse_window_type(const char *type) {
}
return ATOM_LAST; // ie. invalid
}
#endif
enum criteria_token {
T_APP_ID,
T_CLASS,
T_CON_ID,
T_CON_MARK,
T_FLOATING,
#ifdef HAVE_XWAYLAND
T_CLASS,
T_ID,
#endif
T_INSTANCE,
T_WINDOW_ROLE,
T_WINDOW_TYPE,
#endif
T_SHELL,
T_TILING,
T_TITLE,
T_URGENT,
T_WINDOW_ROLE,
T_WINDOW_TYPE,
T_WORKSPACE,
T_INVALID,
@ -310,28 +314,28 @@ enum criteria_token {
static enum criteria_token token_from_name(char *name) {
if (strcmp(name, "app_id") == 0) {
return T_APP_ID;
} else if (strcmp(name, "class") == 0) {
return T_CLASS;
} else if (strcmp(name, "con_id") == 0) {
return T_CON_ID;
} else if (strcmp(name, "con_mark") == 0) {
return T_CON_MARK;
#ifdef HAVE_XWAYLAND
} else if (strcmp(name, "class") == 0) {
return T_CLASS;
} else if (strcmp(name, "id") == 0) {
return T_ID;
#endif
} 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) {
return T_WINDOW_TYPE;
#endif
} else if (strcmp(name, "shell") == 0) {
return T_SHELL;
} else if (strcmp(name, "title") == 0) {
return T_TITLE;
} else if (strcmp(name, "urgent") == 0) {
return T_URGENT;
} else if (strcmp(name, "window_role") == 0) {
return T_WINDOW_ROLE;
} else if (strcmp(name, "window_type") == 0) {
return T_WINDOW_TYPE;
} else if (strcmp(name, "workspace") == 0) {
return T_WORKSPACE;
}
@ -360,21 +364,12 @@ static char *get_focused_prop(enum criteria_token token) {
case T_APP_ID:
value = view_get_app_id(view);
break;
case T_CLASS:
value = view_get_class(view);
break;
case T_INSTANCE:
value = view_get_instance(view);
break;
case T_SHELL:
value = view_get_shell(view);
break;
case T_TITLE:
value = view_get_class(view);
break;
case T_WINDOW_ROLE:
value = view_get_class(view);
break;
case T_WORKSPACE:
{
struct sway_container *ws = container_parent(focus, C_WORKSPACE);
@ -396,11 +391,20 @@ static char *get_focused_prop(enum criteria_token token) {
case T_CON_MARK: // These do not support __focused__
case T_FLOATING:
#ifdef HAVE_XWAYLAND
case T_CLASS:
value = view_get_class(view);
break;
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:
#endif
case T_TILING:
case T_URGENT:
case T_WINDOW_TYPE:
case T_INVALID:
break;
}
@ -447,12 +451,6 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
case T_APP_ID:
generate_regex(&criteria->app_id, effective_value);
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:
criteria->con_id = strtoul(effective_value, &endptr, 10);
if (*endptr != 0) {
@ -462,19 +460,25 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) {
case T_CON_MARK:
generate_regex(&criteria->con_mark, 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;
#ifdef HAVE_XWAYLAND
case T_CLASS:
generate_regex(&criteria->class, effective_value);
break;
case T_ID:
criteria->id = strtoul(effective_value, &endptr, 10);
if (*endptr != 0) {
error = strdup("The value for 'id' should be numeric");
}
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
case T_FLOATING:
criteria->floating = true;
@ -559,7 +563,9 @@ struct criteria *criteria_parse(char *raw, char **error_arg) {
++head;
struct criteria *criteria = calloc(1, sizeof(struct criteria));
#ifdef HAVE_XWAYLAND
criteria->window_type = ATOM_LAST; // default value
#endif
char *name = NULL, *value = NULL;
bool in_quotes = false;

Loading…
Cancel
Save