diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-13 08:16:36 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-14 11:38:09 +1000 |
commit | 1e9aaa54a85e98d6b46ca594b4f50770f71047ea (patch) | |
tree | cb6a2748d1c53dfc80f9faa5da7052790e668400 /sway/tree/view.c | |
parent | Actually fix swayidle (diff) | |
download | sway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.tar.gz sway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.tar.zst sway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.zip |
Revert "Revert "Merge pull request #1943 from RyanDwyer/criteria-improvements""
This reverts commit 32a572cecfd0f6072a78ce0a381a2f8365f9010a.
This reimplements the criteria overhaul in preparation for fixing a
known bug.
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 97 |
1 files changed, 75 insertions, 22 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index 2fdb14a2..8fc45f52 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" |
@@ -21,6 +22,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, | |||
21 | const struct sway_view_impl *impl) { | 22 | const struct sway_view_impl *impl) { |
22 | view->type = type; | 23 | view->type = type; |
23 | view->impl = impl; | 24 | view->impl = impl; |
25 | view->executed_criteria = create_list(); | ||
24 | wl_signal_init(&view->events.unmap); | 26 | wl_signal_init(&view->events.unmap); |
25 | } | 27 | } |
26 | 28 | ||
@@ -33,6 +35,8 @@ void view_destroy(struct sway_view *view) { | |||
33 | view_unmap(view); | 35 | view_unmap(view); |
34 | } | 36 | } |
35 | 37 | ||
38 | list_free(view->executed_criteria); | ||
39 | |||
36 | container_destroy(view->swayc); | 40 | container_destroy(view->swayc); |
37 | 41 | ||
38 | if (view->impl->destroy) { | 42 | if (view->impl->destroy) { |
@@ -43,33 +47,47 @@ void view_destroy(struct sway_view *view) { | |||
43 | } | 47 | } |
44 | 48 | ||
45 | const char *view_get_title(struct sway_view *view) { | 49 | const char *view_get_title(struct sway_view *view) { |
46 | if (view->impl->get_prop) { | 50 | if (view->impl->get_string_prop) { |
47 | return view->impl->get_prop(view, VIEW_PROP_TITLE); | 51 | return view->impl->get_string_prop(view, VIEW_PROP_TITLE); |
48 | } | 52 | } |
49 | return NULL; | 53 | return NULL; |
50 | } | 54 | } |
51 | 55 | ||
52 | const char *view_get_app_id(struct sway_view *view) { | 56 | const char *view_get_app_id(struct sway_view *view) { |
53 | if (view->impl->get_prop) { | 57 | if (view->impl->get_string_prop) { |
54 | return view->impl->get_prop(view, VIEW_PROP_APP_ID); | 58 | return view->impl->get_string_prop(view, VIEW_PROP_APP_ID); |
55 | } | 59 | } |
56 | return NULL; | 60 | return NULL; |
57 | } | 61 | } |
58 | 62 | ||
59 | const char *view_get_class(struct sway_view *view) { | 63 | const char *view_get_class(struct sway_view *view) { |
60 | if (view->impl->get_prop) { | 64 | if (view->impl->get_string_prop) { |
61 | return view->impl->get_prop(view, VIEW_PROP_CLASS); | 65 | return view->impl->get_string_prop(view, VIEW_PROP_CLASS); |
62 | } | 66 | } |
63 | return NULL; | 67 | return NULL; |
64 | } | 68 | } |
65 | 69 | ||
66 | const char *view_get_instance(struct sway_view *view) { | 70 | const char *view_get_instance(struct sway_view *view) { |
67 | if (view->impl->get_prop) { | 71 | if (view->impl->get_string_prop) { |
68 | return view->impl->get_prop(view, VIEW_PROP_INSTANCE); | 72 | return view->impl->get_string_prop(view, VIEW_PROP_INSTANCE); |
69 | } | 73 | } |
70 | return NULL; | 74 | return NULL; |
71 | } | 75 | } |
72 | 76 | ||
77 | uint32_t view_get_x11_window_id(struct sway_view *view) { | ||
78 | if (view->impl->get_int_prop) { | ||
79 | return view->impl->get_int_prop(view, VIEW_PROP_X11_WINDOW_ID); | ||
80 | } | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | uint32_t view_get_window_type(struct sway_view *view) { | ||
85 | if (view->impl->get_int_prop) { | ||
86 | return view->impl->get_int_prop(view, VIEW_PROP_WINDOW_TYPE); | ||
87 | } | ||
88 | return 0; | ||
89 | } | ||
90 | |||
73 | const char *view_get_type(struct sway_view *view) { | 91 | const char *view_get_type(struct sway_view *view) { |
74 | switch(view->type) { | 92 | switch(view->type) { |
75 | case SWAY_VIEW_WL_SHELL: | 93 | case SWAY_VIEW_WL_SHELL: |
@@ -327,19 +345,36 @@ static void view_handle_container_reparent(struct wl_listener *listener, | |||
327 | } | 345 | } |
328 | } | 346 | } |
329 | 347 | ||
330 | static void view_execute_criteria(struct sway_view *view) { | 348 | static bool view_has_executed_criteria(struct sway_view *view, |
331 | if (!sway_assert(view->swayc, "cannot run criteria for unmapped view")) { | 349 | struct criteria *criteria) { |
350 | for (int i = 0; i < view->executed_criteria->length; ++i) { | ||
351 | struct criteria *item = view->executed_criteria->items[i]; | ||
352 | if (item == criteria) { | ||
353 | return true; | ||
354 | } | ||
355 | } | ||
356 | return false; | ||
357 | } | ||
358 | |||
359 | void view_execute_criteria(struct sway_view *view) { | ||
360 | if (!view->swayc) { | ||
332 | return; | 361 | return; |
333 | } | 362 | } |
334 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 363 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
335 | struct sway_container *prior_workspace = | 364 | struct sway_container *prior_workspace = |
336 | container_parent(view->swayc, C_WORKSPACE); | 365 | container_parent(view->swayc, C_WORKSPACE); |
337 | list_t *criteria = criteria_for(view->swayc); | 366 | list_t *criterias = criteria_for_view(view, CT_COMMAND); |
338 | for (int i = 0; i < criteria->length; i++) { | 367 | for (int i = 0; i < criterias->length; i++) { |
339 | struct criteria *crit = criteria->items[i]; | 368 | struct criteria *criteria = criterias->items[i]; |
340 | wlr_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'", | 369 | wlr_log(L_DEBUG, "Checking criteria %s", criteria->raw); |
341 | crit->crit_raw, view, crit->cmdlist); | 370 | if (view_has_executed_criteria(view, criteria)) { |
342 | struct cmd_results *res = execute_command(crit->cmdlist, NULL); | 371 | wlr_log(L_DEBUG, "Criteria already executed"); |
372 | continue; | ||
373 | } | ||
374 | wlr_log(L_DEBUG, "for_window '%s' matches view %p, cmd: '%s'", | ||
375 | criteria->raw, view, criteria->cmdlist); | ||
376 | list_add(view->executed_criteria, criteria); | ||
377 | struct cmd_results *res = execute_command(criteria->cmdlist, NULL); | ||
343 | if (res->status != CMD_SUCCESS) { | 378 | if (res->status != CMD_SUCCESS) { |
344 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); | 379 | wlr_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); |
345 | } | 380 | } |
@@ -348,7 +383,7 @@ static void view_execute_criteria(struct sway_view *view) { | |||
348 | // so always refocus in-between command lists | 383 | // so always refocus in-between command lists |
349 | seat_set_focus(seat, view->swayc); | 384 | seat_set_focus(seat, view->swayc); |
350 | } | 385 | } |
351 | list_free(criteria); | 386 | list_free(criterias); |
352 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); | 387 | seat_set_focus(seat, seat_get_focus_inactive(seat, prior_workspace)); |
353 | } | 388 | } |
354 | 389 | ||
@@ -358,9 +393,26 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
358 | } | 393 | } |
359 | 394 | ||
360 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 395 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
361 | struct sway_container *focus = seat_get_focus_inactive(seat, | 396 | struct sway_container *focus = seat_get_focus(seat); |
362 | &root_container); | 397 | struct sway_container *cont = NULL; |
363 | struct sway_container *cont = container_view_create(focus, view); | 398 | |
399 | // Check if there's any `assign` criteria for the view | ||
400 | list_t *criterias = criteria_for_view(view, | ||
401 | CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); | ||
402 | if (criterias->length) { | ||
403 | struct criteria *criteria = criterias->items[0]; | ||
404 | if (criteria->type == CT_ASSIGN_WORKSPACE) { | ||
405 | struct sway_container *workspace = workspace_by_name(criteria->target); | ||
406 | if (!workspace) { | ||
407 | workspace = workspace_create(NULL, criteria->target); | ||
408 | } | ||
409 | focus = seat_get_focus_inactive(seat, workspace); | ||
410 | } else { | ||
411 | // TODO: CT_ASSIGN_OUTPUT | ||
412 | } | ||
413 | } | ||
414 | free(criterias); | ||
415 | cont = container_view_create(focus, view); | ||
364 | 416 | ||
365 | view->surface = wlr_surface; | 417 | view->surface = wlr_surface; |
366 | view->swayc = cont; | 418 | view->swayc = cont; |
@@ -378,10 +430,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
378 | arrange_children_of(cont->parent); | 430 | arrange_children_of(cont->parent); |
379 | input_manager_set_focus(input_manager, cont); | 431 | input_manager_set_focus(input_manager, cont); |
380 | 432 | ||
433 | view_update_title(view, false); | ||
434 | view_execute_criteria(view); | ||
435 | |||
381 | container_damage_whole(cont); | 436 | container_damage_whole(cont); |
382 | view_handle_container_reparent(&view->container_reparent, NULL); | 437 | view_handle_container_reparent(&view->container_reparent, NULL); |
383 | |||
384 | view_execute_criteria(view); | ||
385 | } | 438 | } |
386 | 439 | ||
387 | void view_unmap(struct sway_view *view) { | 440 | void view_unmap(struct sway_view *view) { |