diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index ac79356a..d3931612 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -5,9 +5,23 @@ | |||
5 | #include "sway/container.h" | 5 | #include "sway/container.h" |
6 | #include "sway/layout.h" | 6 | #include "sway/layout.h" |
7 | #include "sway/output.h" | 7 | #include "sway/output.h" |
8 | #include "sway/view.h" | ||
8 | #include "sway/workspace.h" | 9 | #include "sway/workspace.h" |
9 | #include "log.h" | 10 | #include "log.h" |
10 | 11 | ||
12 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
13 | void (*func)(swayc_t *item, void *data), void *data) { | ||
14 | for (int i = 0; i < root->children->length; ++i) { | ||
15 | swayc_t *item = root->children->items[i]; | ||
16 | if (item->type == type) { | ||
17 | func(item, data); | ||
18 | } | ||
19 | if (item->children && item->children->length) { | ||
20 | swayc_descendants_of_type(item, type, func, data); | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
11 | static swayc_t *new_swayc(enum swayc_types type) { | 25 | static swayc_t *new_swayc(enum swayc_types type) { |
12 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 26 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
13 | static size_t next_id = 1; | 27 | static size_t next_id = 1; |
@@ -69,3 +83,28 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
69 | sort_workspaces(output); | 83 | sort_workspaces(output); |
70 | return workspace; | 84 | return workspace; |
71 | } | 85 | } |
86 | |||
87 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | ||
88 | if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { | ||
89 | return NULL; | ||
90 | } | ||
91 | const char *title = sway_view->iface.get_prop(sway_view, VIEW_PROP_TITLE); | ||
92 | swayc_t *swayc = new_swayc(C_VIEW); | ||
93 | sway_log(L_DEBUG, "Adding new view %p:%s to container %p %d", | ||
94 | swayc, title, sibling, sibling ? sibling->type : 0); | ||
95 | // Setup values | ||
96 | swayc->sway_view = sway_view; | ||
97 | swayc->name = title ? strdup(title) : NULL; | ||
98 | swayc->width = 0; | ||
99 | swayc->height = 0; | ||
100 | |||
101 | if (sibling->type == C_WORKSPACE) { | ||
102 | // Case of focused workspace, just create as child of it | ||
103 | add_child(sibling, swayc); | ||
104 | } else { | ||
105 | // Regular case, create as sibling of current container | ||
106 | // TODO WLR | ||
107 | //add_sibling(sibling, swayc); | ||
108 | } | ||
109 | return swayc; | ||
110 | } | ||