aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-08-05 14:35:50 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-08-06 11:30:17 +0900
commita9e31d925fb34005ad3b13cff855b6d192753e78 (patch)
treeb348e46b23db023e20a8b031539677b9cb1a0134
parentcmd_opacity: add relative opacity changes (diff)
downloadsway-a9e31d925fb34005ad3b13cff855b6d192753e78.tar.gz
sway-a9e31d925fb34005ad3b13cff855b6d192753e78.tar.zst
sway-a9e31d925fb34005ad3b13cff855b6d192753e78.zip
cmd_swap: add floating support
For feature parity with i3 4.17, this just adds floating container support to the swap command
-rw-r--r--sway/commands/swap.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index a4a4108d..697de226 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -24,6 +24,7 @@ static void swap_places(struct sway_container *con1,
24 temp->height_fraction = con1->height_fraction; 24 temp->height_fraction = con1->height_fraction;
25 temp->parent = con1->parent; 25 temp->parent = con1->parent;
26 temp->workspace = con1->workspace; 26 temp->workspace = con1->workspace;
27 bool temp_floating = container_is_floating(con1);
27 28
28 con1->x = con2->x; 29 con1->x = con2->x;
29 con1->y = con2->y; 30 con1->y = con2->y;
@@ -43,12 +44,16 @@ static void swap_places(struct sway_container *con1,
43 if (con2->parent) { 44 if (con2->parent) {
44 container_insert_child(con2->parent, con1, 45 container_insert_child(con2->parent, con1,
45 container_sibling_index(con2)); 46 container_sibling_index(con2));
47 } else if (container_is_floating(con2)) {
48 workspace_add_floating(con2->workspace, con1);
46 } else { 49 } else {
47 workspace_insert_tiling(con2->workspace, con1, 50 workspace_insert_tiling(con2->workspace, con1,
48 container_sibling_index(con2)); 51 container_sibling_index(con2));
49 } 52 }
50 if (temp->parent) { 53 if (temp->parent) {
51 container_insert_child(temp->parent, con2, temp_index); 54 container_insert_child(temp->parent, con2, temp_index);
55 } else if (temp_floating) {
56 workspace_add_floating(temp->workspace, con2);
52 } else { 57 } else {
53 workspace_insert_tiling(temp->workspace, con2, temp_index); 58 workspace_insert_tiling(temp->workspace, con2, temp_index);
54 } 59 }
@@ -99,15 +104,27 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
99 "Cannot swap ancestor and descendant")) { 104 "Cannot swap ancestor and descendant")) {
100 return; 105 return;
101 } 106 }
102 if (!sway_assert(!container_is_floating(con1)
103 && !container_is_floating(con2),
104 "Swapping with floating containers is not supported")) {
105 return;
106 }
107 107
108 sway_log(SWAY_DEBUG, "Swapping containers %zu and %zu", 108 sway_log(SWAY_DEBUG, "Swapping containers %zu and %zu",
109 con1->node.id, con2->node.id); 109 con1->node.id, con2->node.id);
110 110
111 bool scratch1 = con1->scratchpad;
112 bool hidden1 = container_is_scratchpad_hidden(con1);
113 bool scratch2 = con2->scratchpad;
114 bool hidden2 = container_is_scratchpad_hidden(con2);
115 if (scratch1) {
116 if (hidden1) {
117 root_scratchpad_show(con1);
118 }
119 root_scratchpad_remove_container(con1);
120 }
121 if (scratch2) {
122 if (hidden2) {
123 root_scratchpad_show(con2);
124 }
125 root_scratchpad_remove_container(con2);
126 }
127
111 enum sway_fullscreen_mode fs1 = con1->fullscreen_mode; 128 enum sway_fullscreen_mode fs1 = con1->fullscreen_mode;
112 enum sway_fullscreen_mode fs2 = con2->fullscreen_mode; 129 enum sway_fullscreen_mode fs2 = con2->fullscreen_mode;
113 if (fs1) { 130 if (fs1) {
@@ -149,6 +166,19 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
149 seat->prev_workspace_name = stored_prev_name; 166 seat->prev_workspace_name = stored_prev_name;
150 } 167 }
151 168
169 if (scratch1) {
170 root_scratchpad_add_container(con2, NULL);
171 if (!hidden1) {
172 root_scratchpad_show(con2);
173 }
174 }
175 if (scratch2) {
176 root_scratchpad_add_container(con1, NULL);
177 if (!hidden2) {
178 root_scratchpad_show(con1);
179 }
180 }
181
152 if (fs1) { 182 if (fs1) {
153 container_set_fullscreen(con2, fs1); 183 container_set_fullscreen(con2, fs1);
154 } 184 }
@@ -221,9 +251,6 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
221 || container_has_ancestor(other, current)) { 251 || container_has_ancestor(other, current)) {
222 error = cmd_results_new(CMD_FAILURE, 252 error = cmd_results_new(CMD_FAILURE,
223 "Cannot swap ancestor and descendant"); 253 "Cannot swap ancestor and descendant");
224 } else if (container_is_floating(current) || container_is_floating(other)) {
225 error = cmd_results_new(CMD_FAILURE,
226 "Swapping with floating containers is not supported");
227 } 254 }
228 255
229 free(value); 256 free(value);
@@ -237,9 +264,13 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
237 if (root->fullscreen_global) { 264 if (root->fullscreen_global) {
238 arrange_root(); 265 arrange_root();
239 } else { 266 } else {
240 arrange_node(node_get_parent(&current->node)); 267 struct sway_node *current_parent = node_get_parent(&current->node);
241 if (node_get_parent(&other->node) != node_get_parent(&current->node)) { 268 struct sway_node *other_parent = node_get_parent(&other->node);
242 arrange_node(node_get_parent(&other->node)); 269 if (current_parent) {
270 arrange_node(current_parent);
271 }
272 if (other_parent && current_parent != other_parent) {
273 arrange_node(other_parent);
243 } 274 }
244 } 275 }
245 276