diff options
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 104 |
1 files changed, 82 insertions, 22 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index 424c1084..3b3b6eaf 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -3,6 +3,7 @@ | |||
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" | ||
6 | #include "log.h" | 7 | #include "log.h" |
7 | #include "sway/criteria.h" | 8 | #include "sway/criteria.h" |
8 | #include "sway/commands.h" | 9 | #include "sway/commands.h" |
@@ -19,6 +20,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, | |||
19 | const struct sway_view_impl *impl) { | 20 | const struct sway_view_impl *impl) { |
20 | view->type = type; | 21 | view->type = type; |
21 | view->impl = impl; | 22 | view->impl = impl; |
23 | view->executed_criteria = create_list(); | ||
22 | wl_signal_init(&view->events.unmap); | 24 | wl_signal_init(&view->events.unmap); |
23 | } | 25 | } |
24 | 26 | ||
@@ -31,6 +33,8 @@ void view_destroy(struct sway_view *view) { | |||
31 | view_unmap(view); | 33 | view_unmap(view); |
32 | } | 34 | } |
33 | 35 | ||
36 | list_free(view->executed_criteria); | ||
37 | |||
34 | container_destroy(view->swayc); | 38 | container_destroy(view->swayc); |
35 | 39 | ||
36 | if (view->impl->destroy) { | 40 | if (view->impl->destroy) { |
@@ -41,33 +45,54 @@ void view_destroy(struct sway_view *view) { | |||
41 | } | 45 | } |
42 | 46 | ||
43 | const char *view_get_title(struct sway_view *view) { | 47 | const char *view_get_title(struct sway_view *view) { |
44 | if (view->impl->get_prop) { | 48 | if (view->impl->get_string_prop) { |
45 | return view->impl->get_prop(view, VIEW_PROP_TITLE); | 49 | return view->impl->get_string_prop(view, VIEW_PROP_TITLE); |
46 | } | 50 | } |
47 | return NULL; | 51 | return NULL; |
48 | } | 52 | } |
49 | 53 | ||
50 | const char *view_get_app_id(struct sway_view *view) { | 54 | const char *view_get_app_id(struct sway_view *view) { |
51 | if (view->impl->get_prop) { | 55 | if (view->impl->get_string_prop) { |
52 | return view->impl->get_prop(view, VIEW_PROP_APP_ID); | 56 | return view->impl->get_string_prop(view, VIEW_PROP_APP_ID); |
53 | } | 57 | } |
54 | return NULL; | 58 | return NULL; |
55 | } | 59 | } |
56 | 60 | ||
57 | const char *view_get_class(struct sway_view *view) { | 61 | const char *view_get_class(struct sway_view *view) { |
58 | if (view->impl->get_prop) { | 62 | if (view->impl->get_string_prop) { |
59 | return view->impl->get_prop(view, VIEW_PROP_CLASS); | 63 | return view->impl->get_string_prop(view, VIEW_PROP_CLASS); |
60 | } | 64 | } |
61 | return NULL; | 65 | return NULL; |
62 | } | 66 | } |
63 | 67 | ||
64 | const char *view_get_instance(struct sway_view *view) { | 68 | const char *view_get_instance(struct sway_view *view) { |
65 | if (view->impl->get_prop) { | 69 | if (view->impl->get_string_prop) { |
66 | return view->impl->get_prop(view, VIEW_PROP_INSTANCE); | 70 | return view->impl->get_string_prop(view, VIEW_PROP_INSTANCE); |
67 | } | 71 | } |
68 | return NULL; | 72 | return NULL; |
69 | } | 73 | } |
70 | 74 | ||
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 | const char *view_get_window_role(struct sway_view *view) { | ||
83 | if (view->impl->get_string_prop) { | ||
84 | return view->impl->get_string_prop(view, VIEW_PROP_WINDOW_ROLE); | ||
85 | } | ||
86 | return NULL; | ||
87 | } | ||
88 | |||
89 | uint32_t view_get_window_type(struct sway_view *view) { | ||
90 | if (view->impl->get_int_prop) { | ||
91 | return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE); | ||
92 | } | ||
93 | return 0; | ||
94 | } | ||
95 | |||
71 | const char *view_get_type(struct sway_view *view) { | 96 | const char *view_get_type(struct sway_view *view) { |
72 | switch(view->type) { | 97 | switch(view->type) { |
73 | case SWAY_VIEW_WL_SHELL: | 98 | case SWAY_VIEW_WL_SHELL: |
@@ -284,19 +309,36 @@ static void view_handle_container_reparent(struct wl_listener *listener, | |||
284 | } | 309 | } |
285 | } | 310 | } |
286 | 311 | ||
287 | static void view_execute_criteria(struct sway_view *view) { | 312 | static bool view_has_executed_criteria(struct sway_view *view, |
288 | if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { | 313 | struct criteria *criteria) { |
314 | for (int i = 0; i < view->executed_criteria->length; ++i) { | ||
315 | struct criteria *item = view->executed_criteria->items[i]; | ||
316 | if (item == criteria) { | ||
317 | return true; | ||
318 | } | ||
319 | } | ||
320 | return false; | ||
321 | } | ||
322 | |||
323 | void view_execute_criteria(struct sway_view *view) { | ||
324 | if (!view->swayc) { | ||
289 | return; | 325 | return; |
290 | } | 326 | } |
291 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 327 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
292 | struct sway_container *prior_workspace = | 328 | struct sway_container *prior_workspace = |
293 | container_parent(view->swayc, C_WORKSPACE); | 329 | container_parent(view->swayc, C_WORKSPACE); |
294 | list_t *criteria = criteria_for(view->swayc); | 330 | list_t *criterias = criteria_for_view(view, CT_COMMAND); |
295 | for (int i = 0; i < criteria->length; i++) { | 331 | for (int i = 0; i < criterias->length; i++) { |
296 | struct criteria *crit = criteria->items[i]; | 332 | struct criteria *criteria = criterias->items[i]; |
297 | wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", | 333 | wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw); |
298 | crit->crit_raw, view, crit->cmdlist); | 334 | if (view_has_executed_criteria(view, criteria)) { |
299 | struct cmd_results *res = execute_command(crit->cmdlist, NULL); | 335 | wlr_log(L_DEBUG, "Criteria already executed"); |
336 | continue; | ||
337 | } | ||
338 | wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", | ||
339 | criteria->raw, view, criteria->cmdlist); | ||
340 | list_add(view->executed_criteria, criteria); | ||
341 | struct cmd_results *res = execute_command(criteria->cmdlist, NULL); | ||
300 | if (res->status != CMD_SUCCESS) { | 342 | if (res->status != CMD_SUCCESS) { |
301 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); | 343 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); |
302 | } | 344 | } |
@@ -305,7 +347,7 @@ static void view_execute_criteria(struct sway_view *view) { | |||
305 | // so always refocus in-between command lists | 347 | // so always refocus in-between command lists |
306 | seat_set_focus(seat, view->swayc); | 348 | seat_set_focus(seat, view->swayc); |
307 | } | 349 | } |
308 | list_free(criteria); | 350 | list_free(criterias); |
309 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); | 351 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); |
310 | } | 352 | } |
311 | 353 | ||
@@ -315,9 +357,26 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
315 | } | 357 | } |
316 | 358 | ||
317 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 359 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
318 | struct sway_container *focus = seat_get_focus_inactive(seat, | 360 | struct sway_container *focus = seat_get_focus(seat); |
319 | &root_container); | 361 | struct sway_container *cont = NULL; |
320 | struct sway_container *cont = container_view_create(focus, view); | 362 | |
363 | // Check if there's any `assign` criteria for the view | ||
364 | list_t *criterias = criteria_for_view(view, | ||
365 | CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); | ||
366 | if (criterias->length) { | ||
367 | struct criteria *criteria = criterias->items[0]; | ||
368 | if (criteria->type == CT_ASSIGN_WORKSPACE) { | ||
369 | struct sway_container *workspace = workspace_by_name(criteria->target); | ||
370 | if (!workspace) { | ||
371 | workspace = workspace_create(NULL, criteria->target); | ||
372 | } | ||
373 | focus = seat_get_focus_inactive(seat, workspace); | ||
374 | } else { | ||
375 | // TODO: CT_ASSIGN_OUTPUT | ||
376 | } | ||
377 | } | ||
378 | free(criterias); | ||
379 | cont = container_view_create(focus, view); | ||
321 | 380 | ||
322 | view->surface = wlr_surface; | 381 | view->surface = wlr_surface; |
323 | view->swayc = cont; | 382 | view->swayc = cont; |
@@ -335,10 +394,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
335 | arrange_children_of(cont->parent); | 394 | arrange_children_of(cont->parent); |
336 | input_manager_set_focus(input_manager, cont); | 395 | input_manager_set_focus(input_manager, cont); |
337 | 396 | ||
397 | view_update_title(view, false); | ||
398 | view_execute_criteria(view); | ||
399 | |||
338 | container_damage_whole(cont); | 400 | container_damage_whole(cont); |
339 | view_handle_container_reparent(&view->container_reparent, NULL); | 401 | view_handle_container_reparent(&view->container_reparent, NULL); |
340 | |||
341 | view_execute_criteria(view); | ||
342 | } | 402 | } |
343 | 403 | ||
344 | void view_unmap(struct sway_view *view) { | 404 | void view_unmap(struct sway_view *view) { |