aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 23:41:33 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 23:41:33 -0400
commitdc8c9fbeb664518c76066cc28ee29452c6c30128 (patch)
tree88c2de0d08e00b2a30cb20cdfadfa6e53f5c59b4 /sway
parentMerge pull request #1653 from swaywm/revert-1647-refactor-tree (diff)
downloadsway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.gz
sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.zst
sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.zip
Revert "Merge pull request #1653 from swaywm/revert-1647-refactor-tree"
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/exec_always.c4
-rw-r--r--sway/commands/focus.c9
-rw-r--r--sway/commands/kill.c4
-rw-r--r--sway/commands/layout.c20
-rw-r--r--sway/commands/output.c2
-rw-r--r--sway/commands/reload.c2
-rw-r--r--sway/commands/workspace.c14
-rw-r--r--sway/config.c2
-rw-r--r--sway/config/output.c4
-rw-r--r--sway/criteria.c16
-rw-r--r--sway/desktop/layer_shell.c2
-rw-r--r--sway/desktop/output.c20
-rw-r--r--sway/desktop/wl_shell.c12
-rw-r--r--sway/desktop/xdg_shell_v6.c12
-rw-r--r--sway/desktop/xwayland.c24
-rw-r--r--sway/input/cursor.c10
-rw-r--r--sway/input/input-manager.c4
-rw-r--r--sway/input/seat.c38
-rw-r--r--sway/ipc-json.c16
-rw-r--r--sway/ipc-server.c4
-rw-r--r--sway/main.c4
-rw-r--r--sway/tree/container.c221
-rw-r--r--sway/tree/layout.c133
-rw-r--r--sway/tree/view.c7
-rw-r--r--sway/tree/workspace.c92
25 files changed, 349 insertions, 327 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index 61870c51..954950e7 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -6,8 +6,8 @@
6#include <unistd.h> 6#include <unistd.h>
7#include "sway/commands.h" 7#include "sway/commands.h"
8#include "sway/config.h" 8#include "sway/config.h"
9#include "sway/container.h" 9#include "sway/tree/container.h"
10#include "sway/workspace.h" 10#include "sway/tree/workspace.h"
11#include "log.h" 11#include "log.h"
12#include "stringop.h" 12#include "stringop.h"
13 13
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index f1a8078f..64f079f4 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -3,10 +3,11 @@
3#include "log.h" 3#include "log.h"
4#include "sway/input/input-manager.h" 4#include "sway/input/input-manager.h"
5#include "sway/input/seat.h" 5#include "sway/input/seat.h"
6#include "sway/view.h" 6#include "sway/tree/view.h"
7#include "sway/commands.h" 7#include "sway/commands.h"
8 8
9static bool parse_movement_direction(const char *name, enum movement_direction *out) { 9static bool parse_movement_direction(const char *name,
10 enum movement_direction *out) {
10 if (strcasecmp(name, "left") == 0) { 11 if (strcasecmp(name, "left") == 0) {
11 *out = MOVE_LEFT; 12 *out = MOVE_LEFT;
12 } else if (strcasecmp(name, "right") == 0) { 13 } else if (strcasecmp(name, "right") == 0) {
@@ -31,7 +32,7 @@ static bool parse_movement_direction(const char *name, enum movement_direction *
31} 32}
32 33
33struct cmd_results *cmd_focus(int argc, char **argv) { 34struct cmd_results *cmd_focus(int argc, char **argv) {
34 swayc_t *con = config->handler_context.current_container; 35 struct sway_container *con = config->handler_context.current_container;
35 struct sway_seat *seat = config->handler_context.seat; 36 struct sway_seat *seat = config->handler_context.seat;
36 if (con->type < C_WORKSPACE) { 37 if (con->type < C_WORKSPACE) {
37 return cmd_results_new(CMD_FAILURE, "focus", 38 return cmd_results_new(CMD_FAILURE, "focus",
@@ -50,7 +51,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
50 "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>'");
51 } 52 }
52 53
53 swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); 54 struct sway_container *next_focus = container_get_in_direction(con, seat, direction);
54 if (next_focus) { 55 if (next_focus) {
55 sway_seat_set_focus(seat, next_focus); 56 sway_seat_set_focus(seat, next_focus);
56 } 57 }
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index f408ce2a..f6774767 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -2,11 +2,11 @@
2#include "log.h" 2#include "log.h"
3#include "sway/input/input-manager.h" 3#include "sway/input/input-manager.h"
4#include "sway/input/seat.h" 4#include "sway/input/seat.h"
5#include "sway/view.h" 5#include "sway/tree/view.h"
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 b0fc5d66..ebab2a48 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -1,8 +1,8 @@
1#include <string.h> 1#include <string.h>
2#include <strings.h> 2#include <strings.h>
3#include "sway/commands.h" 3#include "sway/commands.h"
4#include "sway/container.h" 4#include "sway/tree/container.h"
5#include "sway/layout.h" 5#include "sway/tree/layout.h"
6#include "log.h" 6#include "log.h"
7 7
8struct cmd_results *cmd_layout(int argc, char **argv) { 8struct cmd_results *cmd_layout(int argc, char **argv) {
@@ -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 /*
@@ -26,10 +26,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
26 // TODO: stacks and tabs 26 // TODO: stacks and tabs
27 27
28 if (strcasecmp(argv[0], "default") == 0) { 28 if (strcasecmp(argv[0], "default") == 0) {
29 swayc_change_layout(parent, parent->prev_layout); 29 container_set_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 = container_parent(parent, C_OUTPUT);
32 swayc_change_layout(parent, default_layout(output)); 32 container_set_layout(parent, container_get_default_layout(output));
33 } 33 }
34 } else { 34 } else {
35 if (parent->layout != L_TABBED && parent->layout != L_STACKED) { 35 if (parent->layout != L_TABBED && parent->layout != L_STACKED) {
@@ -37,15 +37,15 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
37 } 37 }
38 38
39 if (strcasecmp(argv[0], "splith") == 0) { 39 if (strcasecmp(argv[0], "splith") == 0) {
40 swayc_change_layout(parent, L_HORIZ); 40 container_set_layout(parent, L_HORIZ);
41 } else if (strcasecmp(argv[0], "splitv") == 0) { 41 } else if (strcasecmp(argv[0], "splitv") == 0) {
42 swayc_change_layout(parent, L_VERT); 42 container_set_layout(parent, L_VERT);
43 } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { 43 } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) {
44 if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE 44 if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE
45 || parent->workspace_layout == L_HORIZ)) { 45 || parent->workspace_layout == L_HORIZ)) {
46 swayc_change_layout(parent, L_VERT); 46 container_set_layout(parent, L_VERT);
47 } else { 47 } else {
48 swayc_change_layout(parent, L_HORIZ); 48 container_set_layout(parent, L_HORIZ);
49 } 49 }
50 } 50 }
51 } 51 }
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/reload.c b/sway/commands/reload.c
index d54d40db..8cef789b 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -1,6 +1,6 @@
1#include "sway/commands.h" 1#include "sway/commands.h"
2#include "sway/config.h" 2#include "sway/config.h"
3#include "sway/layout.h" 3#include "sway/tree/layout.h"
4 4
5struct cmd_results *cmd_reload(int argc, char **argv) { 5struct cmd_results *cmd_reload(int argc, char **argv) {
6 struct cmd_results *error = NULL; 6 struct cmd_results *error = NULL;
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index fa891398..8f39e5fc 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -4,7 +4,7 @@
4#include "sway/commands.h" 4#include "sway/commands.h"
5#include "sway/config.h" 5#include "sway/config.h"
6#include "sway/input/seat.h" 6#include "sway/input/seat.h"
7#include "sway/workspace.h" 7#include "sway/tree/workspace.h"
8#include "list.h" 8#include "list.h"
9#include "log.h" 9#include "log.h"
10#include "stringop.h" 10#include "stringop.h"
@@ -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 = container_parent(current_container, C_WORKSPACE);
27 } 27 }
28 old_output = swayc_parent_by_type(current_container, C_OUTPUT); 28 old_output = 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 = 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.c b/sway/config.c
index 213e7680..0b29735a 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -24,7 +24,7 @@
24#include "sway/input/seat.h" 24#include "sway/input/seat.h"
25#include "sway/commands.h" 25#include "sway/commands.h"
26#include "sway/config.h" 26#include "sway/config.h"
27#include "sway/layout.h" 27#include "sway/tree/layout.h"
28#include "readline.h" 28#include "readline.h"
29#include "stringop.h" 29#include "stringop.h"
30#include "list.h" 30#include "list.h"
diff --git a/sway/config/output.c b/sway/config/output.c
index 9e211861..7fc79739 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 container_output_destroy(output);
131 return; 131 return;
132 } 132 }
133 133
diff --git a/sway/criteria.c b/sway/criteria.c
index 2eee331c..247f6b75 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -4,9 +4,9 @@
4#include <stdbool.h> 4#include <stdbool.h>
5#include <pcre.h> 5#include <pcre.h>
6#include "sway/criteria.h" 6#include "sway/criteria.h"
7#include "sway/container.h" 7#include "sway/tree/container.h"
8#include "sway/config.h" 8#include "sway/config.h"
9#include "sway/view.h" 9#include "sway/tree/view.h"
10#include "stringop.h" 10#include "stringop.h"
11#include "list.h" 11#include "list.h"
12#include "log.h" 12#include "log.h"
@@ -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 container_for_each_descendent(&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/layer_shell.c b/sway/desktop/layer_shell.c
index bd62f84a..137b3260 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -7,7 +7,7 @@
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include <wlr/util/log.h> 8#include <wlr/util/log.h>
9#include "sway/layers.h" 9#include "sway/layers.h"
10#include "sway/layout.h" 10#include "sway/tree/layout.h"
11#include "sway/output.h" 11#include "sway/output.h"
12#include "sway/server.h" 12#include "sway/server.h"
13 13
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index b8253ace..ba778f4c 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -11,14 +11,14 @@
11#include <wlr/types/wlr_surface.h> 11#include <wlr/types/wlr_surface.h>
12#include <wlr/types/wlr_wl_shell.h> 12#include <wlr/types/wlr_wl_shell.h>
13#include "log.h" 13#include "log.h"
14#include "sway/container.h" 14#include "sway/tree/container.h"
15#include "sway/input/input-manager.h" 15#include "sway/input/input-manager.h"
16#include "sway/input/seat.h" 16#include "sway/input/seat.h"
17#include "sway/layers.h" 17#include "sway/layers.h"
18#include "sway/layout.h" 18#include "sway/tree/layout.h"
19#include "sway/output.h" 19#include "sway/output.h"
20#include "sway/server.h" 20#include "sway/server.h"
21#include "sway/view.h" 21#include "sway/tree/view.h"
22 22
23/** 23/**
24 * Rotate a child's position relative to a parent. The parent size is (pw, ph), 24 * Rotate a child's position relative to a parent. The parent size is (pw, ph),
@@ -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;
@@ -219,16 +219,16 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
219 &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); 219 &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
220 220
221 struct sway_seat *seat = input_manager_current_seat(input_manager); 221 struct sway_seat *seat = input_manager_current_seat(input_manager);
222 swayc_t *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); 222 struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc);
223 swayc_t *workspace = (focus->type == C_WORKSPACE ? 223 struct sway_container *workspace = (focus->type == C_WORKSPACE ?
224 focus : 224 focus :
225 swayc_parent_by_type(focus, C_WORKSPACE)); 225 container_parent(focus, C_WORKSPACE));
226 226
227 struct render_data rdata = { 227 struct render_data rdata = {
228 .output = soutput, 228 .output = soutput,
229 .now = &now, 229 .now = &now,
230 }; 230 };
231 swayc_descendants_of_type(workspace, C_VIEW, output_frame_view, &rdata); 231 container_descendents(workspace, C_VIEW, output_frame_view, &rdata);
232 232
233 // render unmanaged views on top 233 // render unmanaged views on top
234 struct sway_view *view; 234 struct sway_view *view;
@@ -259,7 +259,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) {
259 struct wlr_output *wlr_output = data; 259 struct wlr_output *wlr_output = data;
260 wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); 260 wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name);
261 261
262 destroy_output(output->swayc); 262 container_output_destroy(output->swayc);
263} 263}
264 264
265static void handle_output_mode(struct wl_listener *listener, void *data) { 265static void handle_output_mode(struct wl_listener *listener, void *data) {
@@ -287,7 +287,7 @@ void handle_new_output(struct wl_listener *listener, void *data) {
287 wlr_output_set_mode(wlr_output, mode); 287 wlr_output_set_mode(wlr_output, mode);
288 } 288 }
289 289
290 output->swayc = new_output(output); 290 output->swayc = container_output_create(output);
291 if (!output->swayc) { 291 if (!output->swayc) {
292 free(output); 292 free(output);
293 return; 293 return;
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index 0356aa81..4d4d1ed7 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -3,10 +3,10 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <wayland-server.h> 4#include <wayland-server.h>
5#include <wlr/types/wlr_wl_shell.h> 5#include <wlr/types/wlr_wl_shell.h>
6#include "sway/container.h" 6#include "sway/tree/container.h"
7#include "sway/layout.h" 7#include "sway/tree/layout.h"
8#include "sway/server.h" 8#include "sway/server.h"
9#include "sway/view.h" 9#include "sway/tree/view.h"
10#include "sway/input/seat.h" 10#include "sway/input/seat.h"
11#include "sway/input/input-manager.h" 11#include "sway/input/input-manager.h"
12#include "log.h" 12#include "log.h"
@@ -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 = 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 = 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 18e7d399..25c0cbca 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -3,10 +3,10 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <wayland-server.h> 4#include <wayland-server.h>
5#include <wlr/types/wlr_xdg_shell_v6.h> 5#include <wlr/types/wlr_xdg_shell_v6.h>
6#include "sway/container.h" 6#include "sway/tree/container.h"
7#include "sway/layout.h" 7#include "sway/tree/layout.h"
8#include "sway/server.h" 8#include "sway/server.h"
9#include "sway/view.h" 9#include "sway/tree/view.h"
10#include "sway/input/seat.h" 10#include "sway/input/seat.h"
11#include "sway/input/input-manager.h" 11#include "sway/input/input-manager.h"
12#include "log.h" 12#include "log.h"
@@ -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 = 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);
@@ -137,8 +137,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
137 wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); 137 wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy);
138 138
139 struct sway_seat *seat = input_manager_current_seat(input_manager); 139 struct sway_seat *seat = input_manager_current_seat(input_manager);
140 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 140 struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container);
141 swayc_t *cont = new_view(focus, sway_view); 141 struct sway_container *cont = container_view_create(focus, sway_view);
142 sway_view->swayc = cont; 142 sway_view->swayc = cont;
143 143
144 arrange_windows(cont->parent, -1, -1); 144 arrange_windows(cont->parent, -1, -1);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index f9b5242b..fd0bcaca 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -5,10 +5,10 @@
5#include <wlr/xwayland.h> 5#include <wlr/xwayland.h>
6#include <wlr/types/wlr_output_layout.h> 6#include <wlr/types/wlr_output_layout.h>
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include "sway/container.h" 8#include "sway/tree/container.h"
9#include "sway/layout.h" 9#include "sway/tree/layout.h"
10#include "sway/server.h" 10#include "sway/server.h"
11#include "sway/view.h" 11#include "sway/tree/view.h"
12#include "sway/output.h" 12#include "sway/output.h"
13#include "sway/input/seat.h" 13#include "sway/input/seat.h"
14#include "sway/input/input-manager.h" 14#include "sway/input/input-manager.h"
@@ -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 = 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 = 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 = 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 = 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 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 = 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 = 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 8a0d1df5..d57ac3e3 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -7,7 +7,7 @@
7#include <wlr/types/wlr_cursor.h> 7#include <wlr/types/wlr_cursor.h>
8#include <wlr/types/wlr_xcursor_manager.h> 8#include <wlr/types/wlr_xcursor_manager.h>
9#include "sway/input/cursor.h" 9#include "sway/input/cursor.h"
10#include "sway/view.h" 10#include "sway/tree/view.h"
11#include "list.h" 11#include "list.h"
12#include "log.h" 12#include "log.h"
13 13
@@ -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 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 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/input-manager.c b/sway/input/input-manager.c
index 27c2c72e..d421a03f 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -278,7 +278,7 @@ struct sway_input_manager *sway_input_manager_create(
278} 278}
279 279
280bool sway_input_manager_has_focus(struct sway_input_manager *input, 280bool sway_input_manager_has_focus(struct sway_input_manager *input,
281 swayc_t *container) { 281 struct sway_container *container) {
282 struct sway_seat *seat = NULL; 282 struct sway_seat *seat = NULL;
283 wl_list_for_each(seat, &input->seats, link) { 283 wl_list_for_each(seat, &input->seats, link) {
284 if (sway_seat_get_focus(seat) == container) { 284 if (sway_seat_get_focus(seat) == container) {
@@ -290,7 +290,7 @@ bool sway_input_manager_has_focus(struct sway_input_manager *input,
290} 290}
291 291
292void sway_input_manager_set_focus(struct sway_input_manager *input, 292void sway_input_manager_set_focus(struct sway_input_manager *input,
293 swayc_t *container) { 293 struct sway_container *container) {
294 struct sway_seat *seat ; 294 struct sway_seat *seat ;
295 wl_list_for_each(seat, &input->seats, link) { 295 wl_list_for_each(seat, &input->seats, link) {
296 sway_seat_set_focus(seat, container); 296 sway_seat_set_focus(seat, container);
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 648e7914..76d29b52 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -1,13 +1,13 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#include <wlr/types/wlr_cursor.h> 2#include <wlr/types/wlr_cursor.h>
3#include <wlr/types/wlr_xcursor_manager.h> 3#include <wlr/types/wlr_xcursor_manager.h>
4#include "sway/container.h" 4#include "sway/tree/container.h"
5#include "sway/input/seat.h" 5#include "sway/input/seat.h"
6#include "sway/input/cursor.h" 6#include "sway/input/cursor.h"
7#include "sway/input/input-manager.h" 7#include "sway/input/input-manager.h"
8#include "sway/input/keyboard.h" 8#include "sway/input/keyboard.h"
9#include "sway/output.h" 9#include "sway/output.h"
10#include "sway/view.h" 10#include "sway/tree/view.h"
11#include "log.h" 11#include "log.h"
12 12
13static void seat_device_destroy(struct sway_seat_device *seat_device) { 13static void seat_device_destroy(struct sway_seat_device *seat_device) {
@@ -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 container_for_each_descendent(&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 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 977f1ecb..7caa2457 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -3,7 +3,7 @@
3#include <ctype.h> 3#include <ctype.h>
4#include "log.h" 4#include "log.h"
5#include "sway/ipc-json.h" 5#include "sway/ipc-json.h"
6#include "sway/container.h" 6#include "sway/tree/container.h"
7#include "sway/output.h" 7#include "sway/output.h"
8#include "sway/input/input-manager.h" 8#include "sway/input/input-manager.h"
9#include "sway/input/seat.h" 9#include "sway/input/seat.h"
@@ -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/main.c b/sway/main.c
index f2f24be3..ded922ee 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -18,7 +18,7 @@
18#include <wlr/util/log.h> 18#include <wlr/util/log.h>
19#include "sway/config.h" 19#include "sway/config.h"
20#include "sway/server.h" 20#include "sway/server.h"
21#include "sway/layout.h" 21#include "sway/tree/layout.h"
22#include "sway/ipc-server.h" 22#include "sway/ipc-server.h"
23#include "ipc-client.h" 23#include "ipc-client.h"
24#include "readline.h" 24#include "readline.h"
@@ -382,7 +382,7 @@ int main(int argc, char **argv) {
382 382
383 wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); 383 wlr_log(L_INFO, "Starting sway version " SWAY_VERSION);
384 384
385 init_layout(); 385 layout_init();
386 386
387 if (!server_init(&server)) { 387 if (!server_init(&server)) {
388 return 1; 388 return 1;
diff --git a/sway/tree/container.c b/sway/tree/container.c
index bbafe9ec..40047dcf 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -7,14 +7,14 @@
7#include <wlr/types/wlr_output_layout.h> 7#include <wlr/types/wlr_output_layout.h>
8#include <wlr/types/wlr_wl_shell.h> 8#include <wlr/types/wlr_wl_shell.h>
9#include "sway/config.h" 9#include "sway/config.h"
10#include "sway/container.h" 10#include "sway/tree/container.h"
11#include "sway/input/input-manager.h" 11#include "sway/input/input-manager.h"
12#include "sway/input/seat.h" 12#include "sway/input/seat.h"
13#include "sway/layout.h" 13#include "sway/tree/layout.h"
14#include "sway/output.h" 14#include "sway/output.h"
15#include "sway/server.h" 15#include "sway/server.h"
16#include "sway/view.h" 16#include "sway/tree/view.h"
17#include "sway/workspace.h" 17#include "sway/tree/workspace.h"
18#include "sway/ipc-server.h" 18#include "sway/ipc-server.h"
19#include "log.h" 19#include "log.h"
20 20
@@ -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 *container_create(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 }
@@ -82,8 +49,6 @@ static swayc_t *new_swayc(enum swayc_types type) {
82 c->layout = L_NONE; 49 c->layout = L_NONE;
83 c->workspace_layout = L_NONE; 50 c->workspace_layout = L_NONE;
84 c->type = type; 51 c->type = type;
85 c->nb_master = 1;
86 c->nb_slave_groups = 1;
87 if (type != C_VIEW) { 52 if (type != C_VIEW) {
88 c->children = create_list(); 53 c->children = create_list();
89 } 54 }
@@ -93,18 +58,18 @@ static swayc_t *new_swayc(enum swayc_types type) {
93 return c; 58 return c;
94} 59}
95 60
96static void free_swayc(swayc_t *cont) { 61static void container_destroy(struct sway_container *cont) {
97 if (!sway_assert(cont, "free_swayc passed NULL")) { 62 if (cont == NULL) {
98 return; 63 return;
99 } 64 }
100 65
101 wl_signal_emit(&cont->events.destroy, cont); 66 wl_signal_emit(&cont->events.destroy, cont);
102 67
103 if (cont->children) { 68 if (cont->children) {
104 // remove children until there are no more, free_swayc calls 69 // remove children until there are no more, container_destroy calls
105 // remove_child, which removes child from this container 70 // container_remove_child, which removes child from this container
106 while (cont->children->length) { 71 while (cont->children->length) {
107 free_swayc(cont->children->items[0]); 72 container_destroy(cont->children->items[0]);
108 } 73 }
109 list_free(cont->children); 74 list_free(cont->children);
110 } 75 }
@@ -113,7 +78,7 @@ static void free_swayc(swayc_t *cont) {
113 list_free(cont->marks); 78 list_free(cont->marks);
114 } 79 }
115 if (cont->parent) { 80 if (cont->parent) {
116 remove_child(cont); 81 container_remove_child(cont);
117 } 82 }
118 if (cont->name) { 83 if (cont->name) {
119 free(cont->name); 84 free(cont->name);
@@ -121,7 +86,8 @@ static void free_swayc(swayc_t *cont) {
121 free(cont); 86 free(cont);
122} 87}
123 88
124swayc_t *new_output(struct sway_output *sway_output) { 89struct sway_container *container_output_create(
90 struct sway_output *sway_output) {
125 struct wlr_box size; 91 struct wlr_box size;
126 wlr_output_effective_resolution(sway_output->wlr_output, &size.width, 92 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
127 &size.height); 93 &size.height);
@@ -156,22 +122,22 @@ swayc_t *new_output(struct sway_output *sway_output) {
156 return NULL; 122 return NULL;
157 } 123 }
158 124
159 swayc_t *output = new_swayc(C_OUTPUT); 125 struct sway_container *output = container_create(C_OUTPUT);
160 output->sway_output = sway_output; 126 output->sway_output = sway_output;
161 output->name = strdup(name); 127 output->name = strdup(name);
162 if (output->name == NULL) { 128 if (output->name == NULL) {
163 free_swayc(output); 129 container_destroy(output);
164 return NULL; 130 return NULL;
165 } 131 }
166 132
167 apply_output_config(oc, output); 133 apply_output_config(oc, output);
168 134
169 add_child(&root_container, output); 135 container_add_child(&root_container, output);
170 136
171 // Create workspace 137 // Create workspace
172 char *ws_name = workspace_next_name(output->name); 138 char *ws_name = workspace_next_name(output->name);
173 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); 139 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name);
174 swayc_t *ws = new_workspace(output, ws_name); 140 struct sway_container *ws = container_workspace_create(output, ws_name);
175 // Set each seat's focus if not already set 141 // Set each seat's focus if not already set
176 struct sway_seat *seat = NULL; 142 struct sway_seat *seat = NULL;
177 wl_list_for_each(seat, &input_manager->seats, link) { 143 wl_list_for_each(seat, &input_manager->seats, link) {
@@ -185,12 +151,14 @@ swayc_t *new_output(struct sway_output *sway_output) {
185 return output; 151 return output;
186} 152}
187 153
188swayc_t *new_workspace(swayc_t *output, const char *name) { 154struct sway_container *container_workspace_create(
189 if (!sway_assert(output, "new_workspace called with null output")) { 155 struct sway_container *output, const char *name) {
156 if (!sway_assert(output,
157 "container_workspace_create called with null output")) {
190 return NULL; 158 return NULL;
191 } 159 }
192 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 160 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
193 swayc_t *workspace = new_swayc(C_WORKSPACE); 161 struct sway_container *workspace = container_create(C_WORKSPACE);
194 162
195 workspace->x = output->x; 163 workspace->x = output->x;
196 workspace->y = output->y; 164 workspace->y = output->y;
@@ -198,21 +166,23 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
198 workspace->height = output->height; 166 workspace->height = output->height;
199 workspace->name = !name ? NULL : strdup(name); 167 workspace->name = !name ? NULL : strdup(name);
200 workspace->prev_layout = L_NONE; 168 workspace->prev_layout = L_NONE;
201 workspace->layout = default_layout(output); 169 workspace->layout = container_get_default_layout(output);
202 workspace->workspace_layout = default_layout(output); 170 workspace->workspace_layout = container_get_default_layout(output);
203 171
204 add_child(output, workspace); 172 container_add_child(output, workspace);
205 sort_workspaces(output); 173 container_sort_workspaces(output);
206 notify_new_container(workspace); 174 notify_new_container(workspace);
207 return workspace; 175 return workspace;
208} 176}
209 177
210swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { 178struct sway_container *container_view_create(struct sway_container *sibling,
211 if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { 179 struct sway_view *sway_view) {
180 if (!sway_assert(sibling,
181 "container_view_create called with NULL sibling/parent")) {
212 return NULL; 182 return NULL;
213 } 183 }
214 const char *title = view_get_title(sway_view); 184 const char *title = view_get_title(sway_view);
215 swayc_t *swayc = new_swayc(C_VIEW); 185 struct sway_container *swayc = container_create(C_VIEW);
216 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", 186 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s",
217 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); 187 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name);
218 // Setup values 188 // Setup values
@@ -223,17 +193,18 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
223 193
224 if (sibling->type == C_WORKSPACE) { 194 if (sibling->type == C_WORKSPACE) {
225 // Case of focused workspace, just create as child of it 195 // Case of focused workspace, just create as child of it
226 add_child(sibling, swayc); 196 container_add_child(sibling, swayc);
227 } else { 197 } else {
228 // Regular case, create as sibling of current container 198 // Regular case, create as sibling of current container
229 add_sibling(sibling, swayc); 199 container_add_sibling(sibling, swayc);
230 } 200 }
231 notify_new_container(swayc); 201 notify_new_container(swayc);
232 return swayc; 202 return swayc;
233} 203}
234 204
235swayc_t *destroy_output(swayc_t *output) { 205struct sway_container *container_output_destroy(struct sway_container *output) {
236 if (!sway_assert(output, "null output passed to destroy_output")) { 206 if (!sway_assert(output,
207 "null output passed to container_output_destroy")) {
237 return NULL; 208 return NULL;
238 } 209 }
239 210
@@ -245,12 +216,13 @@ swayc_t *destroy_output(swayc_t *output) {
245 int p = root_container.children->items[0] == output; 216 int p = root_container.children->items[0] == output;
246 // Move workspace from this output to another output 217 // Move workspace from this output to another output
247 while (output->children->length) { 218 while (output->children->length) {
248 swayc_t *child = output->children->items[0]; 219 struct sway_container *child = output->children->items[0];
249 remove_child(child); 220 container_remove_child(child);
250 add_child(root_container.children->items[p], child); 221 container_add_child(root_container.children->items[p], child);
251 } 222 }
252 sort_workspaces(root_container.children->items[p]); 223 container_sort_workspaces(root_container.children->items[p]);
253 arrange_windows(root_container.children->items[p], -1, -1); 224 arrange_windows(root_container.children->items[p],
225 -1, -1);
254 } 226 }
255 } 227 }
256 228
@@ -259,18 +231,18 @@ swayc_t *destroy_output(swayc_t *output) {
259 wl_list_remove(&output->sway_output->mode.link); 231 wl_list_remove(&output->sway_output->mode.link);
260 232
261 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); 233 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
262 free_swayc(output); 234 container_destroy(output);
263 235
264 return &root_container; 236 return &root_container;
265} 237}
266 238
267swayc_t *destroy_view(swayc_t *view) { 239struct sway_container *container_view_destroy(struct sway_container *view) {
268 if (!view) { 240 if (!view) {
269 return NULL; 241 return NULL;
270 } 242 }
271 wlr_log(L_DEBUG, "Destroying view '%s'", view->name); 243 wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
272 swayc_t *parent = view->parent; 244 struct sway_container *parent = view->parent;
273 free_swayc(view); 245 container_destroy(view);
274 246
275 // TODO WLR: Destroy empty containers 247 // TODO WLR: Destroy empty containers
276 /* 248 /*
@@ -281,7 +253,55 @@ swayc_t *destroy_view(swayc_t *view) {
281 return parent; 253 return parent;
282} 254}
283 255
284swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { 256struct sway_container *container_set_layout(struct sway_container *container,
257 enum sway_container_layout layout) {
258 if (container->type == C_WORKSPACE) {
259 container->workspace_layout = layout;
260 if (layout == L_HORIZ || layout == L_VERT) {
261 container->layout = layout;
262 }
263 } else {
264 container->layout = layout;
265 }
266 return container;
267}
268
269void container_descendents(struct sway_container *root,
270 enum sway_container_type type,
271 void (*func)(struct sway_container *item, void *data), void *data) {
272 for (int i = 0; i < root->children->length; ++i) {
273 struct sway_container *item = root->children->items[i];
274 if (item->type == type) {
275 func(item, data);
276 }
277 if (item->children && item->children->length) {
278 container_descendents(item, type, func, data);
279 }
280 }
281}
282
283struct sway_container *container_find(struct sway_container *container,
284 bool (*test)(struct sway_container *view, void *data), void *data) {
285 if (!container->children) {
286 return NULL;
287 }
288 // TODO: floating windows
289 for (int i = 0; i < container->children->length; ++i) {
290 struct sway_container *child = container->children->items[i];
291 if (test(child, data)) {
292 return child;
293 } else {
294 struct sway_container *res = container_find(child, test, data);
295 if (res) {
296 return res;
297 }
298 }
299 }
300 return NULL;
301}
302
303struct sway_container *container_parent(struct sway_container *container,
304 enum sway_container_type type) {
285 if (!sway_assert(container, "container is NULL")) { 305 if (!sway_assert(container, "container is NULL")) {
286 return NULL; 306 return NULL;
287 } 307 }
@@ -294,7 +314,8 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
294 return container; 314 return container;
295} 315}
296 316
297swayc_t *swayc_at(swayc_t *parent, double lx, double ly, 317struct sway_container *container_at(struct sway_container *parent,
318 double lx, double ly,
298 struct wlr_surface **surface, double *sx, double *sy) { 319 struct wlr_surface **surface, double *sx, double *sy) {
299 list_t *queue = get_bfs_queue(); 320 list_t *queue = get_bfs_queue();
300 if (!queue) { 321 if (!queue) {
@@ -303,13 +324,13 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
303 324
304 list_add(queue, parent); 325 list_add(queue, parent);
305 326
306 swayc_t *swayc = NULL; 327 struct sway_container *swayc = NULL;
307 while (queue->length) { 328 while (queue->length) {
308 swayc = queue->items[0]; 329 swayc = queue->items[0];
309 list_del(queue, 0); 330 list_del(queue, 0);
310 if (swayc->type == C_VIEW) { 331 if (swayc->type == C_VIEW) {
311 struct sway_view *sview = swayc->sway_view; 332 struct sway_view *sview = swayc->sway_view;
312 swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); 333 struct sway_container *soutput = container_parent(swayc, C_OUTPUT);
313 struct wlr_box *output_box = 334 struct wlr_box *output_box =
314 wlr_output_layout_get_box( 335 wlr_output_layout_get_box(
315 root_container.sway_root->output_layout, 336 root_container.sway_root->output_layout,
@@ -379,30 +400,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
379 return NULL; 400 return NULL;
380} 401}
381 402
382void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 403void container_for_each_descendent(struct sway_container *con,
383 if (container) { 404 void (*f)(struct sway_container *con, void *data), void *data) {
384 int i;
385 if (container->children) {
386 for (i = 0; i < container->children->length; ++i) {
387 swayc_t *child = container->children->items[i];
388 container_map(child, f, data);
389 }
390 }
391 // TODO
392 /*
393 if (container->floating) {
394 for (i = 0; i < container->floating->length; ++i) {
395 swayc_t *child = container->floating->items[i];
396 container_map(child, f, data);
397 }
398 }
399 */
400 f(container, data);
401 }
402}
403
404void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
405 void *data) {
406 list_t *queue = get_bfs_queue(); 405 list_t *queue = get_bfs_queue();
407 if (!queue) { 406 if (!queue) {
408 return; 407 return;
@@ -415,7 +414,7 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
415 414
416 list_add(queue, con); 415 list_add(queue, con);
417 416
418 swayc_t *current = NULL; 417 struct sway_container *current = NULL;
419 while (queue->length) { 418 while (queue->length) {
420 current = queue->items[0]; 419 current = queue->items[0];
421 list_del(queue, 0); 420 list_del(queue, 0);
@@ -424,15 +423,3 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
424 list_cat(queue, current->children); 423 list_cat(queue, current->children);
425 } 424 }
426} 425}
427
428swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
429 if (container->type == C_WORKSPACE) {
430 container->workspace_layout = layout;
431 if (layout == L_HORIZ || layout == L_VERT) {
432 container->layout = layout;
433 }
434 } else {
435 container->layout = layout;
436 }
437 return container;
438}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index de9e7b58..dc0ee5b4 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -6,24 +6,26 @@
6#include <string.h> 6#include <string.h>
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include <wlr/types/wlr_output_layout.h> 8#include <wlr/types/wlr_output_layout.h>
9#include "sway/container.h" 9#include "sway/tree/container.h"
10#include "sway/layout.h" 10#include "sway/tree/layout.h"
11#include "sway/output.h" 11#include "sway/output.h"
12#include "sway/view.h" 12#include "sway/tree/view.h"
13#include "sway/input/seat.h" 13#include "sway/input/seat.h"
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,
20 void *data) {
20 struct wlr_box *layout_box = wlr_output_layout_get_box( 21 struct wlr_box *layout_box = wlr_output_layout_get_box(
21 root_container.sway_root->output_layout, NULL); 22 root_container.sway_root->output_layout, NULL);
22 root_container.width = layout_box->width; 23 root_container.width = layout_box->width;
23 root_container.height = layout_box->height; 24 root_container.height = layout_box->height;
24 25
25 for (int i = 0 ; i < root_container.children->length; ++i) { 26 for (int i = 0 ; i < root_container.children->length; ++i) {
26 swayc_t *output_container = root_container.children->items[i]; 27 struct sway_container *output_container =
28 root_container.children->items[i];
27 if (output_container->type != C_OUTPUT) { 29 if (output_container->type != C_OUTPUT) {
28 continue; 30 continue;
29 } 31 }
@@ -43,7 +45,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data
43 arrange_windows(&root_container, -1, -1); 45 arrange_windows(&root_container, -1, -1);
44} 46}
45 47
46void init_layout(void) { 48void layout_init(void) {
47 root_container.id = 0; // normally assigned in new_swayc() 49 root_container.id = 0; // normally assigned in new_swayc()
48 root_container.type = C_ROOT; 50 root_container.type = C_ROOT;
49 root_container.layout = L_NONE; 51 root_container.layout = L_NONE;
@@ -62,9 +64,9 @@ void init_layout(void) {
62 &root_container.sway_root->output_layout_change); 64 &root_container.sway_root->output_layout_change);
63} 65}
64 66
65static int index_child(const swayc_t *child) { 67static int index_child(const struct sway_container *child) {
66 // TODO handle floating 68 // TODO handle floating
67 swayc_t *parent = child->parent; 69 struct sway_container *parent = child->parent;
68 int i, len; 70 int i, len;
69 len = parent->children->length; 71 len = parent->children->length;
70 for (i = 0; i < len; ++i) { 72 for (i = 0; i < len; ++i) {
@@ -79,16 +81,18 @@ static int index_child(const swayc_t *child) {
79 return i; 81 return i;
80} 82}
81 83
82swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { 84struct sway_container *container_add_sibling(struct sway_container *fixed,
85 struct sway_container *active) {
83 // TODO handle floating 86 // TODO handle floating
84 swayc_t *parent = fixed->parent; 87 struct sway_container *parent = fixed->parent;
85 int i = index_child(fixed); 88 int i = index_child(fixed);
86 list_insert(parent->children, i + 1, active); 89 list_insert(parent->children, i + 1, active);
87 active->parent = parent; 90 active->parent = parent;
88 return active->parent; 91 return active->parent;
89} 92}
90 93
91void add_child(swayc_t *parent, swayc_t *child) { 94void container_add_child(struct sway_container *parent,
95 struct sway_container *child) {
92 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", 96 wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
93 child, child->type, child->width, child->height, 97 child, child->type, child->width, child->height,
94 parent, parent->type, parent->width, parent->height); 98 parent, parent->type, parent->width, parent->height);
@@ -96,15 +100,17 @@ void add_child(swayc_t *parent, swayc_t *child) {
96 child->parent = parent; 100 child->parent = parent;
97 // set focus for this container 101 // set focus for this container
98 /* TODO WLR 102 /* TODO WLR
99 if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { 103 if (parent->type == C_WORKSPACE && child->type == C_VIEW &&
104 (parent->workspace_layout == L_TABBED || parent->workspace_layout ==
105 L_STACKED)) {
100 child = new_container(child, parent->workspace_layout); 106 child = new_container(child, parent->workspace_layout);
101 } 107 }
102 */ 108 */
103} 109}
104 110
105swayc_t *remove_child(swayc_t *child) { 111struct sway_container *container_remove_child(struct sway_container *child) {
106 int i; 112 int i;
107 swayc_t *parent = child->parent; 113 struct sway_container *parent = child->parent;
108 for (i = 0; i < parent->children->length; ++i) { 114 for (i = 0; i < parent->children->length; ++i) {
109 if (parent->children->items[i] == child) { 115 if (parent->children->items[i] == child) {
110 list_del(parent->children, i); 116 list_del(parent->children, i);
@@ -115,7 +121,8 @@ swayc_t *remove_child(swayc_t *child) {
115 return parent; 121 return parent;
116} 122}
117 123
118enum swayc_layouts default_layout(swayc_t *output) { 124enum sway_container_layout container_get_default_layout(
125 struct sway_container *output) {
119 /* TODO WLR 126 /* TODO WLR
120 if (config->default_layout != L_NONE) { 127 if (config->default_layout != L_NONE) {
121 //return config->default_layout; 128 //return config->default_layout;
@@ -129,8 +136,8 @@ enum swayc_layouts default_layout(swayc_t *output) {
129} 136}
130 137
131static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { 138static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
132 swayc_t *a = *(void **)_a; 139 struct sway_container *a = *(void **)_a;
133 swayc_t *b = *(void **)_b; 140 struct sway_container *b = *(void **)_b;
134 int retval = 0; 141 int retval = 0;
135 142
136 if (isdigit(a->name[0]) && isdigit(b->name[0])) { 143 if (isdigit(a->name[0]) && isdigit(b->name[0])) {
@@ -146,21 +153,22 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
146 return retval; 153 return retval;
147} 154}
148 155
149void sort_workspaces(swayc_t *output) { 156void container_sort_workspaces(struct sway_container *output) {
150 list_stable_sort(output->children, sort_workspace_cmp_qsort); 157 list_stable_sort(output->children, sort_workspace_cmp_qsort);
151} 158}
152 159
153static void apply_horiz_layout(swayc_t *container, const double x, 160static void apply_horiz_layout(struct sway_container *container, const double x,
154 const double y, const double width, 161 const double y, const double width,
155 const double height, const int start, 162 const double height, const int start,
156 const int end); 163 const int end);
157 164
158static void apply_vert_layout(swayc_t *container, const double x, 165static void apply_vert_layout(struct sway_container *container, const double x,
159 const double y, const double width, 166 const double y, const double width,
160 const double height, const int start, 167 const double height, const int start,
161 const int end); 168 const int end);
162 169
163void arrange_windows(swayc_t *container, double width, double height) { 170void arrange_windows(struct sway_container *container,
171 double width, double height) {
164 int i; 172 int i;
165 if (width == -1 || height == -1) { 173 if (width == -1 || height == -1) {
166 width = container->width; 174 width = container->width;
@@ -181,7 +189,7 @@ void arrange_windows(swayc_t *container, double width, double height) {
181 case C_ROOT: 189 case C_ROOT:
182 // TODO: wlr_output_layout probably 190 // TODO: wlr_output_layout probably
183 for (i = 0; i < container->children->length; ++i) { 191 for (i = 0; i < container->children->length; ++i) {
184 swayc_t *output = container->children->items[i]; 192 struct sway_container *output = container->children->items[i];
185 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", 193 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
186 output->name, output->x, output->y); 194 output->name, output->x, output->y);
187 arrange_windows(output, -1, -1); 195 arrange_windows(output, -1, -1);
@@ -197,13 +205,14 @@ void arrange_windows(swayc_t *container, double width, double height) {
197 } 205 }
198 // arrange all workspaces: 206 // arrange all workspaces:
199 for (i = 0; i < container->children->length; ++i) { 207 for (i = 0; i < container->children->length; ++i) {
200 swayc_t *child = container->children->items[i]; 208 struct sway_container *child = container->children->items[i];
201 arrange_windows(child, -1, -1); 209 arrange_windows(child, -1, -1);
202 } 210 }
203 return; 211 return;
204 case C_WORKSPACE: 212 case C_WORKSPACE:
205 { 213 {
206 swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); 214 struct sway_container *output =
215 container_parent(container, C_OUTPUT);
207 struct wlr_box *area = &output->sway_output->usable_area; 216 struct wlr_box *area = &output->sway_output->usable_area;
208 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 217 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
209 area->width, area->height, area->x, area->y); 218 area->width, area->height, area->x, area->y);
@@ -252,14 +261,15 @@ void arrange_windows(swayc_t *container, double width, double height) {
252 } 261 }
253} 262}
254 263
255static void apply_horiz_layout(swayc_t *container, 264static void apply_horiz_layout(struct sway_container *container,
256 const double x, const double y, 265 const double x, const double y,
257 const double width, const double height, 266 const double width, const double height,
258 const int start, const int end) { 267 const int start, const int end) {
259 double scale = 0; 268 double scale = 0;
260 // Calculate total width 269 // Calculate total width
261 for (int i = start; i < end; ++i) { 270 for (int i = start; i < end; ++i) {
262 double *old_width = &((swayc_t *)container->children->items[i])->width; 271 double *old_width =
272 &((struct sway_container *)container->children->items[i])->width;
263 if (*old_width <= 0) { 273 if (*old_width <= 0) {
264 if (end - start > 1) { 274 if (end - start > 1) {
265 *old_width = width / (end - start - 1); 275 *old_width = width / (end - start - 1);
@@ -276,7 +286,7 @@ static void apply_horiz_layout(swayc_t *container,
276 if (scale > 0.1) { 286 if (scale > 0.1) {
277 wlr_log(L_DEBUG, "Arranging %p horizontally", container); 287 wlr_log(L_DEBUG, "Arranging %p horizontally", container);
278 for (int i = start; i < end; ++i) { 288 for (int i = start; i < end; ++i) {
279 swayc_t *child = container->children->items[i]; 289 struct sway_container *child = container->children->items[i];
280 wlr_log(L_DEBUG, 290 wlr_log(L_DEBUG,
281 "Calculating arrangement for %p:%d (will scale %f by %f)", 291 "Calculating arrangement for %p:%d (will scale %f by %f)",
282 child, child->type, width, scale); 292 child, child->type, width, scale);
@@ -301,7 +311,7 @@ static void apply_horiz_layout(swayc_t *container,
301 } 311 }
302} 312}
303 313
304void apply_vert_layout(swayc_t *container, 314void apply_vert_layout(struct sway_container *container,
305 const double x, const double y, 315 const double x, const double y,
306 const double width, const double height, const int start, 316 const double width, const double height, const int start,
307 const int end) { 317 const int end) {
@@ -309,7 +319,8 @@ void apply_vert_layout(swayc_t *container,
309 double scale = 0; 319 double scale = 0;
310 // Calculate total height 320 // Calculate total height
311 for (i = start; i < end; ++i) { 321 for (i = start; i < end; ++i) {
312 double *old_height = &((swayc_t *)container->children->items[i])->height; 322 double *old_height =
323 &((struct sway_container *)container->children->items[i])->height;
313 if (*old_height <= 0) { 324 if (*old_height <= 0) {
314 if (end - start > 1) { 325 if (end - start > 1) {
315 *old_height = height / (end - start - 1); 326 *old_height = height / (end - start - 1);
@@ -326,7 +337,7 @@ void apply_vert_layout(swayc_t *container,
326 if (scale > 0.1) { 337 if (scale > 0.1) {
327 wlr_log(L_DEBUG, "Arranging %p vertically", container); 338 wlr_log(L_DEBUG, "Arranging %p vertically", container);
328 for (i = start; i < end; ++i) { 339 for (i = start; i < end; ++i) {
329 swayc_t *child = container->children->items[i]; 340 struct sway_container *child = container->children->items[i];
330 wlr_log(L_DEBUG, 341 wlr_log(L_DEBUG,
331 "Calculating arrangement for %p:%d (will scale %f by %f)", 342 "Calculating arrangement for %p:%d (will scale %f by %f)",
332 child, child->type, height, scale); 343 child, child->type, height, scale);
@@ -354,15 +365,16 @@ void apply_vert_layout(swayc_t *container,
354/** 365/**
355 * Get swayc in the direction of newly entered output. 366 * Get swayc in the direction of newly entered output.
356 */ 367 */
357static swayc_t *get_swayc_in_output_direction(swayc_t *output, 368static struct sway_container *get_swayc_in_output_direction(
358 enum movement_direction dir, struct sway_seat *seat) { 369 struct sway_container *output, enum movement_direction dir,
370 struct sway_seat *seat) {
359 if (!output) { 371 if (!output) {
360 return NULL; 372 return NULL;
361 } 373 }
362 374
363 swayc_t *ws = sway_seat_get_focus_inactive(seat, output); 375 struct sway_container *ws = sway_seat_get_focus_inactive(seat, output);
364 if (ws->type != C_WORKSPACE) { 376 if (ws->type != C_WORKSPACE) {
365 ws = swayc_parent_by_type(ws, C_WORKSPACE); 377 ws = container_parent(ws, C_WORKSPACE);
366 } 378 }
367 379
368 if (ws == NULL) { 380 if (ws == NULL) {
@@ -380,13 +392,15 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output,
380 return ws->children->items[0]; 392 return ws->children->items[0];
381 case MOVE_UP: 393 case MOVE_UP:
382 case MOVE_DOWN: { 394 case MOVE_DOWN: {
383 swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); 395 struct sway_container *focused =
396 sway_seat_get_focus_inactive(seat, ws);
384 if (focused && focused->parent) { 397 if (focused && focused->parent) {
385 swayc_t *parent = focused->parent; 398 struct sway_container *parent = focused->parent;
386 if (parent->layout == L_VERT) { 399 if (parent->layout == L_VERT) {
387 if (dir == MOVE_UP) { 400 if (dir == MOVE_UP) {
388 // get child furthest down on new output 401 // get child furthest down on new output
389 return parent->children->items[parent->children->length-1]; 402 int idx = parent->children->length - 1;
403 return parent->children->items[idx];
390 } else if (dir == MOVE_DOWN) { 404 } else if (dir == MOVE_DOWN) {
391 // get child furthest up on new output 405 // get child furthest up on new output
392 return parent->children->items[0]; 406 return parent->children->items[0];
@@ -404,13 +418,14 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output,
404 return ws; 418 return ws;
405} 419}
406 420
407static void get_layout_center_position(swayc_t *container, int *x, int *y) { 421static void get_layout_center_position(struct sway_container *container,
422 int *x, int *y) {
408 // FIXME view coords are inconsistently referred to in layout/output systems 423 // FIXME view coords are inconsistently referred to in layout/output systems
409 if (container->type == C_OUTPUT) { 424 if (container->type == C_OUTPUT) {
410 *x = container->x + container->width/2; 425 *x = container->x + container->width/2;
411 *y = container->y + container->height/2; 426 *y = container->y + container->height/2;
412 } else { 427 } else {
413 swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); 428 struct sway_container *output = container_parent(container, C_OUTPUT);
414 if (container->type == C_WORKSPACE) { 429 if (container->type == C_WORKSPACE) {
415 // Workspace coordinates are actually wrong/arbitrary, but should 430 // Workspace coordinates are actually wrong/arbitrary, but should
416 // be same as output. 431 // be same as output.
@@ -423,7 +438,8 @@ static void get_layout_center_position(swayc_t *container, int *x, int *y) {
423 } 438 }
424} 439}
425 440
426static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { 441static bool sway_dir_to_wlr(enum movement_direction dir,
442 enum wlr_direction *out) {
427 switch (dir) { 443 switch (dir) {
428 case MOVE_UP: 444 case MOVE_UP:
429 *out = WLR_DIRECTION_UP; 445 *out = WLR_DIRECTION_UP;
@@ -444,12 +460,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out
444 return true; 460 return true;
445} 461}
446 462
447static swayc_t *sway_output_from_wlr(struct wlr_output *output) { 463static struct sway_container *sway_output_from_wlr(struct wlr_output *output) {
448 if (output == NULL) { 464 if (output == NULL) {
449 return NULL; 465 return NULL;
450 } 466 }
451 for (int i = 0; i < root_container.children->length; ++i) { 467 for (int i = 0; i < root_container.children->length; ++i) {
452 swayc_t *o = root_container.children->items[i]; 468 struct sway_container *o = root_container.children->items[i];
453 if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { 469 if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) {
454 return o; 470 return o;
455 } 471 }
@@ -457,13 +473,14 @@ static swayc_t *sway_output_from_wlr(struct wlr_output *output) {
457 return NULL; 473 return NULL;
458} 474}
459 475
460static swayc_t *get_swayc_in_direction_under(swayc_t *container, 476static struct sway_container *get_swayc_in_direction_under(
461 enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { 477 struct sway_container *container, enum movement_direction dir,
478 struct sway_seat *seat, struct sway_container *limit) {
462 if (dir == MOVE_CHILD) { 479 if (dir == MOVE_CHILD) {
463 return sway_seat_get_focus_inactive(seat, container); 480 return sway_seat_get_focus_inactive(seat, container);
464 } 481 }
465 482
466 swayc_t *parent = container->parent; 483 struct sway_container *parent = container->parent;
467 if (dir == MOVE_PARENT) { 484 if (dir == MOVE_PARENT) {
468 if (parent->type == C_OUTPUT) { 485 if (parent->type == C_OUTPUT) {
469 return NULL; 486 return NULL;
@@ -496,9 +513,10 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
496 /* 513 /*
497 if (container->type == C_VIEW && swayc_is_fullscreen(container)) { 514 if (container->type == C_VIEW && swayc_is_fullscreen(container)) {
498 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); 515 wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
499 container = swayc_parent_by_type(container, C_OUTPUT); 516 container = container_parent(container, C_OUTPUT);
500 get_layout_center_position(container, &abs_pos); 517 get_layout_center_position(container, &abs_pos);
501 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); 518 struct sway_container *output =
519 swayc_adjacent_output(container, dir, &abs_pos, true);
502 return get_swayc_in_output_direction(output, dir); 520 return get_swayc_in_output_direction(output, dir);
503 } 521 }
504 if (container->type == C_WORKSPACE && container->fullscreen) { 522 if (container->type == C_WORKSPACE && container->fullscreen) {
@@ -507,7 +525,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
507 } 525 }
508 */ 526 */
509 527
510 swayc_t *wrap_candidate = NULL; 528 struct sway_container *wrap_candidate = NULL;
511 while (true) { 529 while (true) {
512 // Test if we can even make a difference here 530 // Test if we can even make a difference here
513 bool can_move = false; 531 bool can_move = false;
@@ -521,16 +539,19 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
521 } 539 }
522 int lx, ly; 540 int lx, ly;
523 get_layout_center_position(container, &lx, &ly); 541 get_layout_center_position(container, &lx, &ly);
524 struct wlr_output_layout *layout = root_container.sway_root->output_layout; 542 struct wlr_output_layout *layout =
543 root_container.sway_root->output_layout;
525 struct wlr_output *wlr_adjacent = 544 struct wlr_output *wlr_adjacent =
526 wlr_output_layout_adjacent_output(layout, wlr_dir, 545 wlr_output_layout_adjacent_output(layout, wlr_dir,
527 container->sway_output->wlr_output, lx, ly); 546 container->sway_output->wlr_output, lx, ly);
528 swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); 547 struct sway_container *adjacent =
548 sway_output_from_wlr(wlr_adjacent);
529 549
530 if (!adjacent || adjacent == container) { 550 if (!adjacent || adjacent == container) {
531 return wrap_candidate; 551 return wrap_candidate;
532 } 552 }
533 swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); 553 struct sway_container *next =
554 get_swayc_in_output_direction(adjacent, dir, seat);
534 if (next == NULL) { 555 if (next == NULL) {
535 return NULL; 556 return NULL;
536 } 557 }
@@ -570,8 +591,9 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
570 } 591 }
571 } 592 }
572 } else { 593 } else {
573 wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, 594 wlr_log(L_DEBUG,
574 idx, container, dir, desired, parent->children->items[desired]); 595 "cont %d-%p dir %i sibling %d: %p", idx,
596 container, dir, desired, parent->children->items[desired]);
575 return parent->children->items[desired]; 597 return parent->children->items[desired];
576 } 598 }
577 } 599 }
@@ -587,7 +609,8 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container,
587 } 609 }
588} 610}
589 611
590swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, 612struct sway_container *container_get_in_direction(
613 struct sway_container *container, struct sway_seat *seat,
591 enum movement_direction dir) { 614 enum movement_direction dir) {
592 return get_swayc_in_direction_under(container, dir, seat, NULL); 615 return get_swayc_in_direction_under(container, dir, seat, NULL);
593} 616}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 9499adca..d5325c31 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -1,8 +1,8 @@
1#include <wayland-server.h> 1#include <wayland-server.h>
2#include <wlr/types/wlr_output_layout.h> 2#include <wlr/types/wlr_output_layout.h>
3#include "sway/container.h" 3#include "sway/tree/container.h"
4#include "sway/layout.h" 4#include "sway/tree/layout.h"
5#include "sway/view.h" 5#include "sway/tree/view.h"
6 6
7const char *view_get_title(struct sway_view *view) { 7const char *view_get_title(struct sway_view *view) {
8 if (view->iface.get_prop) { 8 if (view->iface.get_prop) {
@@ -45,6 +45,7 @@ void view_set_size(struct sway_view *view, int width, int height) {
45 } 45 }
46} 46}
47 47
48// TODO make view coordinates in layout coordinates
48void view_set_position(struct sway_view *view, double ox, double oy) { 49void view_set_position(struct sway_view *view, double ox, double oy) {
49 if (view->iface.set_position) { 50 if (view->iface.set_position) {
50 struct wlr_box box = { 51 struct wlr_box box = {
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 861fda4d..ba04c55c 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -3,10 +3,10 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <strings.h> 5#include <strings.h>
6#include "sway/container.h" 6#include "sway/tree/container.h"
7#include "sway/input/input-manager.h" 7#include "sway/input/input-manager.h"
8#include "sway/input/seat.h" 8#include "sway/input/seat.h"
9#include "sway/workspace.h" 9#include "sway/tree/workspace.h"
10#include "log.h" 10#include "log.h"
11#include "util.h" 11#include "util.h"
12 12
@@ -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,28 @@ 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 container_find(&root_container,
56 _workspace_by_number, (void *) &wbnd);
56} 57}
57 58
58static bool _workspace_by_name(swayc_t *view, void *data) { 59static bool _workspace_by_name(struct sway_container *view, void *data) {
59 return (view->type == C_WORKSPACE) && 60 return (view->type == C_WORKSPACE) &&
60 (strcasecmp(view->name, (char *) data) == 0); 61 (strcasecmp(view->name, (char *) data) == 0);
61} 62}
62 63
63swayc_t *workspace_by_name(const char *name) { 64struct sway_container *workspace_by_name(const char *name) {
64 struct sway_seat *seat = input_manager_current_seat(input_manager); 65 struct sway_seat *seat = input_manager_current_seat(input_manager);
65 swayc_t *current_workspace = NULL, *current_output = NULL; 66 struct sway_container *current_workspace = NULL, *current_output = NULL;
66 swayc_t *focus = sway_seat_get_focus(seat); 67 struct sway_container *focus = sway_seat_get_focus(seat);
67 if (focus) { 68 if (focus) {
68 current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); 69 current_workspace = container_parent(focus, C_WORKSPACE);
69 current_output = swayc_parent_by_type(focus, C_OUTPUT); 70 current_output = container_parent(focus, C_OUTPUT);
70 } 71 }
71 if (strcmp(name, "prev") == 0) { 72 if (strcmp(name, "prev") == 0) {
72 return workspace_prev(current_workspace); 73 return workspace_prev(current_workspace);
@@ -79,12 +80,13 @@ swayc_t *workspace_by_name(const char *name) {
79 } else if (strcmp(name, "current") == 0) { 80 } else if (strcmp(name, "current") == 0) {
80 return current_workspace; 81 return current_workspace;
81 } else { 82 } else {
82 return swayc_by_test(&root_container, _workspace_by_name, (void *) name); 83 return container_find(&root_container, _workspace_by_name,
84 (void *)name);
83 } 85 }
84} 86}
85 87
86swayc_t *workspace_create(const char *name) { 88struct sway_container *workspace_create(const char *name) {
87 swayc_t *parent; 89 struct sway_container *parent;
88 // Search for workspace<->output pair 90 // Search for workspace<->output pair
89 int i, e = config->workspace_outputs->length; 91 int i, e = config->workspace_outputs->length;
90 for (i = 0; i < e; ++i) { 92 for (i = 0; i < e; ++i) {
@@ -95,7 +97,7 @@ swayc_t *workspace_create(const char *name) {
95 for (i = 0; i < e; ++i) { 97 for (i = 0; i < e; ++i) {
96 parent = root_container.children->items[i]; 98 parent = root_container.children->items[i];
97 if (strcmp(parent->name, wso->output) == 0) { 99 if (strcmp(parent->name, wso->output) == 0) {
98 return new_workspace(parent, name); 100 return container_workspace_create(parent, name);
99 } 101 }
100 } 102 }
101 break; 103 break;
@@ -103,10 +105,11 @@ swayc_t *workspace_create(const char *name) {
103 } 105 }
104 // Otherwise create a new one 106 // Otherwise create a new one
105 struct sway_seat *seat = input_manager_current_seat(input_manager); 107 struct sway_seat *seat = input_manager_current_seat(input_manager);
106 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 108 struct sway_container *focus =
109 sway_seat_get_focus_inactive(seat, &root_container);
107 parent = focus; 110 parent = focus;
108 parent = swayc_parent_by_type(parent, C_OUTPUT); 111 parent = container_parent(parent, C_OUTPUT);
109 return new_workspace(parent, name); 112 return container_workspace_create(parent, name);
110} 113}
111 114
112/** 115/**
@@ -114,17 +117,18 @@ swayc_t *workspace_create(const char *name) {
114 * the end and beginning. If next is false, the previous workspace is returned, 117 * the end and beginning. If next is false, the previous workspace is returned,
115 * otherwise the next one is returned. 118 * otherwise the next one is returned.
116 */ 119 */
117swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { 120struct sway_container *workspace_output_prev_next_impl(
121 struct sway_container *output, bool next) {
118 if (!sway_assert(output->type == C_OUTPUT, 122 if (!sway_assert(output->type == C_OUTPUT,
119 "Argument must be an output, is %d", output->type)) { 123 "Argument must be an output, is %d", output->type)) {
120 return NULL; 124 return NULL;
121 } 125 }
122 126
123 struct sway_seat *seat = input_manager_current_seat(input_manager); 127 struct sway_seat *seat = input_manager_current_seat(input_manager);
124 swayc_t *focus = sway_seat_get_focus_inactive(seat, output); 128 struct sway_container *focus = sway_seat_get_focus_inactive(seat, output);
125 swayc_t *workspace = (focus->type == C_WORKSPACE ? 129 struct sway_container *workspace = (focus->type == C_WORKSPACE ?
126 focus : 130 focus :
127 swayc_parent_by_type(focus, C_WORKSPACE)); 131 container_parent(focus, C_WORKSPACE));
128 132
129 int i; 133 int i;
130 for (i = 0; i < output->children->length; i++) { 134 for (i = 0; i < output->children->length; i++) {
@@ -134,7 +138,8 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
134 } 138 }
135 } 139 }
136 140
137 // Doesn't happen, at worst the for loop returns the previously active workspace 141 // Doesn't happen, at worst the for loop returns the previously active
142 // workspace
138 return NULL; 143 return NULL;
139} 144}
140 145
@@ -144,13 +149,14 @@ 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 149 * next is false, the previous workspace is returned, otherwise the next one is
145 * returned. 150 * returned.
146 */ 151 */
147swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { 152struct sway_container *workspace_prev_next_impl(
153 struct sway_container *workspace, bool next) {
148 if (!sway_assert(workspace->type == C_WORKSPACE, 154 if (!sway_assert(workspace->type == C_WORKSPACE,
149 "Argument must be a workspace, is %d", workspace->type)) { 155 "Argument must be a workspace, is %d", workspace->type)) {
150 return NULL; 156 return NULL;
151 } 157 }
152 158
153 swayc_t *current_output = workspace->parent; 159 struct sway_container *current_output = workspace->parent;
154 int offset = next ? 1 : -1; 160 int offset = next ? 1 : -1;
155 int start = next ? 0 : 1; 161 int start = next ? 0 : 1;
156 int end; 162 int end;
@@ -166,54 +172,57 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
166 } 172 }
167 } 173 }
168 174
169 // Given workspace is the first/last on the output, jump to the previous/next output 175 // Given workspace is the first/last on the output, jump to the
176 // previous/next output
170 int num_outputs = root_container.children->length; 177 int num_outputs = root_container.children->length;
171 for (i = 0; i < num_outputs; i++) { 178 for (i = 0; i < num_outputs; i++) {
172 if (root_container.children->items[i] == current_output) { 179 if (root_container.children->items[i] == current_output) {
173 swayc_t *next_output = root_container.children->items[ 180 struct sway_container *next_output = root_container.children->items[
174 wrap(i + offset, num_outputs)]; 181 wrap(i + offset, num_outputs)];
175 return workspace_output_prev_next_impl(next_output, next); 182 return workspace_output_prev_next_impl(next_output, next);
176 } 183 }
177 } 184 }
178 185
179 // Doesn't happen, at worst the for loop returns the previously active workspace on the active output 186 // Doesn't happen, at worst the for loop returns the previously active
187 // workspace on the active output
180 return NULL; 188 return NULL;
181} 189}
182 190
183swayc_t *workspace_output_next(swayc_t *current) { 191struct sway_container *workspace_output_next(struct sway_container *current) {
184 return workspace_output_prev_next_impl(current, true); 192 return workspace_output_prev_next_impl(current, true);
185} 193}
186 194
187swayc_t *workspace_next(swayc_t *current) { 195struct sway_container *workspace_next(struct sway_container *current) {
188 return workspace_prev_next_impl(current, true); 196 return workspace_prev_next_impl(current, true);
189} 197}
190 198
191swayc_t *workspace_output_prev(swayc_t *current) { 199struct sway_container *workspace_output_prev(struct sway_container *current) {
192 return workspace_output_prev_next_impl(current, false); 200 return workspace_output_prev_next_impl(current, false);
193} 201}
194 202
195swayc_t *workspace_prev(swayc_t *current) { 203struct sway_container *workspace_prev(struct sway_container *current) {
196 return workspace_prev_next_impl(current, false); 204 return workspace_prev_next_impl(current, false);
197} 205}
198 206
199bool workspace_switch(swayc_t *workspace) { 207bool workspace_switch(struct sway_container *workspace) {
200 if (!workspace) { 208 if (!workspace) {
201 return false; 209 return false;
202 } 210 }
203 struct sway_seat *seat = input_manager_current_seat(input_manager); 211 struct sway_seat *seat = input_manager_current_seat(input_manager);
204 swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); 212 struct sway_container *focus =
213 sway_seat_get_focus_inactive(seat, &root_container);
205 if (!seat || !focus) { 214 if (!seat || !focus) {
206 return false; 215 return false;
207 } 216 }
208 swayc_t *active_ws = focus; 217 struct sway_container *active_ws = focus;
209 if (active_ws->type != C_WORKSPACE) { 218 if (active_ws->type != C_WORKSPACE) {
210 swayc_parent_by_type(focus, C_WORKSPACE); 219 container_parent(focus, C_WORKSPACE);
211 } 220 }
212 221
213 if (config->auto_back_and_forth 222 if (config->auto_back_and_forth
214 && active_ws == workspace 223 && active_ws == workspace
215 && prev_workspace_name) { 224 && prev_workspace_name) {
216 swayc_t *new_ws = workspace_by_name(prev_workspace_name); 225 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
217 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); 226 workspace = new_ws ? new_ws : workspace_create(prev_workspace_name);
218 } 227 }
219 228
@@ -230,13 +239,14 @@ bool workspace_switch(swayc_t *workspace) {
230 239
231 // TODO: Deal with sticky containers 240 // TODO: Deal with sticky containers
232 241
233 wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); 242 wlr_log(L_DEBUG, "Switching to workspace %p:%s",
234 swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); 243 workspace, workspace->name);
244 struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace);
235 if (next == NULL) { 245 if (next == NULL) {
236 next = workspace; 246 next = workspace;
237 } 247 }
238 sway_seat_set_focus(seat, next); 248 sway_seat_set_focus(seat, next);
239 swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); 249 struct sway_container *output = container_parent(workspace, C_OUTPUT);
240 arrange_windows(output, -1, -1); 250 arrange_windows(output, -1, -1);
241 return true; 251 return true;
242} 252}