aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 16:17:55 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 16:40:40 -0400
commitb90099b4b7df8068446c658ab99b58ff83648954 (patch)
treea822ef3605ce98f9d8633c24f6927bb11effbdcc /sway
parentremove swayc_t typedef (diff)
downloadsway-b90099b4b7df8068446c658ab99b58ff83648954.tar.gz
sway-b90099b4b7df8068446c658ab99b58ff83648954.tar.zst
sway-b90099b4b7df8068446c658ab99b58ff83648954.zip
rename container functions
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/focus.c4
-rw-r--r--sway/commands/kill.c2
-rw-r--r--sway/commands/layout.c4
-rw-r--r--sway/commands/output.c2
-rw-r--r--sway/commands/workspace.c12
-rw-r--r--sway/config/output.c4
-rw-r--r--sway/criteria.c12
-rw-r--r--sway/desktop/output.c14
-rw-r--r--sway/desktop/wl_shell.c6
-rw-r--r--sway/desktop/xdg_shell_v6.c6
-rw-r--r--sway/desktop/xwayland.c18
-rw-r--r--sway/input/cursor.c8
-rw-r--r--sway/input/seat.c34
-rw-r--r--sway/ipc-json.c14
-rw-r--r--sway/ipc-server.c4
-rw-r--r--sway/tree/container.c182
-rw-r--r--sway/tree/layout.c86
-rw-r--r--sway/tree/workspace.c70
18 files changed, 241 insertions, 241 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 18e9e0bf..64b05904 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -32,7 +32,7 @@ static bool parse_movement_direction(const char *name,
32} 32}
33 33
34struct cmd_results *cmd_focus(int argc, char **argv) { 34struct cmd_results *cmd_focus(int argc, char **argv) {
35 swayc_t *con = config->handler_context.current_container; 35 struct sway_container *con = config->handler_context.current_container;
36 struct sway_seat *seat = config->handler_context.seat; 36 struct sway_seat *seat = config->handler_context.seat;
37 if (con->type < C_WORKSPACE) { 37 if (con->type < C_WORKSPACE) {
38 return cmd_results_new(CMD_FAILURE, "focus", 38 return cmd_results_new(CMD_FAILURE, "focus",
@@ -51,7 +51,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
51 "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); 51 "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'");
52 } 52 }
53 53
54 swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); 54 struct sway_container *next_focus = get_swayc_in_direction(con, seat, direction);
55 if (next_focus) { 55 if (next_focus) {
56 sway_seat_set_focus(seat, next_focus); 56 sway_seat_set_focus(seat, next_focus);
57 } 57 }
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index c0faed7a..f6774767 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -6,7 +6,7 @@
6#include "sway/commands.h" 6#include "sway/commands.h"
7 7
8struct cmd_results *cmd_kill(int argc, char **argv) { 8struct cmd_results *cmd_kill(int argc, char **argv) {
9 enum swayc_types type = config->handler_context.current_container->type; 9 enum sway_container_type type = config->handler_context.current_container->type;
10 if (type != C_VIEW && type != C_CONTAINER) { 10 if (type != C_VIEW && type != C_CONTAINER) {
11 return cmd_results_new(CMD_INVALID, NULL, 11 return cmd_results_new(CMD_INVALID, NULL,
12 "Can only kill views and containers with this command"); 12 "Can only kill views and containers with this command");
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index 2b193136..e10334e2 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -10,7 +10,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
10 if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { 10 if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) {
11 return error; 11 return error;
12 } 12 }
13 swayc_t *parent = config->handler_context.current_container; 13 struct sway_container *parent = config->handler_context.current_container;
14 14
15 // TODO: floating 15 // TODO: floating
16 /* 16 /*
@@ -28,7 +28,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
28 if (strcasecmp(argv[0], "default") == 0) { 28 if (strcasecmp(argv[0], "default") == 0) {
29 swayc_change_layout(parent, parent->prev_layout); 29 swayc_change_layout(parent, parent->prev_layout);
30 if (parent->layout == L_NONE) { 30 if (parent->layout == L_NONE) {
31 swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); 31 struct sway_container *output = sway_container_parent(parent, C_OUTPUT);
32 swayc_change_layout(parent, default_layout(output)); 32 swayc_change_layout(parent, default_layout(output));
33 } 33 }
34 } else { 34 } else {
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 35bc8099..f7e3372c 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -296,7 +296,7 @@ struct cmd_results *cmd_output(int argc, char **argv) {
296 char identifier[128]; 296 char identifier[128];
297 bool all = strcmp(output->name, "*") == 0; 297 bool all = strcmp(output->name, "*") == 0;
298 for (int i = 0; i < root_container.children->length; ++i) { 298 for (int i = 0; i < root_container.children->length; ++i) {
299 swayc_t *cont = root_container.children->items[i]; 299 struct sway_container *cont = root_container.children->items[i];
300 if (cont->type != C_OUTPUT) { 300 if (cont->type != C_OUTPUT) {
301 continue; 301 continue;
302 } 302 }
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 8751dffe..8b7139a9 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -17,15 +17,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
17 17
18 int output_location = -1; 18 int output_location = -1;
19 19
20 swayc_t *current_container = config->handler_context.current_container; 20 struct sway_container *current_container = config->handler_context.current_container;
21 swayc_t *old_workspace = NULL, *old_output = NULL; 21 struct sway_container *old_workspace = NULL, *old_output = NULL;
22 if (current_container) { 22 if (current_container) {
23 if (current_container->type == C_WORKSPACE) { 23 if (current_container->type == C_WORKSPACE) {
24 old_workspace = current_container; 24 old_workspace = current_container;
25 } else { 25 } else {
26 old_workspace = swayc_parent_by_type(current_container, C_WORKSPACE); 26 old_workspace = sway_container_parent(current_container, C_WORKSPACE);
27 } 27 }
28 old_output = swayc_parent_by_type(current_container, C_OUTPUT); 28 old_output = sway_container_parent(current_container, C_OUTPUT);
29 } 29 }
30 30
31 for (int i = 0; i < argc; ++i) { 31 for (int i = 0; i < argc; ++i) {
@@ -57,7 +57,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
57 if (config->reading || !config->active) { 57 if (config->reading || !config->active) {
58 return cmd_results_new(CMD_DEFER, "workspace", NULL); 58 return cmd_results_new(CMD_DEFER, "workspace", NULL);
59 } 59 }
60 swayc_t *ws = NULL; 60 struct sway_container *ws = NULL;
61 if (strcasecmp(argv[0], "number") == 0) { 61 if (strcasecmp(argv[0], "number") == 0) {
62 if (!(ws = workspace_by_number(argv[1]))) { 62 if (!(ws = workspace_by_number(argv[1]))) {
63 char *name = join_args(argv + 1, argc - 1); 63 char *name = join_args(argv + 1, argc - 1);
@@ -92,7 +92,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
92 workspace_switch(ws); 92 workspace_switch(ws);
93 current_container = 93 current_container =
94 sway_seat_get_focus(config->handler_context.seat); 94 sway_seat_get_focus(config->handler_context.seat);
95 swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT); 95 struct sway_container *new_output = sway_container_parent(current_container, C_OUTPUT);
96 96
97 if (config->mouse_warping && old_output != new_output) { 97 if (config->mouse_warping && old_output != new_output) {
98 // TODO: Warp mouse 98 // TODO: Warp mouse
diff --git a/sway/config/output.c b/sway/config/output.c
index 9e211861..5763bd21 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -120,14 +120,14 @@ void terminate_swaybg(pid_t pid) {
120 } 120 }
121} 121}
122 122
123void apply_output_config(struct output_config *oc, swayc_t *output) { 123void apply_output_config(struct output_config *oc, struct sway_container *output) {
124 assert(output->type == C_OUTPUT); 124 assert(output->type == C_OUTPUT);
125 125
126 struct wlr_output *wlr_output = output->sway_output->wlr_output; 126 struct wlr_output *wlr_output = output->sway_output->wlr_output;
127 if (oc && oc->enabled == 0) { 127 if (oc && oc->enabled == 0) {
128 wlr_output_layout_remove(root_container.sway_root->output_layout, 128 wlr_output_layout_remove(root_container.sway_root->output_layout,
129 wlr_output); 129 wlr_output);
130 destroy_output(output); 130 sway_container_output_destroy(output);
131 return; 131 return;
132 } 132 }
133 133
diff --git a/sway/criteria.c b/sway/criteria.c
index b8b581ed..70f8e305 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -272,7 +272,7 @@ static int regex_cmp(const char *item, const pcre *regex) {
272} 272}
273 273
274// test a single view if it matches list of criteria tokens (all of them). 274// test a single view if it matches list of criteria tokens (all of them).
275static bool criteria_test(swayc_t *cont, list_t *tokens) { 275static bool criteria_test(struct sway_container *cont, list_t *tokens) {
276 if (cont->type != C_VIEW) { 276 if (cont->type != C_VIEW) {
277 return false; 277 return false;
278 } 278 }
@@ -398,7 +398,7 @@ void free_criteria(struct criteria *crit) {
398 free(crit); 398 free(crit);
399} 399}
400 400
401bool criteria_any(swayc_t *cont, list_t *criteria) { 401bool criteria_any(struct sway_container *cont, list_t *criteria) {
402 for (int i = 0; i < criteria->length; i++) { 402 for (int i = 0; i < criteria->length; i++) {
403 struct criteria *bc = criteria->items[i]; 403 struct criteria *bc = criteria->items[i];
404 if (criteria_test(cont, bc->tokens)) { 404 if (criteria_test(cont, bc->tokens)) {
@@ -408,7 +408,7 @@ bool criteria_any(swayc_t *cont, list_t *criteria) {
408 return false; 408 return false;
409} 409}
410 410
411list_t *criteria_for(swayc_t *cont) { 411list_t *criteria_for(struct sway_container *cont) {
412 list_t *criteria = config->criteria, *matches = create_list(); 412 list_t *criteria = config->criteria, *matches = create_list();
413 for (int i = 0; i < criteria->length; i++) { 413 for (int i = 0; i < criteria->length; i++) {
414 struct criteria *bc = criteria->items[i]; 414 struct criteria *bc = criteria->items[i];
@@ -424,7 +424,7 @@ struct list_tokens {
424 list_t *tokens; 424 list_t *tokens;
425}; 425};
426 426
427static void container_match_add(swayc_t *container, 427static void container_match_add(struct sway_container *container,
428 struct list_tokens *list_tokens) { 428 struct list_tokens *list_tokens) {
429 if (criteria_test(container, list_tokens->tokens)) { 429 if (criteria_test(container, list_tokens->tokens)) {
430 list_add(list_tokens->list, container); 430 list_add(list_tokens->list, container);
@@ -435,8 +435,8 @@ list_t *container_for_crit_tokens(list_t *tokens) {
435 struct list_tokens list_tokens = 435 struct list_tokens list_tokens =
436 (struct list_tokens){create_list(), tokens}; 436 (struct list_tokens){create_list(), tokens};
437 437
438 container_map(&root_container, 438 sway_container_for_each(&root_container,
439 (void (*)(swayc_t *, void *))container_match_add, 439 (void (*)(struct sway_container *, void *))container_match_add,
440 &list_tokens); 440 &list_tokens);
441 441
442 // TODO look in the scratchpad 442 // TODO look in the scratchpad
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index debda396..3e7d8509 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -145,7 +145,7 @@ struct render_data {
145 struct timespec *now; 145 struct timespec *now;
146}; 146};
147 147
148static void output_frame_view(swayc_t *view, void *data) { 148static void output_frame_view(struct sway_container *view, void *data) {
149 struct render_data *rdata = data; 149 struct render_data *rdata = data;
150 struct sway_output *output = rdata->output; 150 struct sway_output *output = rdata->output;
151 struct timespec *now = rdata->now; 151 struct timespec *now = rdata->now;
@@ -218,16 +218,16 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
218 &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); 218 &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
219 219
220 struct sway_seat *seat = input_manager_current_seat(input_manager); 220 struct sway_seat *seat = input_manager_current_seat(input_manager);
221 swayc_t *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); 221 struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc);
222 swayc_t *workspace = (focus->type == C_WORKSPACE ? 222 struct sway_container *workspace = (focus->type == C_WORKSPACE ?
223 focus : 223 focus :
224 swayc_parent_by_type(focus, C_WORKSPACE)); 224 sway_container_parent(focus, C_WORKSPACE));
225 225
226 struct render_data rdata = { 226 struct render_data rdata = {
227 .output = soutput, 227 .output = soutput,
228 .now = &now, 228 .now = &now,
229 }; 229 };
230 swayc_descendants_of_type(workspace, C_VIEW, output_frame_view, &rdata); 230 sway_container_descendents(workspace, C_VIEW, output_frame_view, &rdata);
231 231
232 // render unmanaged views on top 232 // render unmanaged views on top
233 struct sway_view *view; 233 struct sway_view *view;
@@ -258,7 +258,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) {
258 struct wlr_output *wlr_output = data; 258 struct wlr_output *wlr_output = data;
259 wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); 259 wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name);
260 260
261 destroy_output(output->swayc); 261 sway_container_output_destroy(output->swayc);
262} 262}
263 263
264static void handle_output_mode(struct wl_listener *listener, void *data) { 264static void handle_output_mode(struct wl_listener *listener, void *data) {
@@ -286,7 +286,7 @@ void handle_new_output(struct wl_listener *listener, void *data) {
286 wlr_output_set_mode(wlr_output, mode); 286 wlr_output_set_mode(wlr_output, mode);
287 } 287 }
288 288
289 output->swayc = new_output(output); 289 output->swayc = sway_container_output_create(output);
290 if (!output->swayc) { 290 if (!output->swayc) {
291 free(output); 291 free(output);
292 return; 292 return;
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index bb97fad4..bf41d7bf 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -74,7 +74,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
74 wl_container_of(listener, sway_surface, destroy); 74 wl_container_of(listener, sway_surface, destroy);
75 wl_list_remove(&sway_surface->commit.link); 75 wl_list_remove(&sway_surface->commit.link);
76 wl_list_remove(&sway_surface->destroy.link); 76 wl_list_remove(&sway_surface->destroy.link);
77 swayc_t *parent = destroy_view(sway_surface->view->swayc); 77 struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc);
78 free(sway_surface->view); 78 free(sway_surface->view);
79 free(sway_surface); 79 free(sway_surface);
80 arrange_windows(parent, -1, -1); 80 arrange_windows(parent, -1, -1);
@@ -132,8 +132,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
132 wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); 132 wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy);
133 133
134 struct sway_seat *seat = input_manager_current_seat(input_manager); 134 struct sway_seat *seat = input_manager_current_seat(input_manager);
135 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 135 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
136 swayc_t *cont = new_view(focus, sway_view); 136 struct sway_container *cont = sway_container_view_create(focus, sway_view);
137 sway_view->swayc = cont; 137 sway_view->swayc = cont;
138 138
139 arrange_windows(cont->parent, -1, -1); 139 arrange_windows(cont->parent, -1, -1);
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 25ffacbb..6b50d470 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -83,7 +83,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
83 wl_container_of(listener, sway_xdg_surface, destroy); 83 wl_container_of(listener, sway_xdg_surface, destroy);
84 wl_list_remove(&sway_xdg_surface->commit.link); 84 wl_list_remove(&sway_xdg_surface->commit.link);
85 wl_list_remove(&sway_xdg_surface->destroy.link); 85 wl_list_remove(&sway_xdg_surface->destroy.link);
86 swayc_t *parent = destroy_view(sway_xdg_surface->view->swayc); 86 struct sway_container *parent = sway_container_view_destroy(sway_xdg_surface->view->swayc);
87 free(sway_xdg_surface->view); 87 free(sway_xdg_surface->view);
88 free(sway_xdg_surface); 88 free(sway_xdg_surface);
89 arrange_windows(parent, -1, -1); 89 arrange_windows(parent, -1, -1);
@@ -136,8 +136,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
136 wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); 136 wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy);
137 137
138 struct sway_seat *seat = input_manager_current_seat(input_manager); 138 struct sway_seat *seat = input_manager_current_seat(input_manager);
139 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 139 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
140 swayc_t *cont = new_view(focus, sway_view); 140 struct sway_container *cont = sway_container_view_create(focus, sway_view);
141 sway_view->swayc = cont; 141 sway_view->swayc = cont;
142 142
143 arrange_windows(cont->parent, -1, -1); 143 arrange_windows(cont->parent, -1, -1);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 7f66f746..96edab51 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -49,11 +49,11 @@ static void set_position(struct sway_view *view, double ox, double oy) {
49 if (!assert_xwayland(view)) { 49 if (!assert_xwayland(view)) {
50 return; 50 return;
51 } 51 }
52 swayc_t *output = swayc_parent_by_type(view->swayc, C_OUTPUT); 52 struct sway_container *output = sway_container_parent(view->swayc, C_OUTPUT);
53 if (!sway_assert(output, "view must be within tree to set position")) { 53 if (!sway_assert(output, "view must be within tree to set position")) {
54 return; 54 return;
55 } 55 }
56 swayc_t *root = swayc_parent_by_type(output, C_ROOT); 56 struct sway_container *root = sway_container_parent(output, C_ROOT);
57 if (!sway_assert(root, "output must be within tree to set position")) { 57 if (!sway_assert(root, "output must be within tree to set position")) {
58 return; 58 return;
59 } 59 }
@@ -114,7 +114,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
114 } 114 }
115 } 115 }
116 116
117 swayc_t *parent = destroy_view(sway_surface->view->swayc); 117 struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc);
118 if (parent) { 118 if (parent) {
119 arrange_windows(parent, -1, -1); 119 arrange_windows(parent, -1, -1);
120 } 120 }
@@ -132,7 +132,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) {
132 } 132 }
133 133
134 // take it out of the tree 134 // take it out of the tree
135 swayc_t *parent = destroy_view(sway_surface->view->swayc); 135 struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc);
136 if (parent) { 136 if (parent) {
137 arrange_windows(parent, -1, -1); 137 arrange_windows(parent, -1, -1);
138 } 138 }
@@ -155,12 +155,12 @@ static void handle_map_notify(struct wl_listener *listener, void *data) {
155 &sway_surface->view->unmanaged_view_link); 155 &sway_surface->view->unmanaged_view_link);
156 } else { 156 } else {
157 struct sway_view *view = sway_surface->view; 157 struct sway_view *view = sway_surface->view;
158 destroy_view(view->swayc); 158 sway_container_view_destroy(view->swayc);
159 159
160 swayc_t *parent = root_container.children->items[0]; 160 struct sway_container *parent = root_container.children->items[0];
161 parent = parent->children->items[0]; // workspace 161 parent = parent->children->items[0]; // workspace
162 162
163 swayc_t *cont = new_view(parent, view); 163 struct sway_container *cont = sway_container_view_create(parent, view);
164 view->swayc = cont; 164 view->swayc = cont;
165 165
166 arrange_windows(cont->parent, -1, -1); 166 arrange_windows(cont->parent, -1, -1);
@@ -238,8 +238,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
238 } 238 }
239 239
240 struct sway_seat *seat = input_manager_current_seat(input_manager); 240 struct sway_seat *seat = input_manager_current_seat(input_manager);
241 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 241 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
242 swayc_t *cont = new_view(focus, sway_view); 242 struct sway_container *cont = sway_container_view_create(focus, sway_view);
243 sway_view->swayc = cont; 243 sway_view->swayc = cont;
244 244
245 arrange_windows(cont->parent, -1, -1); 245 arrange_windows(cont->parent, -1, -1);
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index c0e14265..a0e4b9be 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -49,8 +49,8 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
49 } 49 }
50 } 50 }
51 51
52 swayc_t *swayc = 52 struct sway_container *swayc =
53 swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); 53 sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
54 if (swayc) { 54 if (swayc) {
55 wlr_seat_pointer_notify_enter(seat, surface, sx, sy); 55 wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
56 wlr_seat_pointer_notify_motion(seat, time, sx, sy); 56 wlr_seat_pointer_notify_motion(seat, time, sx, sy);
@@ -87,8 +87,8 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
87 if (event->button == BTN_LEFT) { 87 if (event->button == BTN_LEFT) {
88 struct wlr_surface *surface = NULL; 88 struct wlr_surface *surface = NULL;
89 double sx, sy; 89 double sx, sy;
90 swayc_t *swayc = 90 struct sway_container *swayc =
91 swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); 91 sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
92 92
93 sway_seat_set_focus(cursor->seat, swayc); 93 sway_seat_set_focus(cursor->seat, swayc);
94 } 94 }
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 56b39766..f03a03b4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -37,7 +37,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
37 struct sway_seat_container *seat_con = 37 struct sway_seat_container *seat_con =
38 wl_container_of(listener, seat_con, destroy); 38 wl_container_of(listener, seat_con, destroy);
39 struct sway_seat *seat = seat_con->seat; 39 struct sway_seat *seat = seat_con->seat;
40 swayc_t *con = seat_con->container; 40 struct sway_container *con = seat_con->container;
41 41
42 bool is_focus = (sway_seat_get_focus(seat) == con); 42 bool is_focus = (sway_seat_get_focus(seat) == con);
43 43
@@ -46,7 +46,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
46 if (is_focus) { 46 if (is_focus) {
47 // pick next focus 47 // pick next focus
48 sway_seat_set_focus(seat, NULL); 48 sway_seat_set_focus(seat, NULL);
49 swayc_t *next = sway_seat_get_focus_inactive(seat, con->parent); 49 struct sway_container *next = sway_seat_get_focus_inactive(seat, con->parent);
50 if (next == NULL) { 50 if (next == NULL) {
51 next = con->parent; 51 next = con->parent;
52 } 52 }
@@ -59,7 +59,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
59} 59}
60 60
61static struct sway_seat_container *seat_container_from_container( 61static struct sway_seat_container *seat_container_from_container(
62 struct sway_seat *seat, swayc_t *con) { 62 struct sway_seat *seat, struct sway_container *con) {
63 if (con->type < C_WORKSPACE) { 63 if (con->type < C_WORKSPACE) {
64 // these don't get seat containers ever 64 // these don't get seat containers ever
65 return NULL; 65 return NULL;
@@ -89,11 +89,11 @@ static struct sway_seat_container *seat_container_from_container(
89 89
90static void handle_new_container(struct wl_listener *listener, void *data) { 90static void handle_new_container(struct wl_listener *listener, void *data) {
91 struct sway_seat *seat = wl_container_of(listener, seat, new_container); 91 struct sway_seat *seat = wl_container_of(listener, seat, new_container);
92 swayc_t *con = data; 92 struct sway_container *con = data;
93 seat_container_from_container(seat, con); 93 seat_container_from_container(seat, con);
94} 94}
95 95
96static void collect_focus_iter(swayc_t *con, void *data) { 96static void collect_focus_iter(struct sway_container *con, void *data) {
97 struct sway_seat *seat = data; 97 struct sway_seat *seat = data;
98 if (con->type > C_WORKSPACE) { 98 if (con->type > C_WORKSPACE) {
99 return; 99 return;
@@ -130,7 +130,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
130 // init the focus stack 130 // init the focus stack
131 wl_list_init(&seat->focus_stack); 131 wl_list_init(&seat->focus_stack);
132 132
133 container_for_each_bfs(&root_container, collect_focus_iter, seat); 133 sway_container_for_each_bfs(&root_container, collect_focus_iter, seat);
134 134
135 wl_signal_add(&root_container.sway_root->events.new_container, 135 wl_signal_add(&root_container.sway_root->events.new_container,
136 &seat->new_container); 136 &seat->new_container);
@@ -166,7 +166,7 @@ static void seat_configure_keyboard(struct sway_seat *seat,
166 sway_keyboard_configure(seat_device->keyboard); 166 sway_keyboard_configure(seat_device->keyboard);
167 wlr_seat_set_keyboard(seat->wlr_seat, 167 wlr_seat_set_keyboard(seat->wlr_seat,
168 seat_device->input_device->wlr_device); 168 seat_device->input_device->wlr_device);
169 swayc_t *focus = sway_seat_get_focus(seat); 169 struct sway_container *focus = sway_seat_get_focus(seat);
170 if (focus && focus->type == C_VIEW) { 170 if (focus && focus->type == C_VIEW) {
171 // force notify reenter to pick up the new configuration 171 // force notify reenter to pick up the new configuration
172 wlr_seat_keyboard_clear_focus(seat->wlr_seat); 172 wlr_seat_keyboard_clear_focus(seat->wlr_seat);
@@ -270,7 +270,7 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
270 } 270 }
271 271
272 for (int i = 0; i < root_container.children->length; ++i) { 272 for (int i = 0; i < root_container.children->length; ++i) {
273 swayc_t *output_container = root_container.children->items[i]; 273 struct sway_container *output_container = root_container.children->items[i];
274 struct wlr_output *output = 274 struct wlr_output *output =
275 output_container->sway_output->wlr_output; 275 output_container->sway_output->wlr_output;
276 bool result = 276 bool result =
@@ -289,8 +289,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
289 seat->cursor->cursor->y); 289 seat->cursor->cursor->y);
290} 290}
291 291
292void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { 292void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container) {
293 swayc_t *last_focus = sway_seat_get_focus(seat); 293 struct sway_container *last_focus = sway_seat_get_focus(seat);
294 294
295 if (container && last_focus == container) { 295 if (container && last_focus == container) {
296 return; 296 return;
@@ -330,9 +330,9 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
330 seat->has_focus = (container != NULL); 330 seat->has_focus = (container != NULL);
331} 331}
332 332
333swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container) { 333struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) {
334 struct sway_seat_container *current = NULL; 334 struct sway_seat_container *current = NULL;
335 swayc_t *parent = NULL; 335 struct sway_container *parent = NULL;
336 wl_list_for_each(current, &seat->focus_stack, link) { 336 wl_list_for_each(current, &seat->focus_stack, link) {
337 parent = current->container->parent; 337 parent = current->container->parent;
338 338
@@ -351,21 +351,21 @@ swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container
351 return NULL; 351 return NULL;
352} 352}
353 353
354swayc_t *sway_seat_get_focus(struct sway_seat *seat) { 354struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
355 if (!seat->has_focus) { 355 if (!seat->has_focus) {
356 return NULL; 356 return NULL;
357 } 357 }
358 return sway_seat_get_focus_inactive(seat, &root_container); 358 return sway_seat_get_focus_inactive(seat, &root_container);
359} 359}
360 360
361swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, 361struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat,
362 enum swayc_types type) { 362 enum sway_container_type type) {
363 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 363 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
364 if (focus->type == type) { 364 if (focus->type == type) {
365 return focus; 365 return focus;
366 } 366 }
367 367
368 return swayc_parent_by_type(focus, type); 368 return sway_container_parent(focus, type);
369} 369}
370 370
371void sway_seat_set_config(struct sway_seat *seat, 371void sway_seat_set_config(struct sway_seat *seat,
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index ebd5e43a..7caa2457 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -25,7 +25,7 @@ json_object *ipc_json_get_version() {
25 return version; 25 return version;
26} 26}
27 27
28static json_object *ipc_json_create_rect(swayc_t *c) { 28static json_object *ipc_json_create_rect(struct sway_container *c) {
29 json_object *rect = json_object_new_object(); 29 json_object *rect = json_object_new_object();
30 30
31 json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x)); 31 json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x));
@@ -36,7 +36,7 @@ static json_object *ipc_json_create_rect(swayc_t *c) {
36 return rect; 36 return rect;
37} 37}
38 38
39static void ipc_json_describe_root(swayc_t *root, json_object *object) { 39static void ipc_json_describe_root(struct sway_container *root, json_object *object) {
40 json_object_object_add(object, "type", json_object_new_string("root")); 40 json_object_object_add(object, "type", json_object_new_string("root"));
41 json_object_object_add(object, "layout", json_object_new_string("splith")); 41 json_object_object_add(object, "layout", json_object_new_string("splith"));
42} 42}
@@ -63,7 +63,7 @@ static const char *ipc_json_get_output_transform(enum wl_output_transform transf
63 return NULL; 63 return NULL;
64} 64}
65 65
66static void ipc_json_describe_output(swayc_t *container, json_object *object) { 66static void ipc_json_describe_output(struct sway_container *container, json_object *object) {
67 struct wlr_output *wlr_output = container->sway_output->wlr_output; 67 struct wlr_output *wlr_output = container->sway_output->wlr_output;
68 json_object_object_add(object, "type", json_object_new_string("output")); 68 json_object_object_add(object, "type", json_object_new_string("output"));
69 json_object_object_add(object, "active", json_object_new_boolean(true)); 69 json_object_object_add(object, "active", json_object_new_boolean(true));
@@ -94,7 +94,7 @@ static void ipc_json_describe_output(swayc_t *container, json_object *object) {
94 json_object_object_add(object, "modes", modes_array); 94 json_object_object_add(object, "modes", modes_array);
95} 95}
96 96
97static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { 97static void ipc_json_describe_workspace(struct sway_container *workspace, json_object *object) {
98 int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; 98 int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1;
99 99
100 json_object_object_add(object, "num", json_object_new_int(num)); 100 json_object_object_add(object, "num", json_object_new_int(num));
@@ -102,11 +102,11 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object)
102 json_object_object_add(object, "type", json_object_new_string("workspace")); 102 json_object_object_add(object, "type", json_object_new_string("workspace"));
103} 103}
104 104
105static void ipc_json_describe_view(swayc_t *c, json_object *object) { 105static void ipc_json_describe_view(struct sway_container *c, json_object *object) {
106 json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); 106 json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);
107} 107}
108 108
109json_object *ipc_json_describe_container(swayc_t *c) { 109json_object *ipc_json_describe_container(struct sway_container *c) {
110 if (!(sway_assert(c, "Container must not be null."))) { 110 if (!(sway_assert(c, "Container must not be null."))) {
111 return NULL; 111 return NULL;
112 } 112 }
@@ -147,7 +147,7 @@ json_object *ipc_json_describe_container(swayc_t *c) {
147 return object; 147 return object;
148} 148}
149 149
150json_object *ipc_json_describe_container_recursive(swayc_t *c) { 150json_object *ipc_json_describe_container_recursive(struct sway_container *c) {
151 json_object *object = ipc_json_describe_container(c); 151 json_object *object = ipc_json_describe_container(c);
152 int i; 152 int i;
153 153
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 156de380..50d0bcf3 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -279,7 +279,7 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event)
279 } 279 }
280} 280}
281 281
282void ipc_event_window(swayc_t *window, const char *change) { 282void ipc_event_window(struct sway_container *window, const char *change) {
283 wlr_log(L_DEBUG, "Sending window::%s event", change); 283 wlr_log(L_DEBUG, "Sending window::%s event", change);
284 json_object *obj = json_object_new_object(); 284 json_object *obj = json_object_new_object();
285 json_object_object_add(obj, "change", json_object_new_string(change)); 285 json_object_object_add(obj, "change", json_object_new_string(change));
@@ -400,7 +400,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
400 { 400 {
401 json_object *outputs = json_object_new_array(); 401 json_object *outputs = json_object_new_array();
402 for (int i = 0; i < root_container.children->length; ++i) { 402 for (int i = 0; i < root_container.children->length; ++i) {
403 swayc_t *container = root_container.children->items[i]; 403 struct sway_container *container = root_container.children->items[i];
404 if (container->type == C_OUTPUT) { 404 if (container->type == C_OUTPUT) {
405 json_object_array_add(outputs, 405 json_object_array_add(outputs,
406 ipc_json_describe_container(container)); 406 ipc_json_describe_container(container));
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 805d5644..d31966b3 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -33,48 +33,15 @@ static list_t *get_bfs_queue() {
33 return bfs_queue; 33 return bfs_queue;
34} 34}
35 35
36static void notify_new_container(swayc_t *container) { 36static void notify_new_container(struct sway_container *container) {
37 wl_signal_emit(&root_container.sway_root->events.new_container, container); 37 wl_signal_emit(&root_container.sway_root->events.new_container, container);
38 ipc_event_window(container, "new"); 38 ipc_event_window(container, "new");
39} 39}
40 40
41swayc_t *swayc_by_test(swayc_t *container, 41static struct sway_container *new_swayc(enum sway_container_type type) {
42 bool (*test)(swayc_t *view, void *data), void *data) {
43 if (!container->children) {
44 return NULL;
45 }
46 // TODO: floating windows
47 for (int i = 0; i < container->children->length; ++i) {
48 swayc_t *child = container->children->items[i];
49 if (test(child, data)) {
50 return child;
51 } else {
52 swayc_t *res = swayc_by_test(child, test, data);
53 if (res) {
54 return res;
55 }
56 }
57 }
58 return NULL;
59}
60
61void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
62 void (*func)(swayc_t *item, void *data), void *data) {
63 for (int i = 0; i < root->children->length; ++i) {
64 swayc_t *item = root->children->items[i];
65 if (item->type == type) {
66 func(item, data);
67 }
68 if (item->children && item->children->length) {
69 swayc_descendants_of_type(item, type, func, data);
70 }
71 }
72}
73
74static swayc_t *new_swayc(enum swayc_types type) {
75 // next id starts at 1 because 0 is assigned to root_container in layout.c 42 // next id starts at 1 because 0 is assigned to root_container in layout.c
76 static size_t next_id = 1; 43 static size_t next_id = 1;
77 swayc_t *c = calloc(1, sizeof(swayc_t)); 44 struct sway_container *c = calloc(1, sizeof(struct sway_container));
78 if (!c) { 45 if (!c) {
79 return NULL; 46 return NULL;
80 } 47 }
@@ -91,7 +58,7 @@ static swayc_t *new_swayc(enum swayc_types type) {
91 return c; 58 return c;
92} 59}
93 60
94static void free_swayc(swayc_t *cont) { 61static void free_swayc(struct sway_container *cont) {
95 if (!sway_assert(cont, "free_swayc passed NULL")) { 62 if (!sway_assert(cont, "free_swayc passed NULL")) {
96 return; 63 return;
97 } 64 }
@@ -119,7 +86,7 @@ static void free_swayc(swayc_t *cont) {
119 free(cont); 86 free(cont);
120} 87}
121 88
122swayc_t *new_output(struct sway_output *sway_output) { 89struct sway_container *sway_container_output_create(struct sway_output *sway_output) {
123 struct wlr_box size; 90 struct wlr_box size;
124 wlr_output_effective_resolution(sway_output->wlr_output, &size.width, 91 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
125 &size.height); 92 &size.height);
@@ -154,7 +121,7 @@ swayc_t *new_output(struct sway_output *sway_output) {
154 return NULL; 121 return NULL;
155 } 122 }
156 123
157 swayc_t *output = new_swayc(C_OUTPUT); 124 struct sway_container *output = new_swayc(C_OUTPUT);
158 output->sway_output = sway_output; 125 output->sway_output = sway_output;
159 output->name = strdup(name); 126 output->name = strdup(name);
160 if (output->name == NULL) { 127 if (output->name == NULL) {
@@ -169,7 +136,7 @@ swayc_t *new_output(struct sway_output *sway_output) {
169 // Create workspace 136 // Create workspace
170 char *ws_name = workspace_next_name(output->name); 137 char *ws_name = workspace_next_name(output->name);
171 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); 138 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name);
172 swayc_t *ws = new_workspace(output, ws_name); 139 struct sway_container *ws = sway_container_workspace_create(output, ws_name);
173 // Set each seat's focus if not already set 140 // Set each seat's focus if not already set
174 struct sway_seat *seat = NULL; 141 struct sway_seat *seat = NULL;
175 wl_list_for_each(seat, &input_manager->seats, link) { 142 wl_list_for_each(seat, &input_manager->seats, link) {
@@ -183,12 +150,12 @@ swayc_t *new_output(struct sway_output *sway_output) {
183 return output; 150 return output;
184} 151}
185 152
186swayc_t *new_workspace(swayc_t *output, const char *name) { 153struct sway_container *sway_container_workspace_create(struct sway_container *output, const char *name) {
187 if (!sway_assert(output, "new_workspace called with null output")) { 154 if (!sway_assert(output, "sway_container_workspace_create called with null output")) {
188 return NULL; 155 return NULL;
189 } 156 }
190 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 157 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
191 swayc_t *workspace = new_swayc(C_WORKSPACE); 158 struct sway_container *workspace = new_swayc(C_WORKSPACE);
192 159
193 workspace->x = output->x; 160 workspace->x = output->x;
194 workspace->y = output->y; 161 workspace->y = output->y;
@@ -205,12 +172,12 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
205 return workspace; 172 return workspace;
206} 173}
207 174
208swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { 175struct sway_container *sway_container_view_create(struct sway_container *sibling, struct sway_view *sway_view) {
209 if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { 176 if (!sway_assert(sibling, "sway_container_view_create called with NULL sibling/parent")) {
210 return NULL; 177 return NULL;
211 } 178 }
212 const char *title = view_get_title(sway_view); 179 const char *title = view_get_title(sway_view);
213 swayc_t *swayc = new_swayc(C_VIEW); 180 struct sway_container *swayc = new_swayc(C_VIEW);
214 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", 181 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s",
215 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); 182 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name);
216 // Setup values 183 // Setup values
@@ -230,8 +197,8 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
230 return swayc; 197 return swayc;
231} 198}
232 199
233swayc_t *destroy_output(swayc_t *output) { 200struct sway_container *sway_container_output_destroy(struct sway_container *output) {
234 if (!sway_assert(output, "null output passed to destroy_output")) { 201 if (!sway_assert(output, "null output passed to sway_container_output_destroy")) {
235 return NULL; 202 return NULL;
236 } 203 }
237 204
@@ -243,7 +210,7 @@ swayc_t *destroy_output(swayc_t *output) {
243 int p = root_container.children->items[0] == output; 210 int p = root_container.children->items[0] == output;
244 // Move workspace from this output to another output 211 // Move workspace from this output to another output
245 while (output->children->length) { 212 while (output->children->length) {
246 swayc_t *child = output->children->items[0]; 213 struct sway_container *child = output->children->items[0];
247 remove_child(child); 214 remove_child(child);
248 add_child(root_container.children->items[p], child); 215 add_child(root_container.children->items[p], child);
249 } 216 }
@@ -262,12 +229,12 @@ swayc_t *destroy_output(swayc_t *output) {
262 return &root_container; 229 return &root_container;
263} 230}
264 231
265swayc_t *destroy_view(swayc_t *view) { 232struct sway_container *sway_container_view_destroy(struct sway_container *view) {
266 if (!view) { 233 if (!view) {
267 return NULL; 234 return NULL;
268 } 235 }
269 wlr_log(L_DEBUG, "Destroying view '%s'", view->name); 236 wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
270 swayc_t *parent = view->parent; 237 struct sway_container *parent = view->parent;
271 free_swayc(view); 238 free_swayc(view);
272 239
273 // TODO WLR: Destroy empty containers 240 // TODO WLR: Destroy empty containers
@@ -279,7 +246,52 @@ swayc_t *destroy_view(swayc_t *view) {
279 return parent; 246 return parent;
280} 247}
281 248
282swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { 249struct sway_container *swayc_change_layout(struct sway_container *container, enum sway_container_layout layout) {
250 if (container->type == C_WORKSPACE) {
251 container->workspace_layout = layout;
252 if (layout == L_HORIZ || layout == L_VERT) {
253 container->layout = layout;
254 }
255 } else {
256 container->layout = layout;
257 }
258 return container;
259}
260
261void sway_container_descendents(struct sway_container *root, enum sway_container_type type,
262 void (*func)(struct sway_container *item, void *data), void *data) {
263 for (int i = 0; i < root->children->length; ++i) {
264 struct sway_container *item = root->children->items[i];
265 if (item->type == type) {
266 func(item, data);
267 }
268 if (item->children && item->children->length) {
269 sway_container_descendents(item, type, func, data);
270 }
271 }
272}
273
274struct sway_container *sway_container_find(struct sway_container *container,
275 bool (*test)(struct sway_container *view, void *data), void *data) {
276 if (!container->children) {
277 return NULL;
278 }
279 // TODO: floating windows
280 for (int i = 0; i < container->children->length; ++i) {
281 struct sway_container *child = container->children->items[i];
282 if (test(child, data)) {
283 return child;
284 } else {
285 struct sway_container *res = sway_container_find(child, test, data);
286 if (res) {
287 return res;
288 }
289 }
290 }
291 return NULL;
292}
293
294struct sway_container *sway_container_parent(struct sway_container *container, enum sway_container_type type) {
283 if (!sway_assert(container, "container is NULL")) { 295 if (!sway_assert(container, "container is NULL")) {
284 return NULL; 296 return NULL;
285 } 297 }
@@ -292,7 +304,29 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
292 return container; 304 return container;
293} 305}
294 306
295swayc_t *swayc_at(swayc_t *parent, double lx, double ly, 307void sway_container_for_each(struct sway_container *container, void (*f)(struct sway_container *view, void *data), void *data) {
308 if (container) {
309 int i;
310 if (container->children) {
311 for (i = 0; i < container->children->length; ++i) {
312 struct sway_container *child = container->children->items[i];
313 sway_container_for_each(child, f, data);
314 }
315 }
316 // TODO
317 /*
318 if (container->floating) {
319 for (i = 0; i < container->floating->length; ++i) {
320 struct sway_container *child = container->floating->items[i];
321 container_map(child, f, data);
322 }
323 }
324 */
325 f(container, data);
326 }
327}
328
329struct sway_container *sway_container_at(struct sway_container *parent, double lx, double ly,
296 struct wlr_surface **surface, double *sx, double *sy) { 330 struct wlr_surface **surface, double *sx, double *sy) {
297 list_t *queue = get_bfs_queue(); 331 list_t *queue = get_bfs_queue();
298 if (!queue) { 332 if (!queue) {
@@ -301,13 +335,13 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
301 335
302 list_add(queue, parent); 336 list_add(queue, parent);
303 337
304 swayc_t *swayc = NULL; 338 struct sway_container *swayc = NULL;
305 while (queue->length) { 339 while (queue->length) {
306 swayc = queue->items[0]; 340 swayc = queue->items[0];
307 list_del(queue, 0); 341 list_del(queue, 0);
308 if (swayc->type == C_VIEW) { 342 if (swayc->type == C_VIEW) {
309 struct sway_view *sview = swayc->sway_view; 343 struct sway_view *sview = swayc->sway_view;
310 swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); 344 struct sway_container *soutput = sway_container_parent(swayc, C_OUTPUT);
311 struct wlr_box *output_box = 345 struct wlr_box *output_box =
312 wlr_output_layout_get_box( 346 wlr_output_layout_get_box(
313 root_container.sway_root->output_layout, 347 root_container.sway_root->output_layout,
@@ -377,29 +411,7 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
377 return NULL; 411 return NULL;
378} 412}
379 413
380void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 414void sway_container_for_each_bfs(struct sway_container *con, void (*f)(struct sway_container *con, void *data),
381 if (container) {
382 int i;
383 if (container->children) {
384 for (i = 0; i < container->children->length; ++i) {
385 swayc_t *child = container->children->items[i];
386 container_map(child, f, data);
387 }
388 }
389 // TODO
390 /*
391 if (container->floating) {
392 for (i = 0; i < container->floating->length; ++i) {
393 swayc_t *child = container->floating->items[i];
394 container_map(child, f, data);
395 }
396 }
397 */
398 f(container, data);
399 }
400}
401
402void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
403 void *data) { 415 void *data) {
404 list_t *queue = get_bfs_queue(); 416 list_t *queue = get_bfs_queue();
405 if (!queue) { 417 if (!queue) {
@@ -413,7 +425,7 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
413 425
414 list_add(queue, con); 426 list_add(queue, con);
415 427
416 swayc_t *current = NULL; 428 struct sway_container *current = NULL;
417 while (queue->length) { 429 while (queue->length) {
418 current = queue->items[0]; 430 current = queue->items[0];
419 list_del(queue, 0); 431 list_del(queue, 0);
@@ -422,15 +434,3 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
422 list_cat(queue, current->children); 434 list_cat(queue, current->children);
423 } 435 }
424} 436}
425
426swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
427 if (container->type == C_WORKSPACE) {
428 container->workspace_layout = layout;
429 if (layout == L_HORIZ || layout == L_VERT) {
430 container->layout = layout;
431 }
432 } else {
433 container->layout = layout;
434 }
435 return container;
436}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 5a15f3a2..068fb39c 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -14,7 +14,7 @@
14#include "list.h" 14#include "list.h"
15#include "log.h" 15#include "log.h"
16 16
17swayc_t root_container; 17struct sway_container root_container;
18 18
19static void output_layout_change_notify(struct wl_listener *listener, void *data) { 19static void output_layout_change_notify(struct wl_listener *listener, void *data) {
20 struct wlr_box *layout_box = wlr_output_layout_get_box( 20 struct wlr_box *layout_box = wlr_output_layout_get_box(
@@ -23,7 +23,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data
23 root_container.height = layout_box->height; 23 root_container.height = layout_box->height;
24 24
25 for (int i = 0 ; i < root_container.children->length; ++i) { 25 for (int i = 0 ; i < root_container.children->length; ++i) {
26 swayc_t *output_container = root_container.children->items[i]; 26 struct sway_container *output_container = root_container.children->items[i];
27 if (output_container->type != C_OUTPUT) { 27 if (output_container->type != C_OUTPUT) {
28 continue; 28 continue;
29 } 29 }
@@ -62,9 +62,9 @@ void init_layout(void) {
62 &root_container.sway_root->output_layout_change); 62 &root_container.sway_root->output_layout_change);
63} 63}
64 64
65static int index_child(const swayc_t *child) { 65static int index_child(const struct sway_container *child) {
66 // TODO handle floating 66 // TODO handle floating
67 swayc_t *parent = child->parent; 67 struct sway_container *parent = child->parent;
68 int i, len; 68 int i, len;
69 len = parent->children->length; 69 len = parent->children->length;
70 for (i = 0; i < len; ++i) { 70 for (i = 0; i < len; ++i) {
@@ -79,16 +79,16 @@ static int index_child(const swayc_t *child) {
79 return i; 79 return i;
80} 80}
81 81
82swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { 82struct sway_container *add_sibling(struct sway_container *fixed, struct sway_container *active) {
83 // TODO handle floating 83 // TODO handle floating
84 swayc_t *parent = fixed->parent; 84 struct sway_container *parent = fixed->parent;
85 int i = index_child(fixed); 85 int i = index_child(fixed);
86 list_insert(parent->children, i + 1, active); 86 list_insert(parent->children, i + 1, active);
87 active->parent = parent; 87 active->parent = parent;
88 return active->parent; 88 return active->parent;
89} 89}
90 90
91void add_child(swayc_t *parent, swayc_t *child) { 91void add_child(struct sway_container *parent, struct sway_container *child) {
92 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", 92 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
93 child, child->type, child->width, child->height, 93 child, child->type, child->width, child->height,
94 parent, parent->type, parent->width, parent->height); 94 parent, parent->type, parent->width, parent->height);
@@ -102,9 +102,9 @@ void add_child(swayc_t *parent, swayc_t *child) {
102 */ 102 */
103} 103}
104 104
105swayc_t *remove_child(swayc_t *child) { 105struct sway_container *remove_child(struct sway_container *child) {
106 int i; 106 int i;
107 swayc_t *parent = child->parent; 107 struct sway_container *parent = child->parent;
108 for (i = 0; i < parent->children->length; ++i) { 108 for (i = 0; i < parent->children->length; ++i) {
109 if (parent->children->items[i] == child) { 109 if (parent->children->items[i] == child) {
110 list_del(parent->children, i); 110 list_del(parent->children, i);
@@ -115,7 +115,7 @@ swayc_t *remove_child(swayc_t *child) {
115 return parent; 115 return parent;
116} 116}
117 117
118enum swayc_layouts default_layout(swayc_t *output) { 118enum sway_container_layout default_layout(struct sway_container *output) {
119 /* TODO WLR 119 /* TODO WLR
120 if (config->default_layout != L_NONE) { 120 if (config->default_layout != L_NONE) {
121 //return config->default_layout; 121 //return config->default_layout;
@@ -129,8 +129,8 @@ enum swayc_layouts default_layout(swayc_t *output) {
129} 129}
130 130
131static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { 131static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
132 swayc_t *a = *(void **)_a; 132 struct sway_container *a = *(void **)_a;
133 swayc_t *b = *(void **)_b; 133 struct sway_container *b = *(void **)_b;
134 int retval = 0; 134 int retval = 0;
135 135
136 if (isdigit(a->name[0]) && isdigit(b->name[0])) { 136 if (isdigit(a->name[0]) && isdigit(b->name[0])) {
@@ -146,21 +146,21 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
146 return retval; 146 return retval;
147} 147}
148 148
149void sort_workspaces(swayc_t *output) { 149void sort_workspaces(struct sway_container *output) {
150 list_stable_sort(output->children, sort_workspace_cmp_qsort); 150 list_stable_sort(output->children, sort_workspace_cmp_qsort);
151} 151}
152 152
153static void apply_horiz_layout(swayc_t *container, const double x, 153static void apply_horiz_layout(struct sway_container *container, const double x,
154 const double y, const double width, 154 const double y, const double width,
155 const double height, const int start, 155 const double height, const int start,
156 const int end); 156 const int end);
157 157
158static void apply_vert_layout(swayc_t *container, const double x, 158static void apply_vert_layout(struct sway_container *container, const double x,
159 const double y, const double width, 159 const double y, const double width,
160 const double height, const int start, 160 const double height, const int start,
161 const int end); 161 const int end);
162 162
163void arrange_windows(swayc_t *container, double width, double height) { 163void arrange_windows(struct sway_container *container, double width, double height) {
164 int i; 164 int i;
165 if (width == -1 || height == -1) { 165 if (width == -1 || height == -1) {
166 width = container->width; 166 width = container->width;
@@ -181,7 +181,7 @@ void arrange_windows(swayc_t *container, double width, double height) {
181 case C_ROOT: 181 case C_ROOT:
182 // TODO: wlr_output_layout probably 182 // TODO: wlr_output_layout probably
183 for (i = 0; i < container->children->length; ++i) { 183 for (i = 0; i < container->children->length; ++i) {
184 swayc_t *output = container->children->items[i]; 184 struct sway_container *output = container->children->items[i];
185 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", 185 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
186 output->name, output->x, output->y); 186 output->name, output->x, output->y);
187 arrange_windows(output, -1, -1); 187 arrange_windows(output, -1, -1);
@@ -197,13 +197,13 @@ void arrange_windows(swayc_t *container, double width, double height) {
197 } 197 }
198 // arrange all workspaces: 198 // arrange all workspaces:
199 for (i = 0; i < container->children->length; ++i) { 199 for (i = 0; i < container->children->length; ++i) {
200 swayc_t *child = container->children->items[i]; 200 struct sway_container *child = container->children->items[i];
201 arrange_windows(child, -1, -1); 201 arrange_windows(child, -1, -1);
202 } 202 }
203 return; 203 return;
204 case C_WORKSPACE: 204 case C_WORKSPACE:
205 { 205 {
206 swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); 206 struct sway_container *output = sway_container_parent(container, C_OUTPUT);
207 struct wlr_box *area = &output->sway_output->usable_area; 207 struct wlr_box *area = &output->sway_output->usable_area;
208 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 208 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
209 area->width, area->height, area->x, area->y); 209 area->width, area->height, area->x, area->y);
@@ -252,14 +252,14 @@ void arrange_windows(swayc_t *container, double width, double height) {
252 } 252 }
253} 253}
254 254
255static void apply_horiz_layout(swayc_t *container, 255static void apply_horiz_layout(struct sway_container *container,
256 const double x, const double y, 256 const double x, const double y,
257 const double width, const double height, 257 const double width, const double height,
258 const int start, const int end) { 258 const int start, const int end) {
259 double scale = 0; 259 double scale = 0;
260 // Calculate total width 260 // Calculate total width
261 for (int i = start; i < end; ++i) { 261 for (int i = start; i < end; ++i) {
262 double *old_width = &((swayc_t *)container->children->items[i])->width; 262 double *old_width = &((struct sway_container *)container->children->items[i])->width;
263 if (*old_width <= 0) { 263 if (*old_width <= 0) {
264 if (end - start > 1) { 264 if (end - start > 1) {
265 *old_width = width / (end - start - 1); 265 *old_width = width / (end - start - 1);
@@ -276,7 +276,7 @@ static void apply_horiz_layout(swayc_t *container,
276 if (scale > 0.1) { 276 if (scale > 0.1) {
277 wlr_log(L_DEBUG, "Arranging %p horizontally", container); 277 wlr_log(L_DEBUG, "Arranging %p horizontally", container);
278 for (int i = start; i < end; ++i) { 278 for (int i = start; i < end; ++i) {
279 swayc_t *child = container->children->items[i]; 279 struct sway_container *child = container->children->items[i];
280 wlr_log(L_DEBUG, 280 wlr_log(L_DEBUG,
281 "Calculating arrangement for %p:%d (will scale %f by %f)", 281 "Calculating arrangement for %p:%d (will scale %f by %f)",
282 child, child->type, width, scale); 282 child, child->type, width, scale);
@@ -301,7 +301,7 @@ static void apply_horiz_layout(swayc_t *container,
301 } 301 }
302} 302}
303 303
304void apply_vert_layout(swayc_t *container, 304void apply_vert_layout(struct sway_container *container,
305 const double x, const double y, 305 const double x, const double y,
306 const double width, const double height, const int start, 306 const double width, const double height, const int start,
307 const int end) { 307 const int end) {
@@ -309,7 +309,7 @@ void apply_vert_layout(swayc_t *container,
309 double scale = 0; 309 double scale = 0;
310 // Calculate total height 310 // Calculate total height
311 for (i = start; i < end; ++i) { 311 for (i = start; i < end; ++i) {
312 double *old_height = &((swayc_t *)container->children->items[i])->height; 312 double *old_height = &((struct sway_container *)container->children->items[i])->height;
313 if (*old_height <= 0) { 313 if (*old_height <= 0) {
314 if (end - start > 1) { 314 if (end - start > 1) {
315 *old_height = height / (end - start - 1); 315 *old_height = height / (end - start - 1);
@@ -326,7 +326,7 @@ void apply_vert_layout(swayc_t *container,
326 if (scale > 0.1) { 326 if (scale > 0.1) {
327 wlr_log(L_DEBUG, "Arranging %p vertically", container); 327 wlr_log(L_DEBUG, "Arranging %p vertically", container);
328 for (i = start; i < end; ++i) { 328 for (i = start; i < end; ++i) {
329 swayc_t *child = container->children->items[i]; 329 struct sway_container *child = container->children->items[i];
330 wlr_log(L_DEBUG, 330 wlr_log(L_DEBUG,
331 "Calculating arrangement for %p:%d (will scale %f by %f)", 331 "Calculating arrangement for %p:%d (will scale %f by %f)",
332 child, child->type, height, scale); 332 child, child->type, height, scale);
@@ -354,15 +354,15 @@ void apply_vert_layout(swayc_t *container,
354/** 354/**
355 * Get swayc in the direction of newly entered output. 355 * Get swayc in the direction of newly entered output.
356 */ 356 */
357static swayc_t *get_swayc_in_output_direction(swayc_t *output, 357static struct sway_container *get_swayc_in_output_direction(struct sway_container *output,
358 enum movement_direction dir, struct sway_seat *seat) { 358 enum movement_direction dir, struct sway_seat *seat) {
359 if (!output) { 359 if (!output) {
360 return NULL; 360 return NULL;
361 } 361 }
362 362
363 swayc_t *ws = sway_seat_get_focus_inactive(seat, output); 363 struct sway_container *ws = sway_seat_get_focus_inactive(seat, output);
364 if (ws->type != C_WORKSPACE) { 364 if (ws->type != C_WORKSPACE) {
365 ws = swayc_parent_by_type(ws, C_WORKSPACE); 365 ws = sway_container_parent(ws, C_WORKSPACE);
366 } 366 }
367 367
368 if (ws == NULL) { 368 if (ws == NULL) {
@@ -380,9 +380,9 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output,
380 return ws->children->items[0]; 380 return ws->children->items[0];
381 case MOVE_UP: 381 case MOVE_UP:
382 case MOVE_DOWN: { 382 case MOVE_DOWN: {
383 swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); 383 struct sway_container *focused = sway_seat_get_focus_inactive(seat, ws);
384 if (focused && focused->parent) { 384 if (focused && focused->parent) {
385 swayc_t *parent = focused->parent; 385 struct sway_container *parent = focused->parent;
386 if (parent->layout == L_VERT) { 386 if (parent->layout == L_VERT) {
387 if (dir == MOVE_UP) { 387 if (dir == MOVE_UP) {
388 // get child furthest down on new output 388 // get child furthest down on new output
@@ -404,13 +404,13 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output,
404 return ws; 404 return ws;
405} 405}
406 406
407static void get_layout_center_position(swayc_t *container, int *x, int *y) { 407static void get_layout_center_position(struct sway_container *container, int *x, int *y) {
408 // FIXME view coords are inconsistently referred to in layout/output systems 408 // FIXME view coords are inconsistently referred to in layout/output systems
409 if (container->type == C_OUTPUT) { 409 if (container->type == C_OUTPUT) {
410 *x = container->x + container->width/2; 410 *x = container->x + container->width/2;
411 *y = container->y + container->height/2; 411 *y = container->y + container->height/2;
412 } else { 412 } else {
413 swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); 413 struct sway_container *output = sway_container_parent(container, C_OUTPUT);
414 if (container->type == C_WORKSPACE) { 414 if (container->type == C_WORKSPACE) {
415 // Workspace coordinates are actually wrong/arbitrary, but should 415 // Workspace coordinates are actually wrong/arbitrary, but should
416 // be same as output. 416 // be same as output.
@@ -444,12 +444,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out
444 return true; 444 return true;
445} 445}
446 446
447static swayc_t *sway_output_from_wlr(struct wlr_output *output) { 447static struct sway_container *sway_output_from_wlr(struct wlr_output *output) {
448 if (output == NULL) { 448 if (output == NULL) {
449 return NULL; 449 return NULL;
450 } 450 }
451 for (int i = 0; i < root_container.children->length; ++i) { 451 for (int i = 0; i < root_container.children->length; ++i) {
452 swayc_t *o = root_container.children->items[i]; 452 struct sway_container *o = root_container.children->items[i];
453 if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { 453 if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) {
454 return o; 454 return o;
455 } 455 }
@@ -457,13 +457,13 @@ static swayc_t *sway_output_from_wlr(struct wlr_output *output) {
457 return NULL; 457 return NULL;
458} 458}
459 459
460static swayc_t *get_swayc_in_direction_under(swayc_t *container, 460static struct sway_container *get_swayc_in_direction_under(struct sway_container *container,
461 enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { 461 enum movement_direction dir, struct sway_seat *seat, struct sway_container *limit) {
462 if (dir == MOVE_CHILD) { 462 if (dir == MOVE_CHILD) {
463 return sway_seat_get_focus_inactive(seat, container); 463 return sway_seat_get_focus_inactive(seat, container);
464 } 464 }
465 465
466 swayc_t *parent = container->parent; 466 struct sway_container *parent = container->parent;
467 if (dir == MOVE_PARENT) { 467 if (dir == MOVE_PARENT) {
468 if (parent->type == C_OUTPUT) { 468 if (parent->type == C_OUTPUT) {
469 return NULL; 469 return NULL;
@@ -496,9 +496,9 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
496 /* 496 /*
497 if (container->type == C_VIEW && swayc_is_fullscreen(container)) { 497 if (container->type == C_VIEW && swayc_is_fullscreen(container)) {
498 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); 498 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
499 container = swayc_parent_by_type(container, C_OUTPUT); 499 container = sway_container_parent(container, C_OUTPUT);
500 get_layout_center_position(container, &abs_pos); 500 get_layout_center_position(container, &abs_pos);
501 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); 501 struct sway_container *output = swayc_adjacent_output(container, dir, &abs_pos, true);
502 return get_swayc_in_output_direction(output, dir); 502 return get_swayc_in_output_direction(output, dir);
503 } 503 }
504 if (container->type == C_WORKSPACE && container->fullscreen) { 504 if (container->type == C_WORKSPACE && container->fullscreen) {
@@ -507,7 +507,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
507 } 507 }
508 */ 508 */
509 509
510 swayc_t *wrap_candidate = NULL; 510 struct sway_container *wrap_candidate = NULL;
511 while (true) { 511 while (true) {
512 // Test if we can even make a difference here 512 // Test if we can even make a difference here
513 bool can_move = false; 513 bool can_move = false;
@@ -525,12 +525,12 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
525 struct wlr_output *wlr_adjacent = 525 struct wlr_output *wlr_adjacent =
526 wlr_output_layout_adjacent_output(layout, wlr_dir, 526 wlr_output_layout_adjacent_output(layout, wlr_dir,
527 container->sway_output->wlr_output, lx, ly); 527 container->sway_output->wlr_output, lx, ly);
528 swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); 528 struct sway_container *adjacent = sway_output_from_wlr(wlr_adjacent);
529 529
530 if (!adjacent || adjacent == container) { 530 if (!adjacent || adjacent == container) {
531 return wrap_candidate; 531 return wrap_candidate;
532 } 532 }
533 swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); 533 struct sway_container *next = get_swayc_in_output_direction(adjacent, dir, seat);
534 if (next == NULL) { 534 if (next == NULL) {
535 return NULL; 535 return NULL;
536 } 536 }
@@ -587,7 +587,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
587 } 587 }
588} 588}
589 589
590swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, 590struct sway_container *get_swayc_in_direction(struct sway_container *container, struct sway_seat *seat,
591 enum movement_direction dir) { 591 enum movement_direction dir) {
592 return get_swayc_in_direction_under(container, dir, seat, NULL); 592 return get_swayc_in_direction_under(container, dir, seat, NULL);
593} 593}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 3da3fde6..32e82845 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -17,7 +17,7 @@ struct workspace_by_number_data {
17 const char *name; 17 const char *name;
18}; 18};
19 19
20void next_name_map(swayc_t *ws, void *data) { 20void next_name_map(struct sway_container *ws, void *data) {
21 int *count = data; 21 int *count = data;
22 ++count; 22 ++count;
23} 23}
@@ -37,7 +37,7 @@ char *workspace_next_name(const char *output_name) {
37 return name; 37 return name;
38} 38}
39 39
40static bool _workspace_by_number(swayc_t *view, void *data) { 40static bool _workspace_by_number(struct sway_container *view, void *data) {
41 if (view->type != C_WORKSPACE) { 41 if (view->type != C_WORKSPACE) {
42 return false; 42 return false;
43 } 43 }
@@ -46,27 +46,27 @@ static bool _workspace_by_number(swayc_t *view, void *data) {
46 return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; 46 return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0;
47} 47}
48 48
49swayc_t *workspace_by_number(const char* name) { 49struct sway_container *workspace_by_number(const char* name) {
50 struct workspace_by_number_data wbnd = {0, "1234567890", name}; 50 struct workspace_by_number_data wbnd = {0, "1234567890", name};
51 wbnd.len = strspn(name, wbnd.cset); 51 wbnd.len = strspn(name, wbnd.cset);
52 if (wbnd.len <= 0) { 52 if (wbnd.len <= 0) {
53 return NULL; 53 return NULL;
54 } 54 }
55 return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); 55 return sway_container_find(&root_container, _workspace_by_number, (void *) &wbnd);
56} 56}
57 57
58static bool _workspace_by_name(swayc_t *view, void *data) { 58static bool _workspace_by_name(struct sway_container *view, void *data) {
59 return (view->type == C_WORKSPACE) && 59 return (view->type == C_WORKSPACE) &&
60 (strcasecmp(view->name, (char *) data) == 0); 60 (strcasecmp(view->name, (char *) data) == 0);
61} 61}
62 62
63swayc_t *workspace_by_name(const char *name) { 63struct sway_container *workspace_by_name(const char *name) {
64 struct sway_seat *seat = input_manager_current_seat(input_manager); 64 struct sway_seat *seat = input_manager_current_seat(input_manager);
65 swayc_t *current_workspace = NULL, *current_output = NULL; 65 struct sway_container *current_workspace = NULL, *current_output = NULL;
66 swayc_t *focus = sway_seat_get_focus(seat); 66 struct sway_container *focus = sway_seat_get_focus(seat);
67 if (focus) { 67 if (focus) {
68 current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); 68 current_workspace = sway_container_parent(focus, C_WORKSPACE);
69 current_output = swayc_parent_by_type(focus, C_OUTPUT); 69 current_output = sway_container_parent(focus, C_OUTPUT);
70 } 70 }
71 if (strcmp(name, "prev") == 0) { 71 if (strcmp(name, "prev") == 0) {
72 return workspace_prev(current_workspace); 72 return workspace_prev(current_workspace);
@@ -79,12 +79,12 @@ swayc_t *workspace_by_name(const char *name) {
79 } else if (strcmp(name, "current") == 0) { 79 } else if (strcmp(name, "current") == 0) {
80 return current_workspace; 80 return current_workspace;
81 } else { 81 } else {
82 return swayc_by_test(&root_container, _workspace_by_name, (void *) name); 82 return sway_container_find(&root_container, _workspace_by_name, (void *) name);
83 } 83 }
84} 84}
85 85
86swayc_t *workspace_create(const char *name) { 86struct sway_container *workspace_create(const char *name) {
87 swayc_t *parent; 87 struct sway_container *parent;
88 // Search for workspace<->output pair 88 // Search for workspace<->output pair
89 int i, e = config->workspace_outputs->length; 89 int i, e = config->workspace_outputs->length;
90 for (i = 0; i < e; ++i) { 90 for (i = 0; i < e; ++i) {
@@ -95,7 +95,7 @@ swayc_t *workspace_create(const char *name) {
95 for (i = 0; i < e; ++i) { 95 for (i = 0; i < e; ++i) {
96 parent = root_container.children->items[i]; 96 parent = root_container.children->items[i];
97 if (strcmp(parent->name, wso->output) == 0) { 97 if (strcmp(parent->name, wso->output) == 0) {
98 return new_workspace(parent, name); 98 return sway_container_workspace_create(parent, name);
99 } 99 }
100 } 100 }
101 break; 101 break;
@@ -103,10 +103,10 @@ swayc_t *workspace_create(const char *name) {
103 } 103 }
104 // Otherwise create a new one 104 // Otherwise create a new one
105 struct sway_seat *seat = input_manager_current_seat(input_manager); 105 struct sway_seat *seat = input_manager_current_seat(input_manager);
106 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 106 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
107 parent = focus; 107 parent = focus;
108 parent = swayc_parent_by_type(parent, C_OUTPUT); 108 parent = sway_container_parent(parent, C_OUTPUT);
109 return new_workspace(parent, name); 109 return sway_container_workspace_create(parent, name);
110} 110}
111 111
112/** 112/**
@@ -114,17 +114,17 @@ swayc_t *workspace_create(const char *name) {
114 * the end and beginning. If next is false, the previous workspace is returned, 114 * the end and beginning. If next is false, the previous workspace is returned,
115 * otherwise the next one is returned. 115 * otherwise the next one is returned.
116 */ 116 */
117swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { 117struct sway_container *workspace_output_prev_next_impl(struct sway_container *output, bool next) {
118 if (!sway_assert(output->type == C_OUTPUT, 118 if (!sway_assert(output->type == C_OUTPUT,
119 "Argument must be an output, is %d", output->type)) { 119 "Argument must be an output, is %d", output->type)) {
120 return NULL; 120 return NULL;
121 } 121 }
122 122
123 struct sway_seat *seat = input_manager_current_seat(input_manager); 123 struct sway_seat *seat = input_manager_current_seat(input_manager);
124 swayc_t *focus = sway_seat_get_focus_inactive(seat, output); 124 struct sway_container *focus = sway_seat_get_focus_inactive(seat, output);
125 swayc_t *workspace = (focus->type == C_WORKSPACE ? 125 struct sway_container *workspace = (focus->type == C_WORKSPACE ?
126 focus : 126 focus :
127 swayc_parent_by_type(focus, C_WORKSPACE)); 127 sway_container_parent(focus, C_WORKSPACE));
128 128
129 int i; 129 int i;
130 for (i = 0; i < output->children->length; i++) { 130 for (i = 0; i < output->children->length; i++) {
@@ -144,13 +144,13 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
144 * next is false, the previous workspace is returned, otherwise the next one is 144 * next is false, the previous workspace is returned, otherwise the next one is
145 * returned. 145 * returned.
146 */ 146 */
147swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { 147struct sway_container *workspace_prev_next_impl(struct sway_container *workspace, bool next) {
148 if (!sway_assert(workspace->type == C_WORKSPACE, 148 if (!sway_assert(workspace->type == C_WORKSPACE,
149 "Argument must be a workspace, is %d", workspace->type)) { 149 "Argument must be a workspace, is %d", workspace->type)) {
150 return NULL; 150 return NULL;
151 } 151 }
152 152
153 swayc_t *current_output = workspace->parent; 153 struct sway_container *current_output = workspace->parent;
154 int offset = next ? 1 : -1; 154 int offset = next ? 1 : -1;
155 int start = next ? 0 : 1; 155 int start = next ? 0 : 1;
156 int end; 156 int end;
@@ -170,7 +170,7 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
170 int num_outputs = root_container.children->length; 170 int num_outputs = root_container.children->length;
171 for (i = 0; i < num_outputs; i++) { 171 for (i = 0; i < num_outputs; i++) {
172 if (root_container.children->items[i] == current_output) { 172 if (root_container.children->items[i] == current_output) {
173 swayc_t *next_output = root_container.children->items[ 173 struct sway_container *next_output = root_container.children->items[
174 wrap(i + offset, num_outputs)]; 174 wrap(i + offset, num_outputs)];
175 return workspace_output_prev_next_impl(next_output, next); 175 return workspace_output_prev_next_impl(next_output, next);
176 } 176 }
@@ -180,40 +180,40 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
180 return NULL; 180 return NULL;
181} 181}
182 182
183swayc_t *workspace_output_next(swayc_t *current) { 183struct sway_container *workspace_output_next(struct sway_container *current) {
184 return workspace_output_prev_next_impl(current, true); 184 return workspace_output_prev_next_impl(current, true);
185} 185}
186 186
187swayc_t *workspace_next(swayc_t *current) { 187struct sway_container *workspace_next(struct sway_container *current) {
188 return workspace_prev_next_impl(current, true); 188 return workspace_prev_next_impl(current, true);
189} 189}
190 190
191swayc_t *workspace_output_prev(swayc_t *current) { 191struct sway_container *workspace_output_prev(struct sway_container *current) {
192 return workspace_output_prev_next_impl(current, false); 192 return workspace_output_prev_next_impl(current, false);
193} 193}
194 194
195swayc_t *workspace_prev(swayc_t *current) { 195struct sway_container *workspace_prev(struct sway_container *current) {
196 return workspace_prev_next_impl(current, false); 196 return workspace_prev_next_impl(current, false);
197} 197}
198 198
199bool workspace_switch(swayc_t *workspace) { 199bool workspace_switch(struct sway_container *workspace) {
200 if (!workspace) { 200 if (!workspace) {
201 return false; 201 return false;
202 } 202 }
203 struct sway_seat *seat = input_manager_current_seat(input_manager); 203 struct sway_seat *seat = input_manager_current_seat(input_manager);
204 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 204 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
205 if (!seat || !focus) { 205 if (!seat || !focus) {
206 return false; 206 return false;
207 } 207 }
208 swayc_t *active_ws = focus; 208 struct sway_container *active_ws = focus;
209 if (active_ws->type != C_WORKSPACE) { 209 if (active_ws->type != C_WORKSPACE) {
210 swayc_parent_by_type(focus, C_WORKSPACE); 210 sway_container_parent(focus, C_WORKSPACE);
211 } 211 }
212 212
213 if (config->auto_back_and_forth 213 if (config->auto_back_and_forth
214 && active_ws == workspace 214 && active_ws == workspace
215 && prev_workspace_name) { 215 && prev_workspace_name) {
216 swayc_t *new_ws = workspace_by_name(prev_workspace_name); 216 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
217 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); 217 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name);
218 } 218 }
219 219
@@ -231,12 +231,12 @@ bool workspace_switch(swayc_t *workspace) {
231 // TODO: Deal with sticky containers 231 // TODO: Deal with sticky containers
232 232
233 wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); 233 wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
234 swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); 234 struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace);
235 if (next == NULL) { 235 if (next == NULL) {
236 next = workspace; 236 next = workspace;
237 } 237 }
238 sway_seat_set_focus(seat, next); 238 sway_seat_set_focus(seat, next);
239 swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); 239 struct sway_container *output = sway_container_parent(workspace, C_OUTPUT);
240 arrange_windows(output, -1, -1); 240 arrange_windows(output, -1, -1);
241 return true; 241 return true;
242} 242}