From 72767e1cc302e7aee9645c1eae3f51abe53fb378 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 24 Apr 2018 14:59:49 +1000 Subject: Implement criteria commands Implements the following commands: * for_window [...] * assign [...] --- sway/tree/view.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'sway/tree') diff --git a/sway/tree/view.c b/sway/tree/view.c index 92767188..7c3b4049 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -2,8 +2,11 @@ #include #include #include "log.h" +#include "sway/criteria.h" +#include "sway/commands.h" #include "sway/ipc-server.h" #include "sway/output.h" +#include "sway/input/seat.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/tree/view.h" @@ -208,6 +211,28 @@ static void view_handle_container_reparent(struct wl_listener *listener, } } +static void view_execute_criteria(struct sway_view *view) { + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *prior_workspace = + container_parent(view->swayc, C_WORKSPACE); + list_t *criteria = criteria_for(view->swayc); + for (int i = 0; i < criteria->length; i++) { + struct criteria *crit = criteria->items[i]; + wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", + crit->crit_raw, view, crit->cmdlist); + struct cmd_results *res = execute_command(crit->cmdlist, NULL); + if (res->status != CMD_SUCCESS) { + wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); + } + free_cmd_results(res); + // view must be focused for commands to affect it, + // so always refocus in-between command lists + seat_set_focus(seat, view->swayc); + } + list_free(criteria); + seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); +} + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { return; @@ -234,6 +259,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view_damage(view, true); view_handle_container_reparent(&view->container_reparent, NULL); + + view_execute_criteria(view); } void view_unmap(struct sway_view *view) { -- cgit v1.2.3 From 30a74889366baf4b98bb3d398042508fe07a9906 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 24 Apr 2018 20:06:35 +1000 Subject: Add assert to view_execute_criteria() --- sway/tree/view.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sway/tree') diff --git a/sway/tree/view.c b/sway/tree/view.c index 7c3b4049..3d22d3e4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -212,6 +212,9 @@ static void view_handle_container_reparent(struct wl_listener *listener, } static void view_execute_criteria(struct sway_view *view) { + if (!sway_assert(view->swayc, "cannot run criteria for unmanaged view")) { + return; + } struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *prior_workspace = container_parent(view->swayc, C_WORKSPACE); -- cgit v1.2.3 From dfc26c664f8c1b007f15ff24a3055774af200c69 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 24 Apr 2018 20:14:22 +1000 Subject: Update wording about unmanaged/unmapped views --- include/sway/tree/view.h | 2 +- sway/tree/view.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'sway/tree') diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 648a74c4..7237ea2a 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -39,7 +39,7 @@ struct sway_view { enum sway_view_type type; const struct sway_view_impl *impl; - struct sway_container *swayc; // NULL for unmanaged views + struct sway_container *swayc; // NULL for unmapped views struct wlr_surface *surface; // NULL for unmapped views int width, height; bool is_fullscreen; diff --git a/sway/tree/view.c b/sway/tree/view.c index 3d22d3e4..3eeb1d97 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -212,7 +212,7 @@ static void view_handle_container_reparent(struct wl_listener *listener, } static void view_execute_criteria(struct sway_view *view) { - if (!sway_assert(view->swayc, "cannot run criteria for unmanaged view")) { + if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { return; } struct sway_seat *seat = input_manager_current_seat(input_manager); -- cgit v1.2.3