From 587e320cd85b3c635b653b6e16b21ce5fb7bade0 Mon Sep 17 00:00:00 2001 From: Pascal Pascher Date: Mon, 3 Sep 2018 11:13:50 +0200 Subject: [PATCH 1/3] Fixed window_type with disabled xwayland support. --- include/sway/criteria.h | 2 +- meson_options.txt | 2 +- sway/criteria.c | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/sway/criteria.h b/include/sway/criteria.h index af12ffd7..89fe369c 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -29,9 +29,9 @@ struct criteria { uint32_t con_id; // internal ID #ifdef HAVE_XWAYLAND uint32_t id; // X11 window ID + enum atom_name window_type; #endif pcre *window_role; - enum atom_name window_type; bool floating; bool tiling; char urgent; // 'l' for latest or 'o' for oldest diff --git a/meson_options.txt b/meson_options.txt index 50d646fd..0b31b6b4 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,4 +4,4 @@ option('default-wallpaper', type: 'boolean', value: true, description: 'Install option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') -option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') +option('enable-xwayland', type: 'boolean', value: false, description: 'Enable support for X11 applications') diff --git a/sway/criteria.c b/sway/criteria.c index 13176fa1..4fad45bc 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -24,9 +24,9 @@ bool criteria_is_empty(struct criteria *criteria) { && !criteria->con_id #ifdef HAVE_XWAYLAND && !criteria->id + && criteria->window_type == ATOM_LAST #endif && !criteria->window_role - && criteria->window_type == ATOM_LAST && !criteria->floating && !criteria->tiling && !criteria->urgent @@ -51,8 +51,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 +64,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; @@ -162,11 +162,13 @@ static bool criteria_matches_view(struct criteria *criteria, // TODO } +#ifdef HAVE_XWAYLAND if (criteria->window_type != ATOM_LAST) { if (!view_has_window_type(view, criteria->window_type)) { 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,6 +288,7 @@ static enum atom_name parse_window_type(const char *type) { } return ATOM_LAST; // ie. invalid } +#endif enum criteria_token { T_APP_ID, @@ -294,6 +298,7 @@ enum criteria_token { T_FLOATING, #ifdef HAVE_XWAYLAND T_ID, + T_WINDOW_TYPE, #endif T_INSTANCE, T_SHELL, @@ -301,7 +306,6 @@ enum criteria_token { T_TITLE, T_URGENT, T_WINDOW_ROLE, - T_WINDOW_TYPE, T_WORKSPACE, T_INVALID, @@ -319,6 +323,8 @@ static enum criteria_token token_from_name(char *name) { #ifdef HAVE_XWAYLAND } else if (strcmp(name, "id") == 0) { return T_ID; + } else if (strcmp(name, "window_type") == 0) { + return T_WINDOW_TYPE; #endif } else if (strcmp(name, "instance") == 0) { return T_INSTANCE; @@ -330,8 +336,6 @@ static enum criteria_token token_from_name(char *name) { 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; } @@ -397,10 +401,10 @@ static char *get_focused_prop(enum criteria_token token) { case T_FLOATING: #ifdef HAVE_XWAYLAND case T_ID: + case T_WINDOW_TYPE: #endif case T_TILING: case T_URGENT: - case T_WINDOW_TYPE: case T_INVALID: break; } @@ -465,10 +469,10 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) { case T_WINDOW_ROLE: generate_regex(&criteria->window_role, effective_value); break; +#ifdef HAVE_XWAYLAND case T_WINDOW_TYPE: criteria->window_type = parse_window_type(effective_value); break; -#ifdef HAVE_XWAYLAND case T_ID: criteria->id = strtoul(effective_value, &endptr, 10); if (*endptr != 0) { @@ -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; From f9986018214b82bfc2b2d48e3a9e4a867812ca50 Mon Sep 17 00:00:00 2001 From: Pascal Pascher Date: Mon, 3 Sep 2018 11:17:07 +0200 Subject: [PATCH 2/3] fix window_type with disabled xwayland support --- meson_options.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson_options.txt b/meson_options.txt index 0b31b6b4..50d646fd 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,4 +4,4 @@ option('default-wallpaper', type: 'boolean', value: true, description: 'Install option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') -option('enable-xwayland', type: 'boolean', value: false, description: 'Enable support for X11 applications') +option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') From 93673095f093a286a506415764f736d2dd62ebe9 Mon Sep 17 00:00:00 2001 From: Pascal Pascher Date: Mon, 3 Sep 2018 14:25:48 +0200 Subject: [PATCH 3/3] move criteria "instance", "class" and "window_role" inside HAVE_XWAYLAND ifdefs" --- include/sway/criteria.h | 6 +-- sway/criteria.c | 100 ++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 89fe369c..323ba01d 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -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 + pcre *instance; + pcre *window_role; enum atom_name window_type; #endif - pcre *window_role; bool floating; bool tiling; char urgent; // 'l' for latest or 'o' for oldest diff --git a/sway/criteria.c b/sway/criteria.c index 4fad45bc..acc70d1b 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -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 + && !criteria->instance + && !criteria->window_role && criteria->window_type == ATOM_LAST #endif - && !criteria->window_role && !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); @@ -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,13 +144,25 @@ 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 } -#ifdef HAVE_XWAYLAND if (criteria->window_type != ATOM_LAST) { if (!view_has_window_type(view, criteria->window_type)) { return false; @@ -292,20 +292,20 @@ static enum atom_name parse_window_type(const char *type) { enum criteria_token { T_APP_ID, - T_CLASS, T_CON_ID, T_CON_MARK, T_FLOATING, #ifdef HAVE_XWAYLAND + T_CLASS, T_ID, + T_INSTANCE, + T_WINDOW_ROLE, T_WINDOW_TYPE, #endif - T_INSTANCE, T_SHELL, T_TILING, T_TITLE, T_URGENT, - T_WINDOW_ROLE, T_WORKSPACE, T_INVALID, @@ -314,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; + } 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, "instance") == 0) { - return T_INSTANCE; } 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, "workspace") == 0) { return T_WORKSPACE; } @@ -364,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); @@ -400,7 +391,16 @@ 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: @@ -451,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) { @@ -466,12 +460,9 @@ 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; #ifdef HAVE_XWAYLAND - case T_WINDOW_TYPE: - criteria->window_type = parse_window_type(effective_value); + case T_CLASS: + generate_regex(&criteria->class, effective_value); break; case T_ID: 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"); } 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;