diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-15 19:40:40 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-15 19:40:40 +1000 |
commit | fe803b89a7ecee7f737ad82bfe0bab441c163156 (patch) | |
tree | 76bf683cbff6e29285059e2ebd4e60192b6ef938 /sway/commands/swap.c | |
parent | Merge pull request #2831 from swaywm/move-output-docs (diff) | |
download | sway-fe803b89a7ecee7f737ad82bfe0bab441c163156.tar.gz sway-fe803b89a7ecee7f737ad82bfe0bab441c163156.tar.zst sway-fe803b89a7ecee7f737ad82bfe0bab441c163156.zip |
Fix crash in swap command
When swapping containers that are in the root of the workspace, parent
will be NULL.
Diffstat (limited to 'sway/commands/swap.c')
-rw-r--r-- | sway/commands/swap.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sway/commands/swap.c b/sway/commands/swap.c index e7f9cbea..d8ffe78c 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c | |||
@@ -22,6 +22,7 @@ static void swap_places(struct sway_container *con1, | |||
22 | temp->width = con1->width; | 22 | temp->width = con1->width; |
23 | temp->height = con1->height; | 23 | temp->height = con1->height; |
24 | temp->parent = con1->parent; | 24 | temp->parent = con1->parent; |
25 | temp->workspace = con1->workspace; | ||
25 | 26 | ||
26 | con1->x = con2->x; | 27 | con1->x = con2->x; |
27 | con1->y = con2->y; | 28 | con1->y = con2->y; |
@@ -34,8 +35,18 @@ static void swap_places(struct sway_container *con1, | |||
34 | con2->height = temp->height; | 35 | con2->height = temp->height; |
35 | 36 | ||
36 | int temp_index = container_sibling_index(con1); | 37 | int temp_index = container_sibling_index(con1); |
37 | container_insert_child(con2->parent, con1, container_sibling_index(con2)); | 38 | if (con2->parent) { |
38 | container_insert_child(temp->parent, con2, temp_index); | 39 | container_insert_child(con2->parent, con1, |
40 | container_sibling_index(con2)); | ||
41 | } else { | ||
42 | workspace_insert_tiling(con2->workspace, con1, | ||
43 | container_sibling_index(con2)); | ||
44 | } | ||
45 | if (temp->parent) { | ||
46 | container_insert_child(temp->parent, con2, temp_index); | ||
47 | } else { | ||
48 | workspace_insert_tiling(temp->workspace, con2, temp_index); | ||
49 | } | ||
39 | 50 | ||
40 | free(temp); | 51 | free(temp); |
41 | } | 52 | } |