diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-01 23:04:49 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-01 23:04:49 +1000 |
commit | f4ec3083766280a5197cf40680bf991cc9afa41b (patch) | |
tree | b20160b4d0b0798bd0b6a6050a455b5285479442 | |
parent | 1f1b1b34d6398d463658317dea06f640482f3caa (diff) |
Implement window_type criteria token
-rw-r--r-- | include/sway/criteria.h | 2 | ||||
-rw-r--r-- | include/sway/xwayland.h | 1 | ||||
-rw-r--r-- | sway/criteria.c | 45 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 1 |
4 files changed, 42 insertions, 7 deletions
diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 7a1e547b..af12ffd7 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -31,7 +31,7 @@ struct criteria { uint32_t id; // X11 window ID #endif pcre *window_role; - uint32_t window_type; + enum atom_name window_type; bool floating; bool tiling; char urgent; // 'l' for latest or 'o' for oldest diff --git a/include/sway/xwayland.h b/include/sway/xwayland.h index 78d1053b..121edad3 100644 --- a/include/sway/xwayland.h +++ b/include/sway/xwayland.h @@ -5,6 +5,7 @@ #include <xcb/xproto.h> enum atom_name { + NET_WM_WINDOW_TYPE_NORMAL, NET_WM_WINDOW_TYPE_DIALOG, NET_WM_WINDOW_TYPE_UTILITY, NET_WM_WINDOW_TYPE_TOOLBAR, diff --git a/sway/criteria.c b/sway/criteria.c index 5452c4ee..13176fa1 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <stdio.h> #include <stdbool.h> +#include <strings.h> #include <pcre.h> #include "sway/criteria.h" #include "sway/tree/container.h" @@ -25,7 +26,7 @@ bool criteria_is_empty(struct criteria *criteria) { && !criteria->id #endif && !criteria->window_role - && !criteria->window_type + && criteria->window_type == ATOM_LAST && !criteria->floating && !criteria->tiling && !criteria->urgent @@ -50,6 +51,23 @@ 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 + if (view->type != SWAY_VIEW_XWAYLAND) { + return false; + } + struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; + struct sway_xwayland *xwayland = &server.xwayland; + xcb_atom_t desired_atom = xwayland->atoms[name]; + for (size_t i = 0; i < surface->window_type_len; ++i) { + if (surface->window_type[i] == desired_atom) { + return true; + } + } +#endif + return false; +} + static int cmp_urgent(const void *_a, const void *_b) { struct sway_view *a = *(void **)_a; struct sway_view *b = *(void **)_b; @@ -144,9 +162,8 @@ static bool criteria_matches_view(struct criteria *criteria, // TODO } - if (criteria->window_type) { - uint32_t type = view_get_window_type(view); - if (!type || type != criteria->window_type) { + if (criteria->window_type != ATOM_LAST) { + if (!view_has_window_type(view, criteria->window_type)) { return false; } } @@ -254,6 +271,21 @@ static bool generate_regex(pcre **regex, char *value) { return true; } +static enum atom_name parse_window_type(const char *type) { + if (strcasecmp(type, "normal") == 0) { + return NET_WM_WINDOW_TYPE_NORMAL; + } else if (strcasecmp(type, "dialog") == 0) { + return NET_WM_WINDOW_TYPE_DIALOG; + } else if (strcasecmp(type, "utility") == 0) { + return NET_WM_WINDOW_TYPE_UTILITY; + } else if (strcasecmp(type, "toolbar") == 0) { + return NET_WM_WINDOW_TYPE_TOOLBAR; + } else if (strcasecmp(type, "splash") == 0) { + return NET_WM_WINDOW_TYPE_SPLASH; + } + return ATOM_LAST; // ie. invalid +} + enum criteria_token { T_APP_ID, T_CLASS, @@ -434,7 +466,7 @@ static bool parse_token(struct criteria *criteria, char *name, char *value) { generate_regex(&criteria->window_role, effective_value); break; case T_WINDOW_TYPE: - // TODO: This is a string but will be stored as an enum or integer + criteria->window_type = parse_window_type(effective_value); break; #ifdef HAVE_XWAYLAND case T_ID: @@ -526,7 +558,8 @@ struct criteria *criteria_parse(char *raw, char **error_arg) { } ++head; - struct criteria *criteria = calloc(sizeof(struct criteria), 1); + struct criteria *criteria = calloc(1, sizeof(struct criteria)); + criteria->window_type = ATOM_LAST; // default value char *name = NULL, *value = NULL; bool in_quotes = false; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 4e401008..2adc28c5 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -17,6 +17,7 @@ #include "sway/tree/view.h" static const char *atom_map[ATOM_LAST] = { + "_NET_WM_WINDOW_TYPE_NORMAL", "_NET_WM_WINDOW_TYPE_DIALOG", "_NET_WM_WINDOW_TYPE_UTILITY", "_NET_WM_WINDOW_TYPE_TOOLBAR", |