diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-08-11 08:29:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-11 08:29:34 -0400 |
commit | 2aa6d98c5a6d37c759e1e9cc84032a95fb193793 (patch) | |
tree | c7e26e67ae4e4fa393edc97f301b4e4a989d228f /sway/tree/container.c | |
parent | Merge pull request #2448 from RyanDwyer/remove-container-has-child (diff) | |
parent | Remove container_for_each_descendant_bfs (diff) | |
download | sway-2aa6d98c5a6d37c759e1e9cc84032a95fb193793.tar.gz sway-2aa6d98c5a6d37c759e1e9cc84032a95fb193793.tar.zst sway-2aa6d98c5a6d37c759e1e9cc84032a95fb193793.zip |
Merge pull request #2449 from RyanDwyer/remove-bfs
Remove container_for_each_descendant_bfs
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index cec51af4..435d71e2 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -25,21 +25,6 @@ | |||
25 | #include "log.h" | 25 | #include "log.h" |
26 | #include "stringop.h" | 26 | #include "stringop.h" |
27 | 27 | ||
28 | static list_t *bfs_queue; | ||
29 | |||
30 | static list_t *get_bfs_queue() { | ||
31 | if (!bfs_queue) { | ||
32 | bfs_queue = create_list(); | ||
33 | if (!bfs_queue) { | ||
34 | wlr_log(WLR_ERROR, "could not allocate list for bfs queue"); | ||
35 | return NULL; | ||
36 | } | ||
37 | } | ||
38 | bfs_queue->length = 0; | ||
39 | |||
40 | return bfs_queue; | ||
41 | } | ||
42 | |||
43 | const char *container_type_to_str(enum sway_container_type type) { | 28 | const char *container_type_to_str(enum sway_container_type type) { |
44 | switch (type) { | 29 | switch (type) { |
45 | case C_ROOT: | 30 | case C_ROOT: |
@@ -450,7 +435,7 @@ struct sway_container *container_close(struct sway_container *con) { | |||
450 | if (con->type == C_VIEW) { | 435 | if (con->type == C_VIEW) { |
451 | view_close(con->sway_view); | 436 | view_close(con->sway_view); |
452 | } else { | 437 | } else { |
453 | container_for_each_descendant_dfs(con, container_close_func, NULL); | 438 | container_for_each_descendant(con, container_close_func, NULL); |
454 | } | 439 | } |
455 | 440 | ||
456 | return parent; | 441 | return parent; |
@@ -760,7 +745,7 @@ struct sway_container *container_at(struct sway_container *workspace, | |||
760 | return NULL; | 745 | return NULL; |
761 | } | 746 | } |
762 | 747 | ||
763 | void container_for_each_descendant_dfs(struct sway_container *container, | 748 | void container_for_each_descendant(struct sway_container *container, |
764 | void (*f)(struct sway_container *container, void *data), | 749 | void (*f)(struct sway_container *container, void *data), |
765 | void *data) { | 750 | void *data) { |
766 | if (!container) { | 751 | if (!container) { |
@@ -769,43 +754,19 @@ void container_for_each_descendant_dfs(struct sway_container *container, | |||
769 | if (container->children) { | 754 | if (container->children) { |
770 | for (int i = 0; i < container->children->length; ++i) { | 755 | for (int i = 0; i < container->children->length; ++i) { |
771 | struct sway_container *child = container->children->items[i]; | 756 | struct sway_container *child = container->children->items[i]; |
772 | container_for_each_descendant_dfs(child, f, data); | 757 | container_for_each_descendant(child, f, data); |
773 | } | 758 | } |
774 | } | 759 | } |
775 | if (container->type == C_WORKSPACE) { | 760 | if (container->type == C_WORKSPACE) { |
776 | struct sway_container *floating = container->sway_workspace->floating; | 761 | struct sway_container *floating = container->sway_workspace->floating; |
777 | for (int i = 0; i < floating->children->length; ++i) { | 762 | for (int i = 0; i < floating->children->length; ++i) { |
778 | struct sway_container *child = floating->children->items[i]; | 763 | struct sway_container *child = floating->children->items[i]; |
779 | container_for_each_descendant_dfs(child, f, data); | 764 | container_for_each_descendant(child, f, data); |
780 | } | 765 | } |
781 | } | 766 | } |
782 | f(container, data); | 767 | f(container, data); |
783 | } | 768 | } |
784 | 769 | ||
785 | void container_for_each_descendant_bfs(struct sway_container *con, | ||
786 | void (*f)(struct sway_container *con, void *data), void *data) { | ||
787 | list_t *queue = get_bfs_queue(); | ||
788 | if (!queue) { | ||
789 | return; | ||
790 | } | ||
791 | |||
792 | if (queue == NULL) { | ||
793 | wlr_log(WLR_ERROR, "could not allocate list"); | ||
794 | return; | ||
795 | } | ||
796 | |||
797 | list_add(queue, con); | ||
798 | |||
799 | struct sway_container *current = NULL; | ||
800 | while (queue->length) { | ||
801 | current = queue->items[0]; | ||
802 | list_del(queue, 0); | ||
803 | f(current, data); | ||
804 | // TODO floating containers | ||
805 | list_cat(queue, current->children); | ||
806 | } | ||
807 | } | ||
808 | |||
809 | bool container_has_ancestor(struct sway_container *descendant, | 770 | bool container_has_ancestor(struct sway_container *descendant, |
810 | struct sway_container *ancestor) { | 771 | struct sway_container *ancestor) { |
811 | while (descendant->type != C_ROOT) { | 772 | while (descendant->type != C_ROOT) { |
@@ -1276,8 +1237,7 @@ void container_set_fullscreen(struct sway_container *container, bool enable) { | |||
1276 | container_set_fullscreen(workspace->sway_workspace->fullscreen, false); | 1237 | container_set_fullscreen(workspace->sway_workspace->fullscreen, false); |
1277 | } | 1238 | } |
1278 | 1239 | ||
1279 | container_for_each_descendant_dfs(container, | 1240 | container_for_each_descendant(container, set_fullscreen_iterator, &enable); |
1280 | set_fullscreen_iterator, &enable); | ||
1281 | 1241 | ||
1282 | container->is_fullscreen = enable; | 1242 | container->is_fullscreen = enable; |
1283 | 1243 | ||