From 29f5cc7508ffe8f267e52b7c39c6525ccfab1e45 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 20:06:25 +1000 Subject: [PATCH] Implement window_role criteria token Depends on https://github.com/swaywm/wlroots/pull/1226 --- include/sway/tree/view.h | 1 + sway/criteria.c | 17 ++++++++++------- sway/desktop/xwayland.c | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 382ab6b9..30d3e742 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -170,6 +170,7 @@ struct sway_xwayland_view { struct wl_listener request_activate; struct wl_listener set_title; struct wl_listener set_class; + struct wl_listener set_role; struct wl_listener set_window_type; struct wl_listener set_hints; struct wl_listener map; diff --git a/sway/criteria.c b/sway/criteria.c index acc70d1b..feca904a 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -160,7 +160,10 @@ static bool criteria_matches_view(struct criteria *criteria, } if (criteria->window_role) { - // TODO + const char *role = view_get_window_role(view); + if (!role || regex_cmp(role, criteria->window_role) != 0) { + return false; + } } if (criteria->window_type != ATOM_LAST) { @@ -368,7 +371,7 @@ static char *get_focused_prop(enum criteria_token token) { value = view_get_shell(view); break; case T_TITLE: - value = view_get_class(view); + value = view_get_title(view); break; case T_WORKSPACE: { @@ -388,21 +391,21 @@ static char *get_focused_prop(enum criteria_token token) { snprintf(id_str, id_size, "%zu", id); value = id_str; break; - 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); + value = view_get_window_role(view); break; - case T_WINDOW_TYPE: + case T_WINDOW_TYPE: // These do not support __focused__ + case T_ID: #endif + case T_CON_MARK: + case T_FLOATING: case T_TILING: case T_URGENT: case T_INVALID: diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 10faf91d..94a30239 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -154,6 +154,8 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p return view->wlr_xwayland_surface->class; case VIEW_PROP_INSTANCE: return view->wlr_xwayland_surface->instance; + case VIEW_PROP_WINDOW_ROLE: + return view->wlr_xwayland_surface->role; default: return NULL; } @@ -340,6 +342,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&xwayland_view->request_activate.link); wl_list_remove(&xwayland_view->set_title.link); wl_list_remove(&xwayland_view->set_class.link); + wl_list_remove(&xwayland_view->set_role.link); wl_list_remove(&xwayland_view->set_window_type.link); wl_list_remove(&xwayland_view->set_hints.link); wl_list_remove(&xwayland_view->map.link); @@ -500,6 +503,17 @@ static void handle_set_class(struct wl_listener *listener, void *data) { view_execute_criteria(view); } +static void handle_set_role(struct wl_listener *listener, void *data) { + struct sway_xwayland_view *xwayland_view = + wl_container_of(listener, xwayland_view, set_role); + struct sway_view *view = &xwayland_view->view; + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + if (!xsurface->mapped) { + return; + } + view_execute_criteria(view); +} + static void handle_set_window_type(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, set_window_type); @@ -587,6 +601,9 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&xsurface->events.set_class, &xwayland_view->set_class); xwayland_view->set_class.notify = handle_set_class; + wl_signal_add(&xsurface->events.set_role, &xwayland_view->set_role); + xwayland_view->set_role.notify = handle_set_role; + wl_signal_add(&xsurface->events.set_window_type, &xwayland_view->set_window_type); xwayland_view->set_window_type.notify = handle_set_window_type;