diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-30 10:31:21 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-03-30 10:47:19 -0400 |
commit | 01af34391267e91461a4ab7a1234dd58f45d2c93 (patch) | |
tree | ae5197dabda270035b383d45b5c113afab2ebfbd /sway/tree/layout.c | |
parent | Fix crash when override redirect views close (diff) | |
download | sway-01af34391267e91461a4ab7a1234dd58f45d2c93.tar.gz sway-01af34391267e91461a4ab7a1234dd58f45d2c93.tar.zst sway-01af34391267e91461a4ab7a1234dd58f45d2c93.zip |
Destroy empty workspaces when moving away
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index dc0ee5b4..97007888 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/tree/view.h" | 12 | #include "sway/tree/view.h" |
13 | #include "sway/input/seat.h" | 13 | #include "sway/input/seat.h" |
14 | #include "sway/ipc-server.h" | ||
14 | #include "list.h" | 15 | #include "list.h" |
15 | #include "log.h" | 16 | #include "log.h" |
16 | 17 | ||
@@ -121,6 +122,42 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
121 | return parent; | 122 | return parent; |
122 | } | 123 | } |
123 | 124 | ||
125 | struct sway_container *container_reap_empty(struct sway_container *container) { | ||
126 | if (!sway_assert(container, "reaping null container")) { | ||
127 | return NULL; | ||
128 | } | ||
129 | while (container->children->length == 0 && container->type == C_CONTAINER) { | ||
130 | wlr_log(L_DEBUG, "Container: Destroying container '%p'", container); | ||
131 | struct sway_container *parent = container->parent; | ||
132 | container_destroy(container); | ||
133 | container = parent; | ||
134 | } | ||
135 | return container; | ||
136 | } | ||
137 | |||
138 | void container_move_to(struct sway_container* container, | ||
139 | struct sway_container* destination) { | ||
140 | if (container == destination | ||
141 | || container_has_anscestor(container, destination)) { | ||
142 | return; | ||
143 | } | ||
144 | struct sway_container *old_parent = container_remove_child(container); | ||
145 | container->width = container->height = 0; | ||
146 | struct sway_container *new_parent = | ||
147 | container_add_sibling(destination, container); | ||
148 | if (destination->type == C_WORKSPACE) { | ||
149 | // If the workspace only has one child after adding one, it | ||
150 | // means that the workspace was just initialized. | ||
151 | // TODO: Consider floating views in this test | ||
152 | if (destination->children->length == 1) { | ||
153 | ipc_event_workspace(NULL, destination, "init"); | ||
154 | } | ||
155 | } | ||
156 | old_parent = container_reap_empty(old_parent); | ||
157 | arrange_windows(old_parent, -1, -1); | ||
158 | arrange_windows(new_parent, -1, -1); | ||
159 | } | ||
160 | |||
124 | enum sway_container_layout container_get_default_layout( | 161 | enum sway_container_layout container_get_default_layout( |
125 | struct sway_container *output) { | 162 | struct sway_container *output) { |
126 | /* TODO WLR | 163 | /* TODO WLR |