diff options
41 files changed, 569 insertions, 540 deletions
diff --git a/common/util.c b/common/util.c index 467aa4b5..561b3804 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -175,3 +175,24 @@ failed: | |||
175 | free(current); | 175 | free(current); |
176 | return NULL; | 176 | return NULL; |
177 | } | 177 | } |
178 | |||
179 | bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { | ||
180 | switch (dir) { | ||
181 | case MOVE_UP: | ||
182 | *out = WLR_DIRECTION_UP; | ||
183 | break; | ||
184 | case MOVE_DOWN: | ||
185 | *out = WLR_DIRECTION_DOWN; | ||
186 | break; | ||
187 | case MOVE_LEFT: | ||
188 | *out = WLR_DIRECTION_LEFT; | ||
189 | break; | ||
190 | case MOVE_RIGHT: | ||
191 | *out = WLR_DIRECTION_RIGHT; | ||
192 | break; | ||
193 | default: | ||
194 | return false; | ||
195 | } | ||
196 | |||
197 | return true; | ||
198 | } | ||
diff --git a/include/sway/config.h b/include/sway/config.h index c2eaea1b..18d10faa 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -8,8 +8,8 @@ | |||
8 | #include <xkbcommon/xkbcommon.h> | 8 | #include <xkbcommon/xkbcommon.h> |
9 | #include "list.h" | 9 | #include "list.h" |
10 | #include "swaynag.h" | 10 | #include "swaynag.h" |
11 | #include "tree/layout.h" | ||
12 | #include "tree/container.h" | 11 | #include "tree/container.h" |
12 | #include "sway/tree/root.h" | ||
13 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 13 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
14 | 14 | ||
15 | // TODO: Refactor this shit | 15 | // TODO: Refactor this shit |
diff --git a/include/sway/tree/arrange.h b/include/sway/tree/arrange.h index d6abcc81..346103d3 100644 --- a/include/sway/tree/arrange.h +++ b/include/sway/tree/arrange.h | |||
@@ -4,12 +4,6 @@ | |||
4 | 4 | ||
5 | struct sway_container; | 5 | struct sway_container; |
6 | 6 | ||
7 | // Remove gaps around container | ||
8 | void remove_gaps(struct sway_container *c); | ||
9 | |||
10 | // Add gaps around container | ||
11 | void add_gaps(struct sway_container *c); | ||
12 | |||
13 | /** | 7 | /** |
14 | * Arrange layout for all the children of the given container. | 8 | * Arrange layout for all the children of the given container. |
15 | */ | 9 | */ |
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 2cedb613..e4071cfe 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -53,6 +53,9 @@ struct sway_output; | |||
53 | struct sway_workspace; | 53 | struct sway_workspace; |
54 | struct sway_view; | 54 | struct sway_view; |
55 | 55 | ||
56 | enum movement_direction; | ||
57 | enum wlr_direction; | ||
58 | |||
56 | struct sway_container_state { | 59 | struct sway_container_state { |
57 | // Container/swayc properties | 60 | // Container/swayc properties |
58 | enum sway_container_layout layout; | 61 | enum sway_container_layout layout; |
@@ -335,6 +338,35 @@ struct sway_output *container_get_effective_output(struct sway_container *con); | |||
335 | 338 | ||
336 | void container_discover_outputs(struct sway_container *con); | 339 | void container_discover_outputs(struct sway_container *con); |
337 | 340 | ||
341 | void container_remove_gaps(struct sway_container *container); | ||
342 | |||
343 | void container_add_gaps(struct sway_container *container); | ||
344 | |||
338 | int container_sibling_index(const struct sway_container *child); | 345 | int container_sibling_index(const struct sway_container *child); |
339 | 346 | ||
347 | void container_handle_fullscreen_reparent(struct sway_container *con, | ||
348 | struct sway_container *old_parent); | ||
349 | |||
350 | void container_add_child(struct sway_container *parent, | ||
351 | struct sway_container *child); | ||
352 | |||
353 | void container_insert_child(struct sway_container *parent, | ||
354 | struct sway_container *child, int i); | ||
355 | |||
356 | struct sway_container *container_add_sibling(struct sway_container *parent, | ||
357 | struct sway_container *child); | ||
358 | |||
359 | struct sway_container *container_remove_child(struct sway_container *child); | ||
360 | |||
361 | struct sway_container *container_replace_child(struct sway_container *child, | ||
362 | struct sway_container *new_child); | ||
363 | |||
364 | bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out); | ||
365 | |||
366 | enum sway_container_layout container_get_default_layout( | ||
367 | struct sway_container *con); | ||
368 | |||
369 | struct sway_container *container_split(struct sway_container *child, | ||
370 | enum sway_container_layout layout); | ||
371 | |||
340 | #endif | 372 | #endif |
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h deleted file mode 100644 index 5c834ad2..00000000 --- a/include/sway/tree/layout.h +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | ||
2 | #define _SWAY_LAYOUT_H | ||
3 | #include <wlr/types/wlr_output_layout.h> | ||
4 | #include <wlr/render/wlr_texture.h> | ||
5 | #include "sway/tree/container.h" | ||
6 | #include "sway/tree/root.h" | ||
7 | #include "config.h" | ||
8 | |||
9 | enum movement_direction { | ||
10 | MOVE_LEFT, | ||
11 | MOVE_RIGHT, | ||
12 | MOVE_UP, | ||
13 | MOVE_DOWN, | ||
14 | MOVE_PARENT, | ||
15 | MOVE_CHILD, | ||
16 | }; | ||
17 | |||
18 | enum wlr_edges; | ||
19 | |||
20 | struct sway_container; | ||
21 | |||
22 | void container_handle_fullscreen_reparent(struct sway_container *con, | ||
23 | struct sway_container *old_parent); | ||
24 | |||
25 | void container_add_child(struct sway_container *parent, | ||
26 | struct sway_container *child); | ||
27 | |||
28 | void container_insert_child(struct sway_container *parent, | ||
29 | struct sway_container *child, int i); | ||
30 | |||
31 | struct sway_container *container_add_sibling(struct sway_container *parent, | ||
32 | struct sway_container *child); | ||
33 | |||
34 | struct sway_container *container_remove_child(struct sway_container *child); | ||
35 | |||
36 | struct sway_container *container_replace_child(struct sway_container *child, | ||
37 | struct sway_container *new_child); | ||
38 | |||
39 | bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out); | ||
40 | |||
41 | enum sway_container_layout container_get_default_layout( | ||
42 | struct sway_container *con); | ||
43 | |||
44 | struct sway_container *container_split(struct sway_container *child, | ||
45 | enum sway_container_layout layout); | ||
46 | |||
47 | void container_recursive_resize(struct sway_container *container, | ||
48 | double amount, enum wlr_edges edge); | ||
49 | |||
50 | void container_swap(struct sway_container *con1, struct sway_container *con2); | ||
51 | |||
52 | #endif | ||
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index efcb7c69..04325919 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -75,4 +75,8 @@ struct sway_container *workspace_wrap_children(struct sway_container *ws); | |||
75 | void workspace_add_floating(struct sway_container *workspace, | 75 | void workspace_add_floating(struct sway_container *workspace, |
76 | struct sway_container *con); | 76 | struct sway_container *con); |
77 | 77 | ||
78 | void workspace_remove_gaps(struct sway_container *ws); | ||
79 | |||
80 | void workspace_add_gaps(struct sway_container *ws); | ||
81 | |||
78 | #endif | 82 | #endif |
diff --git a/include/util.h b/include/util.h index 9277fa6e..46ed1533 100644 --- a/include/util.h +++ b/include/util.h | |||
@@ -4,9 +4,19 @@ | |||
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <wlr/types/wlr_output_layout.h> | ||
8 | #include <xkbcommon/xkbcommon.h> | 9 | #include <xkbcommon/xkbcommon.h> |
9 | 10 | ||
11 | enum movement_direction { | ||
12 | MOVE_LEFT, | ||
13 | MOVE_RIGHT, | ||
14 | MOVE_UP, | ||
15 | MOVE_DOWN, | ||
16 | MOVE_PARENT, | ||
17 | MOVE_CHILD, | ||
18 | }; | ||
19 | |||
10 | /** | 20 | /** |
11 | * Wrap i into the range [0, max[ | 21 | * Wrap i into the range [0, max[ |
12 | */ | 22 | */ |
@@ -71,4 +81,6 @@ char* resolve_path(const char* path); | |||
71 | char *b64_encode(const char* binaryData, size_t len, size_t *flen); | 81 | char *b64_encode(const char* binaryData, size_t len, size_t *flen); |
72 | unsigned char *b64_decode(const char *ascii, size_t len, size_t *flen); | 82 | unsigned char *b64_decode(const char *ascii, size_t len, size_t *flen); |
73 | 83 | ||
84 | bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out); | ||
85 | |||
74 | #endif | 86 | #endif |
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 5ce7919b..bc07c2aa 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "sway/commands.h" | 8 | #include "sway/commands.h" |
9 | #include "sway/config.h" | 9 | #include "sway/config.h" |
10 | #include "sway/tree/container.h" | 10 | #include "sway/tree/container.h" |
11 | #include "sway/tree/root.h" | ||
11 | #include "sway/tree/workspace.h" | 12 | #include "sway/tree/workspace.h" |
12 | #include "log.h" | 13 | #include "log.h" |
13 | #include "stringop.h" | 14 | #include "stringop.h" |
diff --git a/sway/commands/floating.c b/sway/commands/floating.c index beafd9fb..436376e3 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c | |||
@@ -6,7 +6,6 @@ | |||
6 | #include "sway/output.h" | 6 | #include "sway/output.h" |
7 | #include "sway/tree/arrange.h" | 7 | #include "sway/tree/arrange.h" |
8 | #include "sway/tree/container.h" | 8 | #include "sway/tree/container.h" |
9 | #include "sway/tree/layout.h" | ||
10 | #include "sway/tree/view.h" | 9 | #include "sway/tree/view.h" |
11 | #include "sway/tree/workspace.h" | 10 | #include "sway/tree/workspace.h" |
12 | #include "list.h" | 11 | #include "list.h" |
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index a9fa9a0f..f342e524 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -6,9 +6,11 @@ | |||
6 | #include "sway/input/seat.h" | 6 | #include "sway/input/seat.h" |
7 | #include "sway/output.h" | 7 | #include "sway/output.h" |
8 | #include "sway/tree/arrange.h" | 8 | #include "sway/tree/arrange.h" |
9 | #include "sway/tree/root.h" | ||
9 | #include "sway/tree/view.h" | 10 | #include "sway/tree/view.h" |
10 | #include "sway/tree/workspace.h" | 11 | #include "sway/tree/workspace.h" |
11 | #include "stringop.h" | 12 | #include "stringop.h" |
13 | #include "util.h" | ||
12 | 14 | ||
13 | static bool parse_movement_direction(const char *name, | 15 | static bool parse_movement_direction(const char *name, |
14 | enum movement_direction *out) { | 16 | enum movement_direction *out) { |
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c index a0661200..ac65dffb 100644 --- a/sway/commands/fullscreen.c +++ b/sway/commands/fullscreen.c | |||
@@ -5,7 +5,6 @@ | |||
5 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
6 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/tree/workspace.h" | 7 | #include "sway/tree/workspace.h" |
8 | #include "sway/tree/layout.h" | ||
9 | #include "util.h" | 8 | #include "util.h" |
10 | 9 | ||
11 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { | 10 | struct cmd_results *cmd_fullscreen(int argc, char **argv) { |
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index d59c9fdb..e494f6aa 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "sway/commands.h" | 1 | #include "sway/commands.h" |
2 | #include "sway/config.h" | 2 | #include "sway/config.h" |
3 | #include "sway/tree/container.h" | 3 | #include "sway/tree/container.h" |
4 | #include "sway/tree/root.h" | ||
4 | #include "sway/tree/view.h" | 5 | #include "sway/tree/view.h" |
5 | 6 | ||
6 | static void _configure_view(struct sway_container *con, void *data) { | 7 | static void _configure_view(struct sway_container *con, void *data) { |
diff --git a/sway/commands/move.c b/sway/commands/move.c index a4eedf7f..d0f6b9ea 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "stringop.h" | 19 | #include "stringop.h" |
20 | #include "list.h" | 20 | #include "list.h" |
21 | #include "log.h" | 21 | #include "log.h" |
22 | #include "util.h" | ||
22 | 23 | ||
23 | static const char *expected_syntax = | 24 | static const char *expected_syntax = |
24 | "Expected 'move <left|right|up|down> <[px] px>' or " | 25 | "Expected 'move <left|right|up|down> <[px] px>' or " |
@@ -26,7 +27,20 @@ static const char *expected_syntax = | |||
26 | "'move <container|window|workspace> [to] output <name|direction>' or " | 27 | "'move <container|window|workspace> [to] output <name|direction>' or " |
27 | "'move <container|window> [to] mark <mark>'"; | 28 | "'move <container|window> [to] mark <mark>'"; |
28 | 29 | ||
29 | static struct sway_container *output_in_direction(const char *direction, | 30 | enum wlr_direction opposite_direction(enum wlr_direction d) { |
31 | switch (d) { | ||
32 | case WLR_DIRECTION_UP: | ||
33 | return WLR_DIRECTION_DOWN; | ||
34 | case WLR_DIRECTION_DOWN: | ||
35 | return WLR_DIRECTION_UP; | ||
36 | case WLR_DIRECTION_RIGHT: | ||
37 | return WLR_DIRECTION_LEFT; | ||
38 | default: | ||
39 | return WLR_DIRECTION_RIGHT; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | static struct sway_container *output_in_direction(const char *direction_string, | ||
30 | struct wlr_output *reference, int ref_lx, int ref_ly) { | 44 | struct wlr_output *reference, int ref_lx, int ref_ly) { |
31 | struct { | 45 | struct { |
32 | char *name; | 46 | char *name; |
@@ -37,19 +51,34 @@ static struct sway_container *output_in_direction(const char *direction, | |||
37 | { "left", WLR_DIRECTION_LEFT }, | 51 | { "left", WLR_DIRECTION_LEFT }, |
38 | { "right", WLR_DIRECTION_RIGHT }, | 52 | { "right", WLR_DIRECTION_RIGHT }, |
39 | }; | 53 | }; |
54 | |||
55 | enum wlr_direction direction; | ||
56 | |||
40 | for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) { | 57 | for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) { |
41 | if (strcasecmp(names[i].name, direction) == 0) { | 58 | if (strcasecmp(names[i].name, direction_string) == 0) { |
42 | struct wlr_output *adjacent = wlr_output_layout_adjacent_output( | 59 | direction = names[i].direction; |
43 | root_container.sway_root->output_layout, | ||
44 | names[i].direction, reference, ref_lx, ref_ly); | ||
45 | if (adjacent) { | ||
46 | struct sway_output *sway_output = adjacent->data; | ||
47 | return sway_output->swayc; | ||
48 | } | ||
49 | break; | 60 | break; |
50 | } | 61 | } |
51 | } | 62 | } |
52 | return output_by_name(direction); | 63 | |
64 | if (direction) { | ||
65 | struct wlr_output *target = wlr_output_layout_adjacent_output( | ||
66 | root_container.sway_root->output_layout, | ||
67 | direction, reference, ref_lx, ref_ly); | ||
68 | |||
69 | if (!target) { | ||
70 | target = wlr_output_layout_farthest_output( | ||
71 | root_container.sway_root->output_layout, | ||
72 | opposite_direction(direction), reference, ref_lx, ref_ly); | ||
73 | } | ||
74 | |||
75 | if (target) { | ||
76 | struct sway_output *sway_output = target->data; | ||
77 | return sway_output->swayc; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | return output_by_name(direction_string); | ||
53 | } | 82 | } |
54 | 83 | ||
55 | static void container_move_to(struct sway_container *container, | 84 | static void container_move_to(struct sway_container *container, |
diff --git a/sway/commands/output.c b/sway/commands/output.c index ef1b7a69..00910843 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -1,7 +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/output.h" | 3 | #include "sway/output.h" |
4 | #include "sway/tree/layout.h" | ||
5 | #include "list.h" | 4 | #include "list.h" |
6 | #include "log.h" | 5 | #include "log.h" |
7 | 6 | ||
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index ea1e36ff..ad659ef5 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -159,6 +159,27 @@ static int parallel_size(struct sway_container *c, enum resize_axis a) { | |||
159 | return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->width : c->height; | 159 | return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->width : c->height; |
160 | } | 160 | } |
161 | 161 | ||
162 | static void container_recursive_resize(struct sway_container *container, | ||
163 | double amount, enum wlr_edges edge) { | ||
164 | bool layout_match = true; | ||
165 | wlr_log(WLR_DEBUG, "Resizing %p with amount: %f", container, amount); | ||
166 | if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) { | ||
167 | container->width += amount; | ||
168 | layout_match = container->layout == L_HORIZ; | ||
169 | } else if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) { | ||
170 | container->height += amount; | ||
171 | layout_match = container->layout == L_VERT; | ||
172 | } | ||
173 | if (container->children) { | ||
174 | for (int i = 0; i < container->children->length; i++) { | ||
175 | struct sway_container *child = container->children->items[i]; | ||
176 | double amt = layout_match ? | ||
177 | amount / container->children->length : amount; | ||
178 | container_recursive_resize(child, amt, edge); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
162 | static void resize_tiled(struct sway_container *parent, int amount, | 183 | static void resize_tiled(struct sway_container *parent, int amount, |
163 | enum resize_axis axis) { | 184 | enum resize_axis axis) { |
164 | struct sway_container *focused = parent; | 185 | struct sway_container *focused = parent; |
diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c index dd7d170c..1844e917 100644 --- a/sway/commands/show_marks.c +++ b/sway/commands/show_marks.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
4 | #include "sway/config.h" | 4 | #include "sway/config.h" |
5 | #include "sway/tree/root.h" | ||
5 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
6 | #include "sway/output.h" | 7 | #include "sway/output.h" |
7 | #include "list.h" | 8 | #include "list.h" |
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c index 72ef4282..8692e08d 100644 --- a/sway/commands/sticky.c +++ b/sway/commands/sticky.c | |||
@@ -6,7 +6,6 @@ | |||
6 | #include "sway/output.h" | 6 | #include "sway/output.h" |
7 | #include "sway/tree/arrange.h" | 7 | #include "sway/tree/arrange.h" |
8 | #include "sway/tree/container.h" | 8 | #include "sway/tree/container.h" |
9 | #include "sway/tree/layout.h" | ||
10 | #include "sway/tree/view.h" | 9 | #include "sway/tree/view.h" |
11 | #include "sway/tree/workspace.h" | 10 | #include "sway/tree/workspace.h" |
12 | #include "list.h" | 11 | #include "list.h" |
diff --git a/sway/commands/swap.c b/sway/commands/swap.c index f881a002..f25c43a1 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c | |||
@@ -1,15 +1,141 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
1 | #include <strings.h> | 2 | #include <strings.h> |
2 | #include <wlr/util/log.h> | 3 | #include <wlr/util/log.h> |
3 | #include "config.h" | 4 | #include "config.h" |
5 | #include "log.h" | ||
4 | #include "sway/commands.h" | 6 | #include "sway/commands.h" |
5 | #include "sway/tree/arrange.h" | 7 | #include "sway/tree/arrange.h" |
6 | #include "sway/tree/layout.h" | 8 | #include "sway/tree/root.h" |
7 | #include "sway/tree/view.h" | 9 | #include "sway/tree/view.h" |
10 | #include "sway/tree/workspace.h" | ||
8 | #include "stringop.h" | 11 | #include "stringop.h" |
9 | 12 | ||
10 | static const char* EXPECTED_SYNTAX = | 13 | static const char* EXPECTED_SYNTAX = |
11 | "Expected 'swap container with id|con_id|mark <arg>'"; | 14 | "Expected 'swap container with id|con_id|mark <arg>'"; |
12 | 15 | ||
16 | static void swap_places(struct sway_container *con1, | ||
17 | struct sway_container *con2) { | ||
18 | struct sway_container *temp = malloc(sizeof(struct sway_container)); | ||
19 | temp->x = con1->x; | ||
20 | temp->y = con1->y; | ||
21 | temp->width = con1->width; | ||
22 | temp->height = con1->height; | ||
23 | temp->parent = con1->parent; | ||
24 | |||
25 | con1->x = con2->x; | ||
26 | con1->y = con2->y; | ||
27 | con1->width = con2->width; | ||
28 | con1->height = con2->height; | ||
29 | |||
30 | con2->x = temp->x; | ||
31 | con2->y = temp->y; | ||
32 | con2->width = temp->width; | ||
33 | con2->height = temp->height; | ||
34 | |||
35 | int temp_index = container_sibling_index(con1); | ||
36 | container_insert_child(con2->parent, con1, container_sibling_index(con2)); | ||
37 | container_insert_child(temp->parent, con2, temp_index); | ||
38 | |||
39 | free(temp); | ||
40 | } | ||
41 | |||
42 | static void swap_focus(struct sway_container *con1, | ||
43 | struct sway_container *con2, struct sway_seat *seat, | ||
44 | struct sway_container *focus) { | ||
45 | if (focus == con1 || focus == con2) { | ||
46 | struct sway_container *ws1 = container_parent(con1, C_WORKSPACE); | ||
47 | struct sway_container *ws2 = container_parent(con2, C_WORKSPACE); | ||
48 | if (focus == con1 && (con2->parent->layout == L_TABBED | ||
49 | || con2->parent->layout == L_STACKED)) { | ||
50 | if (workspace_is_visible(ws2)) { | ||
51 | seat_set_focus_warp(seat, con2, false, true); | ||
52 | } | ||
53 | seat_set_focus(seat, ws1 != ws2 ? con2 : con1); | ||
54 | } else if (focus == con2 && (con1->parent->layout == L_TABBED | ||
55 | || con1->parent->layout == L_STACKED)) { | ||
56 | if (workspace_is_visible(ws1)) { | ||
57 | seat_set_focus_warp(seat, con1, false, true); | ||
58 | } | ||
59 | seat_set_focus(seat, ws1 != ws2 ? con1 : con2); | ||
60 | } else if (ws1 != ws2) { | ||
61 | seat_set_focus(seat, focus == con1 ? con2 : con1); | ||
62 | } else { | ||
63 | seat_set_focus(seat, focus); | ||
64 | } | ||
65 | } else { | ||
66 | seat_set_focus(seat, focus); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static void container_swap(struct sway_container *con1, | ||
71 | struct sway_container *con2) { | ||
72 | if (!sway_assert(con1 && con2, "Cannot swap with nothing")) { | ||
73 | return; | ||
74 | } | ||
75 | if (!sway_assert(con1->type >= C_CONTAINER && con2->type >= C_CONTAINER, | ||
76 | "Can only swap containers and views")) { | ||
77 | return; | ||
78 | } | ||
79 | if (!sway_assert(!container_has_ancestor(con1, con2) | ||
80 | && !container_has_ancestor(con2, con1), | ||
81 | "Cannot swap ancestor and descendant")) { | ||
82 | return; | ||
83 | } | ||
84 | if (!sway_assert(!container_is_floating(con1) | ||
85 | && !container_is_floating(con2), | ||
86 | "Swapping with floating containers is not supported")) { | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | wlr_log(WLR_DEBUG, "Swapping containers %zu and %zu", con1->id, con2->id); | ||
91 | |||
92 | int fs1 = con1->is_fullscreen; | ||
93 | int fs2 = con2->is_fullscreen; | ||
94 | if (fs1) { | ||
95 | container_set_fullscreen(con1, false); | ||
96 | } | ||
97 | if (fs2) { | ||
98 | container_set_fullscreen(con2, false); | ||
99 | } | ||
100 | |||
101 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
102 | struct sway_container *focus = seat_get_focus(seat); | ||
103 | struct sway_container *vis1 = container_parent( | ||
104 | seat_get_focus_inactive(seat, container_parent(con1, C_OUTPUT)), | ||
105 | C_WORKSPACE); | ||
106 | struct sway_container *vis2 = container_parent( | ||
107 | seat_get_focus_inactive(seat, container_parent(con2, C_OUTPUT)), | ||
108 | C_WORKSPACE); | ||
109 | |||
110 | char *stored_prev_name = NULL; | ||
111 | if (prev_workspace_name) { | ||
112 | stored_prev_name = strdup(prev_workspace_name); | ||
113 | } | ||
114 | |||
115 | swap_places(con1, con2); | ||
116 | |||
117 | if (!workspace_is_visible(vis1)) { | ||
118 | seat_set_focus(seat, seat_get_focus_inactive(seat, vis1)); | ||
119 | } | ||
120 | if (!workspace_is_visible(vis2)) { | ||
121 | seat_set_focus(seat, seat_get_focus_inactive(seat, vis2)); | ||
122 | } | ||
123 | |||
124 | swap_focus(con1, con2, seat, focus); | ||
125 | |||
126 | if (stored_prev_name) { | ||
127 | free(prev_workspace_name); | ||
128 | prev_workspace_name = stored_prev_name; | ||
129 | } | ||
130 | |||
131 | if (fs1) { | ||
132 | container_set_fullscreen(con2, true); | ||
133 | } | ||
134 | if (fs2) { | ||
135 | container_set_fullscreen(con1, true); | ||
136 | } | ||
137 | } | ||
138 | |||
13 | static bool test_con_id(struct sway_container *container, void *con_id) { | 139 | static bool test_con_id(struct sway_container *container, void *con_id) { |
14 | return container->id == (size_t)con_id; | 140 | return container->id == (size_t)con_id; |
15 | } | 141 | } |
diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c index c183785b..62127c97 100644 --- a/sway/commands/unmark.c +++ b/sway/commands/unmark.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
4 | #include "sway/config.h" | 4 | #include "sway/config.h" |
5 | #include "sway/tree/root.h" | ||
5 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
6 | #include "list.h" | 7 | #include "list.h" |
7 | #include "log.h" | 8 | #include "log.h" |
diff --git a/sway/commands/urgent.c b/sway/commands/urgent.c index 51c497c4..bccb33fe 100644 --- a/sway/commands/urgent.c +++ b/sway/commands/urgent.c | |||
@@ -4,7 +4,6 @@ | |||
4 | #include "sway/tree/arrange.h" | 4 | #include "sway/tree/arrange.h" |
5 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
6 | #include "sway/tree/view.h" | 6 | #include "sway/tree/view.h" |
7 | #include "sway/tree/layout.h" | ||
8 | #include "util.h" | 7 | #include "util.h" |
9 | 8 | ||
10 | struct cmd_results *cmd_urgent(int argc, char **argv) { | 9 | struct cmd_results *cmd_urgent(int argc, char **argv) { |
diff --git a/sway/config.c b/sway/config.c index 642abbac..8105722a 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "sway/criteria.h" | 27 | #include "sway/criteria.h" |
28 | #include "sway/swaynag.h" | 28 | #include "sway/swaynag.h" |
29 | #include "sway/tree/arrange.h" | 29 | #include "sway/tree/arrange.h" |
30 | #include "sway/tree/layout.h" | 30 | #include "sway/tree/root.h" |
31 | #include "sway/tree/workspace.h" | 31 | #include "sway/tree/workspace.h" |
32 | #include "cairo.h" | 32 | #include "cairo.h" |
33 | #include "pango.h" | 33 | #include "pango.h" |
diff --git a/sway/config/output.c b/sway/config/output.c index d939eea6..16ec9339 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <wlr/types/wlr_output_layout.h> | 9 | #include <wlr/types/wlr_output_layout.h> |
10 | #include "sway/config.h" | 10 | #include "sway/config.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/tree/root.h" | ||
12 | #include "log.h" | 13 | #include "log.h" |
13 | 14 | ||
14 | int output_name_cmp(const void *item, const void *data) { | 15 | int output_name_cmp(const void *item, const void *data) { |
diff --git a/sway/criteria.c b/sway/criteria.c index 81c2325a..5452c4ee 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "sway/criteria.h" | 6 | #include "sway/criteria.h" |
7 | #include "sway/tree/container.h" | 7 | #include "sway/tree/container.h" |
8 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/tree/root.h" | ||
9 | #include "sway/tree/view.h" | 10 | #include "sway/tree/view.h" |
10 | #include "stringop.h" | 11 | #include "stringop.h" |
11 | #include "list.h" | 12 | #include "list.h" |
diff --git a/sway/debug-tree.c b/sway/debug-tree.c index ea0826b9..2768cf58 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c | |||
@@ -9,7 +9,7 @@ | |||
9 | #include "sway/output.h" | 9 | #include "sway/output.h" |
10 | #include "sway/server.h" | 10 | #include "sway/server.h" |
11 | #include "sway/tree/container.h" | 11 | #include "sway/tree/container.h" |
12 | #include "sway/tree/layout.h" | 12 | #include "sway/tree/root.h" |
13 | #include "cairo.h" | 13 | #include "cairo.h" |
14 | #include "config.h" | 14 | #include "config.h" |
15 | #include "pango.h" | 15 | #include "pango.h" |
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index a2935883..1fae5db2 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "sway/output.h" | 14 | #include "sway/output.h" |
15 | #include "sway/server.h" | 15 | #include "sway/server.h" |
16 | #include "sway/tree/arrange.h" | 16 | #include "sway/tree/arrange.h" |
17 | #include "sway/tree/layout.h" | ||
18 | #include "log.h" | 17 | #include "log.h" |
19 | 18 | ||
20 | static void apply_exclusive(struct wlr_box *usable_area, | 19 | static void apply_exclusive(struct wlr_box *usable_area, |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index f95d9965..bbebe453 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "sway/server.h" | 23 | #include "sway/server.h" |
24 | #include "sway/tree/arrange.h" | 24 | #include "sway/tree/arrange.h" |
25 | #include "sway/tree/container.h" | 25 | #include "sway/tree/container.h" |
26 | #include "sway/tree/layout.h" | 26 | #include "sway/tree/root.h" |
27 | #include "sway/tree/view.h" | 27 | #include "sway/tree/view.h" |
28 | #include "sway/tree/workspace.h" | 28 | #include "sway/tree/workspace.h" |
29 | 29 | ||
diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 5cf8abc0..b5a10370 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "sway/server.h" | 24 | #include "sway/server.h" |
25 | #include "sway/tree/arrange.h" | 25 | #include "sway/tree/arrange.h" |
26 | #include "sway/tree/container.h" | 26 | #include "sway/tree/container.h" |
27 | #include "sway/tree/layout.h" | 27 | #include "sway/tree/root.h" |
28 | #include "sway/tree/view.h" | 28 | #include "sway/tree/view.h" |
29 | #include "sway/tree/workspace.h" | 29 | #include "sway/tree/workspace.h" |
30 | 30 | ||
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index f5aaa575..7d1824f1 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include "sway/server.h" | 13 | #include "sway/server.h" |
14 | #include "sway/tree/arrange.h" | 14 | #include "sway/tree/arrange.h" |
15 | #include "sway/tree/container.h" | 15 | #include "sway/tree/container.h" |
16 | #include "sway/tree/layout.h" | ||
17 | #include "sway/tree/view.h" | 16 | #include "sway/tree/view.h" |
18 | 17 | ||
19 | static const struct sway_view_child_impl popup_impl; | 18 | static const struct sway_view_child_impl popup_impl; |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index f623b77b..522fddca 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include "sway/server.h" | 12 | #include "sway/server.h" |
13 | #include "sway/tree/arrange.h" | 13 | #include "sway/tree/arrange.h" |
14 | #include "sway/tree/container.h" | 14 | #include "sway/tree/container.h" |
15 | #include "sway/tree/layout.h" | ||
16 | #include "sway/tree/view.h" | 15 | #include "sway/tree/view.h" |
17 | 16 | ||
18 | static const struct sway_view_child_impl popup_impl; | 17 | static const struct sway_view_child_impl popup_impl; |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 6fcc850d..4e401008 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "sway/server.h" | 14 | #include "sway/server.h" |
15 | #include "sway/tree/arrange.h" | 15 | #include "sway/tree/arrange.h" |
16 | #include "sway/tree/container.h" | 16 | #include "sway/tree/container.h" |
17 | #include "sway/tree/layout.h" | ||
18 | #include "sway/tree/view.h" | 17 | #include "sway/tree/view.h" |
19 | 18 | ||
20 | static const char *atom_map[ATOM_LAST] = { | 19 | static const char *atom_map[ATOM_LAST] = { |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index ba5e0400..00240e84 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "sway/layers.h" | 20 | #include "sway/layers.h" |
21 | #include "sway/output.h" | 21 | #include "sway/output.h" |
22 | #include "sway/tree/arrange.h" | 22 | #include "sway/tree/arrange.h" |
23 | #include "sway/tree/root.h" | ||
23 | #include "sway/tree/view.h" | 24 | #include "sway/tree/view.h" |
24 | #include "sway/tree/workspace.h" | 25 | #include "sway/tree/workspace.h" |
25 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 26 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 997d7815..269823ee 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -25,10 +25,9 @@ | |||
25 | #include "sway/output.h" | 25 | #include "sway/output.h" |
26 | #include "sway/tree/arrange.h" | 26 | #include "sway/tree/arrange.h" |
27 | #include "sway/tree/container.h" | 27 | #include "sway/tree/container.h" |
28 | #include "sway/tree/container.h" | 28 | #include "sway/tree/root.h" |
29 | #include "sway/tree/view.h" | 29 | #include "sway/tree/view.h" |
30 | #include "sway/tree/workspace.h" | 30 | #include "sway/tree/workspace.h" |
31 | #include "sway/tree/workspace.h" | ||
32 | 31 | ||
33 | static void seat_device_destroy(struct sway_seat_device *seat_device) { | 32 | static void seat_device_destroy(struct sway_seat_device *seat_device) { |
34 | if (!seat_device) { | 33 | if (!seat_device) { |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 49342f47..ed710be5 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "sway/server.h" | 31 | #include "sway/server.h" |
32 | #include "sway/input/input-manager.h" | 32 | #include "sway/input/input-manager.h" |
33 | #include "sway/input/seat.h" | 33 | #include "sway/input/seat.h" |
34 | #include "sway/tree/root.h" | ||
34 | #include "sway/tree/view.h" | 35 | #include "sway/tree/view.h" |
35 | #include "list.h" | 36 | #include "list.h" |
36 | #include "log.h" | 37 | #include "log.h" |
diff --git a/sway/main.c b/sway/main.c index 3ba4ba75..7ed10c86 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "sway/desktop/transaction.h" | 23 | #include "sway/desktop/transaction.h" |
24 | #include "sway/server.h" | 24 | #include "sway/server.h" |
25 | #include "sway/swaynag.h" | 25 | #include "sway/swaynag.h" |
26 | #include "sway/tree/layout.h" | 26 | #include "sway/tree/root.h" |
27 | #include "sway/ipc-server.h" | 27 | #include "sway/ipc-server.h" |
28 | #include "ipc-client.h" | 28 | #include "ipc-client.h" |
29 | #include "readline.h" | 29 | #include "readline.h" |
diff --git a/sway/meson.build b/sway/meson.build index 676422d0..bcb44e8b 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -150,7 +150,6 @@ sway_sources = files( | |||
150 | 150 | ||
151 | 'tree/arrange.c', | 151 | 'tree/arrange.c', |
152 | 'tree/container.c', | 152 | 'tree/container.c', |
153 | 'tree/layout.c', | ||
154 | 'tree/root.c', | 153 | 'tree/root.c', |
155 | 'tree/view.c', | 154 | 'tree/view.c', |
156 | 'tree/workspace.c', | 155 | 'tree/workspace.c', |
diff --git a/sway/server.c b/sway/server.c index 00acaa01..7fa6007e 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "sway/desktop/idle_inhibit_v1.h" | 24 | #include "sway/desktop/idle_inhibit_v1.h" |
25 | #include "sway/input/input-manager.h" | 25 | #include "sway/input/input-manager.h" |
26 | #include "sway/server.h" | 26 | #include "sway/server.h" |
27 | #include "sway/tree/layout.h" | 27 | #include "sway/tree/root.h" |
28 | #include "config.h" | 28 | #include "config.h" |
29 | #ifdef HAVE_XWAYLAND | 29 | #ifdef HAVE_XWAYLAND |
30 | #include "sway/xwayland.h" | 30 | #include "sway/xwayland.h" |
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index a4b058f3..60e5b951 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c | |||
@@ -7,7 +7,6 @@ | |||
7 | #include <wlr/types/wlr_output_layout.h> | 7 | #include <wlr/types/wlr_output_layout.h> |
8 | #include "sway/tree/arrange.h" | 8 | #include "sway/tree/arrange.h" |
9 | #include "sway/tree/container.h" | 9 | #include "sway/tree/container.h" |
10 | #include "sway/tree/layout.h" | ||
11 | #include "sway/output.h" | 10 | #include "sway/output.h" |
12 | #include "sway/tree/workspace.h" | 11 | #include "sway/tree/workspace.h" |
13 | #include "sway/tree/view.h" | 12 | #include "sway/tree/view.h" |
@@ -39,7 +38,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
39 | child->width = parent->width; | 38 | child->width = parent->width; |
40 | } | 39 | } |
41 | } | 40 | } |
42 | remove_gaps(child); | 41 | container_remove_gaps(child); |
43 | total_width += child->width; | 42 | total_width += child->width; |
44 | } | 43 | } |
45 | double scale = parent->width / total_width; | 44 | double scale = parent->width / total_width; |
@@ -62,7 +61,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
62 | if (i == num_children - 1) { | 61 | if (i == num_children - 1) { |
63 | child->width = parent->x + parent->width - child->x; | 62 | child->width = parent->x + parent->width - child->x; |
64 | } | 63 | } |
65 | add_gaps(child); | 64 | container_add_gaps(child); |
66 | } | 65 | } |
67 | } | 66 | } |
68 | 67 | ||
@@ -91,7 +90,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
91 | child->height = parent_height; | 90 | child->height = parent_height; |
92 | } | 91 | } |
93 | } | 92 | } |
94 | remove_gaps(child); | 93 | container_remove_gaps(child); |
95 | total_height += child->height; | 94 | total_height += child->height; |
96 | } | 95 | } |
97 | double scale = parent_height / total_height; | 96 | double scale = parent_height / total_height; |
@@ -115,7 +114,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
115 | child->height = | 114 | child->height = |
116 | parent->y + parent_offset + parent_height - child->y; | 115 | parent->y + parent_offset + parent_height - child->y; |
117 | } | 116 | } |
118 | add_gaps(child); | 117 | container_add_gaps(child); |
119 | } | 118 | } |
120 | } | 119 | } |
121 | 120 | ||
@@ -133,12 +132,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { | |||
133 | size_t parent_height = parent->height - parent_offset; | 132 | size_t parent_height = parent->height - parent_offset; |
134 | for (int i = 0; i < parent->children->length; ++i) { | 133 | for (int i = 0; i < parent->children->length; ++i) { |
135 | struct sway_container *child = parent->children->items[i]; | 134 | struct sway_container *child = parent->children->items[i]; |
136 | remove_gaps(child); | 135 | container_remove_gaps(child); |
137 | child->x = parent->x; | 136 | child->x = parent->x; |
138 | child->y = parent->y + parent_offset; | 137 | child->y = parent->y + parent_offset; |
139 | child->width = parent->width; | 138 | child->width = parent->width; |
140 | child->height = parent_height; | 139 | child->height = parent_height; |
141 | add_gaps(child); | 140 | container_add_gaps(child); |
142 | } | 141 | } |
143 | } | 142 | } |
144 | 143 | ||
@@ -205,7 +204,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
205 | struct wlr_box *area = &output->sway_output->usable_area; | 204 | struct wlr_box *area = &output->sway_output->usable_area; |
206 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 205 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
207 | area->width, area->height, area->x, area->y); | 206 | area->width, area->height, area->x, area->y); |
208 | remove_gaps(workspace); | 207 | workspace_remove_gaps(workspace); |
209 | 208 | ||
210 | double prev_x = workspace->x; | 209 | double prev_x = workspace->x; |
211 | double prev_y = workspace->y; | 210 | double prev_y = workspace->y; |
@@ -230,7 +229,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
230 | } | 229 | } |
231 | } | 230 | } |
232 | 231 | ||
233 | add_gaps(workspace); | 232 | workspace_add_gaps(workspace); |
234 | container_set_dirty(workspace); | 233 | container_set_dirty(workspace); |
235 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, | 234 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, |
236 | workspace->x, workspace->y); | 235 | workspace->x, workspace->y); |
@@ -314,41 +313,3 @@ void arrange_windows(struct sway_container *container) { | |||
314 | break; | 313 | break; |
315 | } | 314 | } |
316 | } | 315 | } |
317 | |||
318 | void remove_gaps(struct sway_container *c) { | ||
319 | if (c->current_gaps == 0) { | ||
320 | wlr_log(WLR_DEBUG, "Removing gaps: not gapped: %p", c); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | c->width += c->current_gaps * 2; | ||
325 | c->height += c->current_gaps * 2; | ||
326 | c->x -= c->current_gaps; | ||
327 | c->y -= c->current_gaps; | ||
328 | |||
329 | c->current_gaps = 0; | ||
330 | |||
331 | wlr_log(WLR_DEBUG, "Removing gaps %p", c); | ||
332 | } | ||
333 | |||
334 | void add_gaps(struct sway_container *c) { | ||
335 | if (c->current_gaps > 0 || c->type == C_CONTAINER) { | ||
336 | wlr_log(WLR_DEBUG, "Not adding gaps: %p", c); | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | if (c->type == C_WORKSPACE && | ||
341 | !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) { | ||
342 | return; | ||
343 | } | ||
344 | |||
345 | double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
346 | |||
347 | c->x += gaps; | ||
348 | c->y += gaps; | ||
349 | c->width -= 2 * gaps; | ||
350 | c->height -= 2 * gaps; | ||
351 | c->current_gaps = gaps; | ||
352 | |||
353 | wlr_log(WLR_DEBUG, "Adding gaps: %p", c); | ||
354 | } | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index 5721c35c..f13e2e96 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include "sway/output.h" | 19 | #include "sway/output.h" |
20 | #include "sway/server.h" | 20 | #include "sway/server.h" |
21 | #include "sway/tree/arrange.h" | 21 | #include "sway/tree/arrange.h" |
22 | #include "sway/tree/layout.h" | ||
23 | #include "sway/tree/view.h" | 22 | #include "sway/tree/view.h" |
24 | #include "sway/tree/workspace.h" | 23 | #include "sway/tree/workspace.h" |
25 | #include "log.h" | 24 | #include "log.h" |
@@ -1124,7 +1123,258 @@ void container_discover_outputs(struct sway_container *con) { | |||
1124 | } | 1123 | } |
1125 | } | 1124 | } |
1126 | 1125 | ||
1126 | void container_remove_gaps(struct sway_container *c) { | ||
1127 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1128 | "Expected a container or view")) { | ||
1129 | return; | ||
1130 | } | ||
1131 | if (c->current_gaps == 0) { | ||
1132 | return; | ||
1133 | } | ||
1134 | |||
1135 | c->width += c->current_gaps * 2; | ||
1136 | c->height += c->current_gaps * 2; | ||
1137 | c->x -= c->current_gaps; | ||
1138 | c->y -= c->current_gaps; | ||
1139 | c->current_gaps = 0; | ||
1140 | } | ||
1141 | |||
1142 | void container_add_gaps(struct sway_container *c) { | ||
1143 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1144 | "Expected a container or view")) { | ||
1145 | return; | ||
1146 | } | ||
1147 | if (c->current_gaps > 0 || c->type != C_VIEW) { | ||
1148 | return; | ||
1149 | } | ||
1150 | |||
1151 | c->current_gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
1152 | c->x += c->current_gaps; | ||
1153 | c->y += c->current_gaps; | ||
1154 | c->width -= 2 * c->current_gaps; | ||
1155 | c->height -= 2 * c->current_gaps; | ||
1156 | } | ||
1157 | |||
1127 | int container_sibling_index(const struct sway_container *child) { | 1158 | int container_sibling_index(const struct sway_container *child) { |
1128 | return list_find(child->parent->children, child); | 1159 | return list_find(child->parent->children, child); |
1129 | } | 1160 | } |
1130 | 1161 | ||
1162 | void container_handle_fullscreen_reparent(struct sway_container *con, | ||
1163 | struct sway_container *old_parent) { | ||
1164 | if (!con->is_fullscreen) { | ||
1165 | return; | ||
1166 | } | ||
1167 | struct sway_container *old_workspace = old_parent; | ||
1168 | if (old_workspace && old_workspace->type != C_WORKSPACE) { | ||
1169 | old_workspace = container_parent(old_workspace, C_WORKSPACE); | ||
1170 | } | ||
1171 | struct sway_container *new_workspace = container_parent(con, C_WORKSPACE); | ||
1172 | if (old_workspace == new_workspace) { | ||
1173 | return; | ||
1174 | } | ||
1175 | // Unmark the old workspace as fullscreen | ||
1176 | if (old_workspace) { | ||
1177 | old_workspace->sway_workspace->fullscreen = NULL; | ||
1178 | } | ||
1179 | |||
1180 | // Mark the new workspace as fullscreen | ||
1181 | if (new_workspace->sway_workspace->fullscreen) { | ||
1182 | container_set_fullscreen( | ||
1183 | new_workspace->sway_workspace->fullscreen, false); | ||
1184 | } | ||
1185 | new_workspace->sway_workspace->fullscreen = con; | ||
1186 | |||
1187 | // Resize container to new output dimensions | ||
1188 | struct sway_container *output = new_workspace->parent; | ||
1189 | con->x = output->x; | ||
1190 | con->y = output->y; | ||
1191 | con->width = output->width; | ||
1192 | con->height = output->height; | ||
1193 | |||
1194 | if (con->type == C_VIEW) { | ||
1195 | struct sway_view *view = con->sway_view; | ||
1196 | view->x = output->x; | ||
1197 | view->y = output->y; | ||
1198 | view->width = output->width; | ||
1199 | view->height = output->height; | ||
1200 | } else { | ||
1201 | arrange_windows(new_workspace); | ||
1202 | } | ||
1203 | } | ||
1204 | |||
1205 | void container_insert_child(struct sway_container *parent, | ||
1206 | struct sway_container *child, int i) { | ||
1207 | struct sway_container *old_parent = child->parent; | ||
1208 | if (old_parent) { | ||
1209 | container_remove_child(child); | ||
1210 | } | ||
1211 | wlr_log(WLR_DEBUG, "Inserting id:%zd at index %d", child->id, i); | ||
1212 | list_insert(parent->children, i, child); | ||
1213 | child->parent = parent; | ||
1214 | container_handle_fullscreen_reparent(child, old_parent); | ||
1215 | } | ||
1216 | |||
1217 | struct sway_container *container_add_sibling(struct sway_container *fixed, | ||
1218 | struct sway_container *active) { | ||
1219 | // TODO handle floating | ||
1220 | struct sway_container *old_parent = NULL; | ||
1221 | if (active->parent) { | ||
1222 | old_parent = active->parent; | ||
1223 | container_remove_child(active); | ||
1224 | } | ||
1225 | struct sway_container *parent = fixed->parent; | ||
1226 | int i = container_sibling_index(fixed); | ||
1227 | list_insert(parent->children, i + 1, active); | ||
1228 | active->parent = parent; | ||
1229 | container_handle_fullscreen_reparent(active, old_parent); | ||
1230 | return active->parent; | ||
1231 | } | ||
1232 | |||
1233 | void container_add_child(struct sway_container *parent, | ||
1234 | struct sway_container *child) { | ||
1235 | wlr_log(WLR_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | ||
1236 | child, child->type, child->width, child->height, | ||
1237 | parent, parent->type, parent->width, parent->height); | ||
1238 | struct sway_container *old_parent = child->parent; | ||
1239 | list_add(parent->children, child); | ||
1240 | child->parent = parent; | ||
1241 | container_handle_fullscreen_reparent(child, old_parent); | ||
1242 | if (old_parent) { | ||
1243 | container_set_dirty(old_parent); | ||
1244 | } | ||
1245 | container_set_dirty(child); | ||
1246 | } | ||
1247 | |||
1248 | struct sway_container *container_remove_child(struct sway_container *child) { | ||
1249 | if (child->is_fullscreen) { | ||
1250 | struct sway_container *workspace = container_parent(child, C_WORKSPACE); | ||
1251 | workspace->sway_workspace->fullscreen = NULL; | ||
1252 | } | ||
1253 | |||
1254 | struct sway_container *parent = child->parent; | ||
1255 | list_t *list = container_is_floating(child) ? | ||
1256 | parent->sway_workspace->floating : parent->children; | ||
1257 | int index = list_find(list, child); | ||
1258 | if (index != -1) { | ||
1259 | list_del(list, index); | ||
1260 | } | ||
1261 | child->parent = NULL; | ||
1262 | container_notify_subtree_changed(parent); | ||
1263 | |||
1264 | container_set_dirty(parent); | ||
1265 | container_set_dirty(child); | ||
1266 | |||
1267 | return parent; | ||
1268 | } | ||
1269 | |||
1270 | enum sway_container_layout container_get_default_layout( | ||
1271 | struct sway_container *con) { | ||
1272 | if (con->type != C_OUTPUT) { | ||
1273 | con = container_parent(con, C_OUTPUT); | ||
1274 | } | ||
1275 | |||
1276 | if (!sway_assert(con != NULL, | ||
1277 | "container_get_default_layout must be called on an attached" | ||
1278 | " container below the root container")) { | ||
1279 | return 0; | ||
1280 | } | ||
1281 | |||
1282 | if (config->default_layout != L_NONE) { | ||
1283 | return config->default_layout; | ||
1284 | } else if (config->default_orientation != L_NONE) { | ||
1285 | return config->default_orientation; | ||
1286 | } else if (con->width >= con->height) { | ||
1287 | return L_HORIZ; | ||
1288 | } else { | ||
1289 | return L_VERT; | ||
1290 | } | ||
1291 | } | ||
1292 | |||
1293 | struct sway_container *container_replace_child(struct sway_container *child, | ||
1294 | struct sway_container *new_child) { | ||
1295 | struct sway_container *parent = child->parent; | ||
1296 | if (parent == NULL) { | ||
1297 | return NULL; | ||
1298 | } | ||
1299 | |||
1300 | list_t *list = container_is_floating(child) ? | ||
1301 | parent->sway_workspace->floating : parent->children; | ||
1302 | int i = list_find(list, child); | ||
1303 | |||
1304 | if (new_child->parent) { | ||
1305 | container_remove_child(new_child); | ||
1306 | } | ||
1307 | list->items[i] = new_child; | ||
1308 | new_child->parent = parent; | ||
1309 | child->parent = NULL; | ||
1310 | |||
1311 | // Set geometry for new child | ||
1312 | new_child->x = child->x; | ||
1313 | new_child->y = child->y; | ||
1314 | new_child->width = child->width; | ||
1315 | new_child->height = child->height; | ||
1316 | |||
1317 | // reset geometry for child | ||
1318 | child->width = 0; | ||
1319 | child->height = 0; | ||
1320 | |||
1321 | return parent; | ||
1322 | } | ||
1323 | |||
1324 | struct sway_container *container_split(struct sway_container *child, | ||
1325 | enum sway_container_layout layout) { | ||
1326 | // TODO floating: cannot split a floating container | ||
1327 | if (!sway_assert(child, "child cannot be null")) { | ||
1328 | return NULL; | ||
1329 | } | ||
1330 | if (child->type == C_WORKSPACE && child->children->length == 0) { | ||
1331 | // Special case: this just behaves like splitt | ||
1332 | child->prev_split_layout = child->layout; | ||
1333 | child->layout = layout; | ||
1334 | return child; | ||
1335 | } | ||
1336 | |||
1337 | struct sway_container *cont = container_create(C_CONTAINER); | ||
1338 | |||
1339 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); | ||
1340 | |||
1341 | child->type == C_WORKSPACE ? workspace_remove_gaps(child) | ||
1342 | : container_remove_gaps(child); | ||
1343 | |||
1344 | cont->prev_split_layout = L_NONE; | ||
1345 | cont->width = child->width; | ||
1346 | cont->height = child->height; | ||
1347 | cont->x = child->x; | ||
1348 | cont->y = child->y; | ||
1349 | |||
1350 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
1351 | bool set_focus = (seat_get_focus(seat) == child); | ||
1352 | |||
1353 | container_add_gaps(cont); | ||
1354 | |||
1355 | if (child->type == C_WORKSPACE) { | ||
1356 | struct sway_container *workspace = child; | ||
1357 | while (workspace->children->length) { | ||
1358 | struct sway_container *ws_child = workspace->children->items[0]; | ||
1359 | container_remove_child(ws_child); | ||
1360 | container_add_child(cont, ws_child); | ||
1361 | } | ||
1362 | |||
1363 | container_add_child(workspace, cont); | ||
1364 | enum sway_container_layout old_layout = workspace->layout; | ||
1365 | workspace->layout = layout; | ||
1366 | cont->layout = old_layout; | ||
1367 | } else { | ||
1368 | cont->layout = layout; | ||
1369 | container_replace_child(child, cont); | ||
1370 | container_add_child(cont, child); | ||
1371 | } | ||
1372 | |||
1373 | if (set_focus) { | ||
1374 | seat_set_focus(seat, cont); | ||
1375 | seat_set_focus(seat, child); | ||
1376 | } | ||
1377 | |||
1378 | container_notify_subtree_changed(cont); | ||
1379 | return cont; | ||
1380 | } | ||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c deleted file mode 100644 index 601d0e91..00000000 --- a/sway/tree/layout.c +++ /dev/null | |||
@@ -1,402 +0,0 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <math.h> | ||
3 | #include <stdbool.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <wlr/types/wlr_output.h> | ||
7 | #include <wlr/types/wlr_output_layout.h> | ||
8 | #include "config.h" | ||
9 | #include "sway/debug.h" | ||
10 | #include "sway/tree/arrange.h" | ||
11 | #include "sway/tree/container.h" | ||
12 | #include "sway/tree/layout.h" | ||
13 | #include "sway/output.h" | ||
14 | #include "sway/tree/workspace.h" | ||
15 | #include "sway/tree/view.h" | ||
16 | #include "sway/input/seat.h" | ||
17 | #include "sway/ipc-server.h" | ||
18 | #include "list.h" | ||
19 | #include "log.h" | ||
20 | |||
21 | void container_handle_fullscreen_reparent(struct sway_container *con, | ||
22 | struct sway_container *old_parent) { | ||
23 | if (!con->is_fullscreen) { | ||
24 | return; | ||
25 | } | ||
26 | struct sway_container *old_workspace = old_parent; | ||
27 | if (old_workspace && old_workspace->type != C_WORKSPACE) { | ||
28 | old_workspace = container_parent(old_workspace, C_WORKSPACE); | ||
29 | } | ||
30 | struct sway_container *new_workspace = container_parent(con, C_WORKSPACE); | ||
31 | if (old_workspace == new_workspace) { | ||
32 | return; | ||
33 | } | ||
34 | // Unmark the old workspace as fullscreen | ||
35 | if (old_workspace) { | ||
36 | old_workspace->sway_workspace->fullscreen = NULL; | ||
37 | } | ||
38 | |||
39 | // Mark the new workspace as fullscreen | ||
40 | if (new_workspace->sway_workspace->fullscreen) { | ||
41 | container_set_fullscreen( | ||
42 | new_workspace->sway_workspace->fullscreen, false); | ||
43 | } | ||
44 | new_workspace->sway_workspace->fullscreen = con; | ||
45 | |||
46 | // Resize container to new output dimensions | ||
47 | struct sway_container *output = new_workspace->parent; | ||
48 | con->x = output->x; | ||
49 | con->y = output->y; | ||
50 | con->width = output->width; | ||
51 | con->height = output->height; | ||
52 | |||
53 | if (con->type == C_VIEW) { | ||
54 | struct sway_view *view = con->sway_view; | ||
55 | view->x = output->x; | ||
56 | view->y = output->y; | ||
57 | view->width = output->width; | ||
58 | view->height = output->height; | ||
59 | } else { | ||
60 | arrange_windows(new_workspace); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | void container_insert_child(struct sway_container *parent, | ||
65 | struct sway_container *child, int i) { | ||
66 | struct sway_container *old_parent = child->parent; | ||
67 | if (old_parent) { | ||
68 | container_remove_child(child); | ||
69 | } | ||
70 | wlr_log(WLR_DEBUG, "Inserting id:%zd at index %d", child->id, i); | ||
71 | list_insert(parent->children, i, child); | ||
72 | child->parent = parent; | ||
73 | container_handle_fullscreen_reparent(child, old_parent); | ||
74 | } | ||
75 | |||
76 | struct sway_container *container_add_sibling(struct sway_container *fixed, | ||
77 | struct sway_container *active) { | ||
78 | // TODO handle floating | ||
79 | struct sway_container *old_parent = NULL; | ||
80 | if (active->parent) { | ||
81 | old_parent = active->parent; | ||
82 | container_remove_child(active); | ||
83 | } | ||
84 | struct sway_container *parent = fixed->parent; | ||
85 | int i = container_sibling_index(fixed); | ||
86 | list_insert(parent->children, i + 1, active); | ||
87 | active->parent = parent; | ||
88 | container_handle_fullscreen_reparent(active, old_parent); | ||
89 | return active->parent; | ||
90 | } | ||
91 | |||
92 | void container_add_child(struct sway_container *parent, | ||
93 | struct sway_container *child) { | ||
94 | wlr_log(WLR_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | ||
95 | child, child->type, child->width, child->height, | ||
96 | parent, parent->type, parent->width, parent->height); | ||
97 | struct sway_container *old_parent = child->parent; | ||
98 | list_add(parent->children, child); | ||
99 | child->parent = parent; | ||
100 | container_handle_fullscreen_reparent(child, old_parent); | ||
101 | if (old_parent) { | ||
102 | container_set_dirty(old_parent); | ||
103 | } | ||
104 | container_set_dirty(child); | ||
105 | } | ||
106 | |||
107 | struct sway_container *container_remove_child(struct sway_container *child) { | ||
108 | if (child->is_fullscreen) { | ||
109 | struct sway_container *workspace = container_parent(child, C_WORKSPACE); | ||
110 | workspace->sway_workspace->fullscreen = NULL; | ||
111 | } | ||
112 | |||
113 | struct sway_container *parent = child->parent; | ||
114 | list_t *list = container_is_floating(child) ? | ||
115 | parent->sway_workspace->floating : parent->children; | ||
116 | int index = list_find(list, child); | ||
117 | if (index != -1) { | ||
118 | list_del(list, index); | ||
119 | } | ||
120 | child->parent = NULL; | ||
121 | container_notify_subtree_changed(parent); | ||
122 | |||
123 | container_set_dirty(parent); | ||
124 | container_set_dirty(child); | ||
125 | |||
126 | return parent; | ||
127 | } | ||
128 | |||
129 | bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { | ||
130 | switch (dir) { | ||
131 | case MOVE_UP: | ||
132 | *out = WLR_DIRECTION_UP; | ||
133 | break; | ||
134 | case MOVE_DOWN: | ||
135 | *out = WLR_DIRECTION_DOWN; | ||
136 | break; | ||
137 | case MOVE_LEFT: | ||
138 | *out = WLR_DIRECTION_LEFT; | ||
139 | break; | ||
140 | case MOVE_RIGHT: | ||
141 | *out = WLR_DIRECTION_RIGHT; | ||
142 | break; | ||
143 | default: | ||
144 | return false; | ||
145 | } | ||
146 | |||
147 | return true; | ||
148 | } | ||
149 | |||
150 | enum sway_container_layout container_get_default_layout( | ||
151 | struct sway_container *con) { | ||
152 | if (con->type != C_OUTPUT) { | ||
153 | con = container_parent(con, C_OUTPUT); | ||
154 | } | ||
155 | |||
156 | if (!sway_assert(con != NULL, | ||
157 | "container_get_default_layout must be called on an attached" | ||
158 | " container below the root container")) { | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | if (config->default_layout != L_NONE) { | ||
163 | return config->default_layout; | ||
164 | } else if (config->default_orientation != L_NONE) { | ||
165 | return config->default_orientation; | ||
166 | } else if (con->width >= con->height) { | ||
167 | return L_HORIZ; | ||
168 | } else { | ||
169 | return L_VERT; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | struct sway_container *container_replace_child(struct sway_container *child, | ||
174 | struct sway_container *new_child) { | ||
175 | struct sway_container *parent = child->parent; | ||
176 | if (parent == NULL) { | ||
177 | return NULL; | ||
178 | } | ||
179 | |||
180 | list_t *list = container_is_floating(child) ? | ||
181 | parent->sway_workspace->floating : parent->children; | ||
182 | int i = list_find(list, child); | ||
183 | |||
184 | if (new_child->parent) { | ||
185 | container_remove_child(new_child); | ||
186 | } | ||
187 | list->items[i] = new_child; | ||
188 | new_child->parent = parent; | ||
189 | child->parent = NULL; | ||
190 | |||
191 | // Set geometry for new child | ||
192 | new_child->x = child->x; | ||
193 | new_child->y = child->y; | ||
194 | new_child->width = child->width; | ||
195 | new_child->height = child->height; | ||
196 | |||
197 | // reset geometry for child | ||
198 | child->width = 0; | ||
199 | child->height = 0; | ||
200 | |||
201 | return parent; | ||
202 | } | ||
203 | |||
204 | struct sway_container *container_split(struct sway_container *child, | ||
205 | enum sway_container_layout layout) { | ||
206 | // TODO floating: cannot split a floating container | ||
207 | if (!sway_assert(child, "child cannot be null")) { | ||
208 | return NULL; | ||
209 | } | ||
210 | if (child->type == C_WORKSPACE && child->children->length == 0) { | ||
211 | // Special case: this just behaves like splitt | ||
212 | child->prev_split_layout = child->layout; | ||
213 | child->layout = layout; | ||
214 | return child; | ||
215 | } | ||
216 | |||
217 | struct sway_container *cont = container_create(C_CONTAINER); | ||
218 | |||
219 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); | ||
220 | |||
221 | remove_gaps(child); | ||
222 | |||
223 | cont->prev_split_layout = L_NONE; | ||
224 | cont->width = child->width; | ||
225 | cont->height = child->height; | ||
226 | cont->x = child->x; | ||
227 | cont->y = child->y; | ||
228 | |||
229 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
230 | bool set_focus = (seat_get_focus(seat) == child); | ||
231 | |||
232 | add_gaps(cont); | ||
233 | |||
234 | if (child->type == C_WORKSPACE) { | ||
235 | struct sway_container *workspace = child; | ||
236 | while (workspace->children->length) { | ||
237 | struct sway_container *ws_child = workspace->children->items[0]; | ||
238 | container_remove_child(ws_child); | ||
239 | container_add_child(cont, ws_child); | ||
240 | } | ||
241 | |||
242 | container_add_child(workspace, cont); | ||
243 | enum sway_container_layout old_layout = workspace->layout; | ||
244 | workspace->layout = layout; | ||
245 | cont->layout = old_layout; | ||
246 | } else { | ||
247 | cont->layout = layout; | ||
248 | container_replace_child(child, cont); | ||
249 | container_add_child(cont, child); | ||
250 | } | ||
251 | |||
252 | if (set_focus) { | ||
253 | seat_set_focus(seat, cont); | ||
254 | seat_set_focus(seat, child); | ||
255 | } | ||
256 | |||
257 | container_notify_subtree_changed(cont); | ||
258 | return cont; | ||
259 | } | ||
260 | |||
261 | void container_recursive_resize(struct sway_container *container, | ||
262 | double amount, enum wlr_edges edge) { | ||
263 | bool layout_match = true; | ||
264 | wlr_log(WLR_DEBUG, "Resizing %p with amount: %f", container, amount); | ||
265 | if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) { | ||
266 | container->width += amount; | ||
267 | layout_match = container->layout == L_HORIZ; | ||
268 | } else if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) { | ||
269 | container->height += amount; | ||
270 | layout_match = container->layout == L_VERT; | ||
271 | } | ||
272 | if (container->children) { | ||
273 | for (int i = 0; i < container->children->length; i++) { | ||
274 | struct sway_container *child = container->children->items[i]; | ||
275 | double amt = layout_match ? | ||
276 | amount / container->children->length : amount; | ||
277 | container_recursive_resize(child, amt, edge); | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | |||
282 | static void swap_places(struct sway_container *con1, | ||
283 | struct sway_container *con2) { | ||
284 | struct sway_container *temp = malloc(sizeof(struct sway_container)); | ||
285 | temp->x = con1->x; | ||
286 | temp->y = con1->y; | ||
287 | temp->width = con1->width; | ||
288 | temp->height = con1->height; | ||
289 | temp->parent = con1->parent; | ||
290 | |||
291 | con1->x = con2->x; | ||
292 | con1->y = con2->y; | ||
293 | con1->width = con2->width; | ||
294 | con1->height = con2->height; | ||
295 | |||
296 | con2->x = temp->x; | ||
297 | con2->y = temp->y; | ||
298 | con2->width = temp->width; | ||
299 | con2->height = temp->height; | ||
300 | |||
301 | int temp_index = container_sibling_index(con1); | ||
302 | container_insert_child(con2->parent, con1, container_sibling_index(con2)); | ||
303 | container_insert_child(temp->parent, con2, temp_index); | ||
304 | |||
305 | free(temp); | ||
306 | } | ||
307 | |||
308 | static void swap_focus(struct sway_container *con1, | ||
309 | struct sway_container *con2, struct sway_seat *seat, | ||
310 | struct sway_container *focus) { | ||
311 | if (focus == con1 || focus == con2) { | ||
312 | struct sway_container *ws1 = container_parent(con1, C_WORKSPACE); | ||
313 | struct sway_container *ws2 = container_parent(con2, C_WORKSPACE); | ||
314 | if (focus == con1 && (con2->parent->layout == L_TABBED | ||
315 | || con2->parent->layout == L_STACKED)) { | ||
316 | if (workspace_is_visible(ws2)) { | ||
317 | seat_set_focus_warp(seat, con2, false, true); | ||
318 | } | ||
319 | seat_set_focus(seat, ws1 != ws2 ? con2 : con1); | ||
320 | } else if (focus == con2 && (con1->parent->layout == L_TABBED | ||
321 | || con1->parent->layout == L_STACKED)) { | ||
322 | if (workspace_is_visible(ws1)) { | ||
323 | seat_set_focus_warp(seat, con1, false, true); | ||
324 | } | ||
325 | seat_set_focus(seat, ws1 != ws2 ? con1 : con2); | ||
326 | } else if (ws1 != ws2) { | ||
327 | seat_set_focus(seat, focus == con1 ? con2 : con1); | ||
328 | } else { | ||
329 | seat_set_focus(seat, focus); | ||
330 | } | ||
331 | } else { | ||
332 | seat_set_focus(seat, focus); | ||
333 | } | ||
334 | } | ||
335 | |||
336 | void container_swap(struct sway_container *con1, struct sway_container *con2) { | ||
337 | if (!sway_assert(con1 && con2, "Cannot swap with nothing")) { | ||
338 | return; | ||
339 | } | ||
340 | if (!sway_assert(con1->type >= C_CONTAINER && con2->type >= C_CONTAINER, | ||
341 | "Can only swap containers and views")) { | ||
342 | return; | ||
343 | } | ||
344 | if (!sway_assert(!container_has_ancestor(con1, con2) | ||
345 | && !container_has_ancestor(con2, con1), | ||
346 | "Cannot swap ancestor and descendant")) { | ||
347 | return; | ||
348 | } | ||
349 | if (!sway_assert(!container_is_floating(con1) | ||
350 | && !container_is_floating(con2), | ||
351 | "Swapping with floating containers is not supported")) { | ||
352 | return; | ||
353 | } | ||
354 | |||
355 | wlr_log(WLR_DEBUG, "Swapping containers %zu and %zu", con1->id, con2->id); | ||
356 | |||
357 | int fs1 = con1->is_fullscreen; | ||
358 | int fs2 = con2->is_fullscreen; | ||
359 | if (fs1) { | ||
360 | container_set_fullscreen(con1, false); | ||
361 | } | ||
362 | if (fs2) { | ||
363 | container_set_fullscreen(con2, false); | ||
364 | } | ||
365 | |||
366 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
367 | struct sway_container *focus = seat_get_focus(seat); | ||
368 | struct sway_container *vis1 = container_parent( | ||
369 | seat_get_focus_inactive(seat, container_parent(con1, C_OUTPUT)), | ||
370 | C_WORKSPACE); | ||
371 | struct sway_container *vis2 = container_parent( | ||
372 | seat_get_focus_inactive(seat, container_parent(con2, C_OUTPUT)), | ||
373 | C_WORKSPACE); | ||
374 | |||
375 | char *stored_prev_name = NULL; | ||
376 | if (prev_workspace_name) { | ||
377 | stored_prev_name = strdup(prev_workspace_name); | ||
378 | } | ||
379 | |||
380 | swap_places(con1, con2); | ||
381 | |||
382 | if (!workspace_is_visible(vis1)) { | ||
383 | seat_set_focus(seat, seat_get_focus_inactive(seat, vis1)); | ||
384 | } | ||
385 | if (!workspace_is_visible(vis2)) { | ||
386 | seat_set_focus(seat, seat_get_focus_inactive(seat, vis2)); | ||
387 | } | ||
388 | |||
389 | swap_focus(con1, con2, seat, focus); | ||
390 | |||
391 | if (stored_prev_name) { | ||
392 | free(prev_workspace_name); | ||
393 | prev_workspace_name = stored_prev_name; | ||
394 | } | ||
395 | |||
396 | if (fs1) { | ||
397 | container_set_fullscreen(con2, true); | ||
398 | } | ||
399 | if (fs2) { | ||
400 | container_set_fullscreen(con1, true); | ||
401 | } | ||
402 | } | ||
diff --git a/sway/tree/view.c b/sway/tree/view.c index ba4a880f..2870d4f5 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include "sway/input/seat.h" | 18 | #include "sway/input/seat.h" |
19 | #include "sway/tree/arrange.h" | 19 | #include "sway/tree/arrange.h" |
20 | #include "sway/tree/container.h" | 20 | #include "sway/tree/container.h" |
21 | #include "sway/tree/layout.h" | ||
22 | #include "sway/tree/view.h" | 21 | #include "sway/tree/view.h" |
23 | #include "sway/tree/workspace.h" | 22 | #include "sway/tree/workspace.h" |
24 | #include "sway/config.h" | 23 | #include "sway/config.h" |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 93c4b3d3..d930826e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -665,3 +665,38 @@ void workspace_add_floating(struct sway_container *workspace, | |||
665 | container_set_dirty(workspace); | 665 | container_set_dirty(workspace); |
666 | container_set_dirty(con); | 666 | container_set_dirty(con); |
667 | } | 667 | } |
668 | |||
669 | void workspace_remove_gaps(struct sway_container *ws) { | ||
670 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
671 | return; | ||
672 | } | ||
673 | if (ws->current_gaps == 0) { | ||
674 | return; | ||
675 | } | ||
676 | |||
677 | ws->width += ws->current_gaps * 2; | ||
678 | ws->height += ws->current_gaps * 2; | ||
679 | ws->x -= ws->current_gaps; | ||
680 | ws->y -= ws->current_gaps; | ||
681 | ws->current_gaps = 0; | ||
682 | } | ||
683 | |||
684 | void workspace_add_gaps(struct sway_container *ws) { | ||
685 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
686 | return; | ||
687 | } | ||
688 | if (ws->current_gaps > 0) { | ||
689 | return; | ||
690 | } | ||
691 | bool should_apply = | ||
692 | config->edge_gaps || (config->smart_gaps && ws->children->length > 1); | ||
693 | if (!should_apply) { | ||
694 | return; | ||
695 | } | ||
696 | |||
697 | ws->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner; | ||
698 | ws->x += ws->current_gaps; | ||
699 | ws->y += ws->current_gaps; | ||
700 | ws->width -= 2 * ws->current_gaps; | ||
701 | ws->height -= 2 * ws->current_gaps; | ||
702 | } | ||