diff options
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index 92767188..3eeb1d97 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -2,8 +2,11 @@ | |||
2 | #include <wayland-server.h> | 2 | #include <wayland-server.h> |
3 | #include <wlr/types/wlr_output_layout.h> | 3 | #include <wlr/types/wlr_output_layout.h> |
4 | #include "log.h" | 4 | #include "log.h" |
5 | #include "sway/criteria.h" | ||
6 | #include "sway/commands.h" | ||
5 | #include "sway/ipc-server.h" | 7 | #include "sway/ipc-server.h" |
6 | #include "sway/output.h" | 8 | #include "sway/output.h" |
9 | #include "sway/input/seat.h" | ||
7 | #include "sway/tree/container.h" | 10 | #include "sway/tree/container.h" |
8 | #include "sway/tree/layout.h" | 11 | #include "sway/tree/layout.h" |
9 | #include "sway/tree/view.h" | 12 | #include "sway/tree/view.h" |
@@ -208,6 +211,31 @@ static void view_handle_container_reparent(struct wl_listener *listener, | |||
208 | } | 211 | } |
209 | } | 212 | } |
210 | 213 | ||
214 | static void view_execute_criteria(struct sway_view *view) { | ||
215 | if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { | ||
216 | return; | ||
217 | } | ||
218 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
219 | struct sway_container *prior_workspace = | ||
220 | container_parent(view->swayc, C_WORKSPACE); | ||
221 | list_t *criteria = criteria_for(view->swayc); | ||
222 | for (int i = 0; i < criteria->length; i++) { | ||
223 | struct criteria *crit = criteria->items[i]; | ||
224 | wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", | ||
225 | crit->crit_raw, view, crit->cmdlist); | ||
226 | struct cmd_results *res = execute_command(crit->cmdlist, NULL); | ||
227 | if (res->status != CMD_SUCCESS) { | ||
228 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); | ||
229 | } | ||
230 | free_cmd_results(res); | ||
231 | // view must be focused for commands to affect it, | ||
232 | // so always refocus in-between command lists | ||
233 | seat_set_focus(seat, view->swayc); | ||
234 | } | ||
235 | list_free(criteria); | ||
236 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); | ||
237 | } | ||
238 | |||
211 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 239 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
212 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 240 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
213 | return; | 241 | return; |
@@ -234,6 +262,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
234 | 262 | ||
235 | view_damage(view, true); | 263 | view_damage(view, true); |
236 | view_handle_container_reparent(&view->container_reparent, NULL); | 264 | view_handle_container_reparent(&view->container_reparent, NULL); |
265 | |||
266 | view_execute_criteria(view); | ||
237 | } | 267 | } |
238 | 268 | ||
239 | void view_unmap(struct sway_view *view) { | 269 | void view_unmap(struct sway_view *view) { |