aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-26 12:05:16 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-26 12:05:16 +1000
commit5dbbab7bdc56fc513eea2f9a39d722859a3b0c2e (patch)
tree2aad57ba7f7eec9fdb51b98859f6da826a4d39a1 /sway/commands
parentMerge pull request #2488 from RyanDwyer/separate-gaps-functions (diff)
downloadsway-5dbbab7bdc56fc513eea2f9a39d722859a3b0c2e.tar.gz
sway-5dbbab7bdc56fc513eea2f9a39d722859a3b0c2e.tar.zst
sway-5dbbab7bdc56fc513eea2f9a39d722859a3b0c2e.zip
Remove layout.c
When we have type safety we'll need to have functions for workspace_add_tiling and so on. This means the existing container functions will be just for containers, so they are being moved to container.c. At this point layout.c doesn't contain much else, so I've relocated everything and removed the file. * container_swap and its static functions have been moved to the swap command and made static. * container_recursive_resize has been moved to the resize command and made static. * The following have been moved to container.c: * container_handle_fullscreen_reparent * container_insert_child * container_add_sibling * container_add_child * container_remove_child * container_replace_child * container_split * enum movement_direction and sway_dir_to_wlr have been moved to util.c. Side note: Several commands included layout.h which then included root.h. With layout.h gone, root.h has to be included by those commands.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/exec_always.c1
-rw-r--r--sway/commands/floating.c1
-rw-r--r--sway/commands/focus.c2
-rw-r--r--sway/commands/fullscreen.c1
-rw-r--r--sway/commands/hide_edge_borders.c1
-rw-r--r--sway/commands/move.c1
-rw-r--r--sway/commands/output.c1
-rw-r--r--sway/commands/resize.c21
-rw-r--r--sway/commands/show_marks.c1
-rw-r--r--sway/commands/sticky.c1
-rw-r--r--sway/commands/swap.c128
-rw-r--r--sway/commands/unmark.c1
-rw-r--r--sway/commands/urgent.c1
13 files changed, 155 insertions, 6 deletions
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
13static bool parse_movement_direction(const char *name, 15static 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
11struct cmd_results *cmd_fullscreen(int argc, char **argv) { 10struct 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
6static void _configure_view(struct sway_container *con, void *data) { 7static void _configure_view(struct sway_container *con, void *data) {
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 2744b354..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
23static const char *expected_syntax = 24static const char *expected_syntax =
24 "Expected 'move <left|right|up|down> <[px] px>' or " 25 "Expected 'move <left|right|up|down> <[px] px>' or "
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
162static 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
162static void resize_tiled(struct sway_container *parent, int amount, 183static 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
10static const char* EXPECTED_SYNTAX = 13static 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
16static 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
42static 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
70static 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
13static bool test_con_id(struct sway_container *container, void *con_id) { 139static 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
10struct cmd_results *cmd_urgent(int argc, char **argv) { 9struct cmd_results *cmd_urgent(int argc, char **argv) {