diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-04-24 14:59:49 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-04-24 20:08:32 +1000 |
commit | 72767e1cc302e7aee9645c1eae3f51abe53fb378 (patch) | |
tree | 5220706816f7e4601f4213812ef1eb3e4cc7fa4b /sway/tree/view.c | |
parent | Merge pull request #1851 from RyanDwyer/container-descendants-crash (diff) | |
download | sway-72767e1cc302e7aee9645c1eae3f51abe53fb378.tar.gz sway-72767e1cc302e7aee9645c1eae3f51abe53fb378.tar.zst sway-72767e1cc302e7aee9645c1eae3f51abe53fb378.zip |
Implement criteria commands
Implements the following commands:
* for_window [...] <cmdlist>
* assign [...] <workspace>
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ | |||
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,28 @@ 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 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
216 | struct sway_container *prior_workspace = | ||
217 | container_parent(view->swayc, C_WORKSPACE); | ||
218 | list_t *criteria = criteria_for(view->swayc); | ||
219 | for (int i = 0; i < criteria->length; i++) { | ||
220 | struct criteria *crit = criteria->items[i]; | ||
221 | wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", | ||
222 | crit->crit_raw, view, crit->cmdlist); | ||
223 | struct cmd_results *res = execute_command(crit->cmdlist, NULL); | ||
224 | if (res->status != CMD_SUCCESS) { | ||
225 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); | ||
226 | } | ||
227 | free_cmd_results(res); | ||
228 | // view must be focused for commands to affect it, | ||
229 | // so always refocus in-between command lists | ||
230 | seat_set_focus(seat, view->swayc); | ||
231 | } | ||
232 | list_free(criteria); | ||
233 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); | ||
234 | } | ||
235 | |||
211 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 236 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
212 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 237 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
213 | return; | 238 | return; |
@@ -234,6 +259,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
234 | 259 | ||
235 | view_damage(view, true); | 260 | view_damage(view, true); |
236 | view_handle_container_reparent(&view->container_reparent, NULL); | 261 | view_handle_container_reparent(&view->container_reparent, NULL); |
262 | |||
263 | view_execute_criteria(view); | ||
237 | } | 264 | } |
238 | 265 | ||
239 | void view_unmap(struct sway_view *view) { | 266 | void view_unmap(struct sway_view *view) { |