diff options
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 113 |
1 files changed, 31 insertions, 82 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index 7d921e0e..424c1084 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -3,7 +3,6 @@ | |||
3 | #include <wayland-server.h> | 3 | #include <wayland-server.h> |
4 | #include <wlr/render/wlr_renderer.h> | 4 | #include <wlr/render/wlr_renderer.h> |
5 | #include <wlr/types/wlr_output_layout.h> | 5 | #include <wlr/types/wlr_output_layout.h> |
6 | #include "list.h" | ||
7 | #include "log.h" | 6 | #include "log.h" |
8 | #include "sway/criteria.h" | 7 | #include "sway/criteria.h" |
9 | #include "sway/commands.h" | 8 | #include "sway/commands.h" |
@@ -20,7 +19,6 @@ void view_init(struct sway_view *view, enum sway_view_type type, | |||
20 | const struct sway_view_impl *impl) { | 19 | const struct sway_view_impl *impl) { |
21 | view->type = type; | 20 | view->type = type; |
22 | view->impl = impl; | 21 | view->impl = impl; |
23 | view->executed_criteria = create_list(); | ||
24 | wl_signal_init(&view->events.unmap); | 22 | wl_signal_init(&view->events.unmap); |
25 | } | 23 | } |
26 | 24 | ||
@@ -33,8 +31,6 @@ void view_destroy(struct sway_view *view) { | |||
33 | view_unmap(view); | 31 | view_unmap(view); |
34 | } | 32 | } |
35 | 33 | ||
36 | list_free(view->executed_criteria); | ||
37 | |||
38 | container_destroy(view->swayc); | 34 | container_destroy(view->swayc); |
39 | 35 | ||
40 | if (view->impl->destroy) { | 36 | if (view->impl->destroy) { |
@@ -45,47 +41,33 @@ void view_destroy(struct sway_view *view) { | |||
45 | } | 41 | } |
46 | 42 | ||
47 | const char *view_get_title(struct sway_view *view) { | 43 | const char *view_get_title(struct sway_view *view) { |
48 | if (view->impl->get_string_prop) { | 44 | if (view->impl->get_prop) { |
49 | return view->impl->get_string_prop(view, VIEW_PROP_TITLE); | 45 | return view->impl->get_prop(view, VIEW_PROP_TITLE); |
50 | } | 46 | } |
51 | return NULL; | 47 | return NULL; |
52 | } | 48 | } |
53 | 49 | ||
54 | const char *view_get_app_id(struct sway_view *view) { | 50 | const char *view_get_app_id(struct sway_view *view) { |
55 | if (view->impl->get_string_prop) { | 51 | if (view->impl->get_prop) { |
56 | return view->impl->get_string_prop(view, VIEW_PROP_APP_ID); | 52 | return view->impl->get_prop(view, VIEW_PROP_APP_ID); |
57 | } | 53 | } |
58 | return NULL; | 54 | return NULL; |
59 | } | 55 | } |
60 | 56 | ||
61 | const char *view_get_class(struct sway_view *view) { | 57 | const char *view_get_class(struct sway_view *view) { |
62 | if (view->impl->get_string_prop) { | 58 | if (view->impl->get_prop) { |
63 | return view->impl->get_string_prop(view, VIEW_PROP_CLASS); | 59 | return view->impl->get_prop(view, VIEW_PROP_CLASS); |
64 | } | 60 | } |
65 | return NULL; | 61 | return NULL; |
66 | } | 62 | } |
67 | 63 | ||
68 | const char *view_get_instance(struct sway_view *view) { | 64 | const char *view_get_instance(struct sway_view *view) { |
69 | if (view->impl->get_string_prop) { | 65 | if (view->impl->get_prop) { |
70 | return view->impl->get_string_prop(view, VIEW_PROP_INSTANCE); | 66 | return view->impl->get_prop(view, VIEW_PROP_INSTANCE); |
71 | } | 67 | } |
72 | return NULL; | 68 | return NULL; |
73 | } | 69 | } |
74 | 70 | ||
75 | uint32_t view_get_x11_window_id(struct sway_view *view) { | ||
76 | if (view->impl->get_int_prop) { | ||
77 | return view->impl->get_int_prop(view, VIEW_PROP_X11_WINDOW_ID); | ||
78 | } | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | uint32_t view_get_window_type(struct sway_view *view) { | ||
83 | if (view->impl->get_int_prop) { | ||
84 | return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE); | ||
85 | } | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | const char *view_get_type(struct sway_view *view) { | 71 | const char *view_get_type(struct sway_view *view) { |
90 | switch(view->type) { | 72 | switch(view->type) { |
91 | case SWAY_VIEW_WL_SHELL: | 73 | case SWAY_VIEW_WL_SHELL: |
@@ -181,13 +163,15 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { | |||
181 | struct sway_container *focus, *focus_ws; | 163 | struct sway_container *focus, *focus_ws; |
182 | wl_list_for_each(seat, &input_manager->seats, link) { | 164 | wl_list_for_each(seat, &input_manager->seats, link) { |
183 | focus = seat_get_focus(seat); | 165 | focus = seat_get_focus(seat); |
184 | focus_ws = focus; | 166 | if (focus) { |
185 | if (focus_ws->type != C_WORKSPACE) { | 167 | focus_ws = focus; |
186 | focus_ws = container_parent(focus_ws, C_WORKSPACE); | 168 | if (focus && focus_ws->type != C_WORKSPACE) { |
187 | } | 169 | focus_ws = container_parent(focus_ws, C_WORKSPACE); |
188 | seat_set_focus(seat, view->swayc); | 170 | } |
189 | if (focus_ws != workspace) { | 171 | seat_set_focus(seat, view->swayc); |
190 | seat_set_focus(seat, focus); | 172 | if (focus_ws != workspace) { |
173 | seat_set_focus(seat, focus); | ||
174 | } | ||
191 | } | 175 | } |
192 | } | 176 | } |
193 | } else { | 177 | } else { |
@@ -300,36 +284,19 @@ static void view_handle_container_reparent(struct wl_listener *listener, | |||
300 | } | 284 | } |
301 | } | 285 | } |
302 | 286 | ||
303 | static bool view_has_executed_criteria(struct sway_view *view, | 287 | static void view_execute_criteria(struct sway_view *view) { |
304 | struct criteria *criteria) { | 288 | if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { |
305 | for (int i = 0; i < view->executed_criteria->length; ++i) { | ||
306 | struct criteria *item = view->executed_criteria->items[i]; | ||
307 | if (item == criteria) { | ||
308 | return true; | ||
309 | } | ||
310 | } | ||
311 | return false; | ||
312 | } | ||
313 | |||
314 | void view_execute_criteria(struct sway_view *view) { | ||
315 | if (!view->swayc) { | ||
316 | return; | 289 | return; |
317 | } | 290 | } |
318 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 291 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
319 | struct sway_container *prior_workspace = | 292 | struct sway_container *prior_workspace = |
320 | container_parent(view->swayc, C_WORKSPACE); | 293 | container_parent(view->swayc, C_WORKSPACE); |
321 | list_t *criterias = criteria_for_view(view, CT_COMMAND); | 294 | list_t *criteria = criteria_for(view->swayc); |
322 | for (int i = 0; i < criterias->length; i++) { | 295 | for (int i = 0; i < criteria->length; i++) { |
323 | struct criteria *criteria = criterias->items[i]; | 296 | struct criteria *crit = criteria->items[i]; |
324 | wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw); | 297 | wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", |
325 | if (view_has_executed_criteria(view, criteria)) { | 298 | crit->crit_raw, view, crit->cmdlist); |
326 | wlr_log(L_DEBUG, "Criteria already executed"); | 299 | struct cmd_results *res = execute_command(crit->cmdlist, NULL); |
327 | continue; | ||
328 | } | ||
329 | wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", | ||
330 | criteria->raw, view, criteria->cmdlist); | ||
331 | list_add(view->executed_criteria, criteria); | ||
332 | struct cmd_results *res = execute_command(criteria->cmdlist, NULL); | ||
333 | if (res->status != CMD_SUCCESS) { | 300 | if (res->status != CMD_SUCCESS) { |
334 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); | 301 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); |
335 | } | 302 | } |
@@ -338,7 +305,7 @@ void view_execute_criteria(struct sway_view *view) { | |||
338 | // so always refocus in-between command lists | 305 | // so always refocus in-between command lists |
339 | seat_set_focus(seat, view->swayc); | 306 | seat_set_focus(seat, view->swayc); |
340 | } | 307 | } |
341 | list_free(criterias); | 308 | list_free(criteria); |
342 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); | 309 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); |
343 | } | 310 | } |
344 | 311 | ||
@@ -348,26 +315,9 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
348 | } | 315 | } |
349 | 316 | ||
350 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 317 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
351 | struct sway_container *focus = seat_get_focus(seat); | 318 | struct sway_container *focus = seat_get_focus_inactive(seat, |
352 | struct sway_container *cont = NULL; | 319 | &root_container); |
353 | 320 | struct sway_container *cont = container_view_create(focus, view); | |
354 | // Check if there's any `assign` criteria for the view | ||
355 | list_t *criterias = criteria_for_view(view, | ||
356 | CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); | ||
357 | if (criterias->length) { | ||
358 | struct criteria *criteria = criterias->items[0]; | ||
359 | if (criteria->type == CT_ASSIGN_WORKSPACE) { | ||
360 | struct sway_container *workspace = workspace_by_name(criteria->target); | ||
361 | if (!workspace) { | ||
362 | workspace = workspace_create(NULL, criteria->target); | ||
363 | } | ||
364 | focus = seat_get_focus_inactive(seat, workspace); | ||
365 | } else { | ||
366 | // TODO: CT_ASSIGN_OUTPUT | ||
367 | } | ||
368 | } | ||
369 | free(criterias); | ||
370 | cont = container_view_create(focus, view); | ||
371 | 321 | ||
372 | view->surface = wlr_surface; | 322 | view->surface = wlr_surface; |
373 | view->swayc = cont; | 323 | view->swayc = cont; |
@@ -385,11 +335,10 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
385 | arrange_children_of(cont->parent); | 335 | arrange_children_of(cont->parent); |
386 | input_manager_set_focus(input_manager, cont); | 336 | input_manager_set_focus(input_manager, cont); |
387 | 337 | ||
388 | view_update_title(view, false); | ||
389 | view_execute_criteria(view); | ||
390 | |||
391 | container_damage_whole(cont); | 338 | container_damage_whole(cont); |
392 | view_handle_container_reparent(&view->container_reparent, NULL); | 339 | view_handle_container_reparent(&view->container_reparent, NULL); |
340 | |||
341 | view_execute_criteria(view); | ||
393 | } | 342 | } |
394 | 343 | ||
395 | void view_unmap(struct sway_view *view) { | 344 | void view_unmap(struct sway_view *view) { |