diff options
author | emersion <contact@emersion.fr> | 2018-05-27 17:07:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-27 17:07:09 +0100 |
commit | 0743b21cc89141c6783210a1f20b6b372b24ae59 (patch) | |
tree | f9703ad693145350eec52bfeb10732ed47267391 | |
parent | Merge pull request #2040 from RedSoxFan/cmd-swap (diff) | |
parent | Don't move empty workspaces when output is destroyed (diff) | |
download | sway-0743b21cc89141c6783210a1f20b6b372b24ae59.tar.gz sway-0743b21cc89141c6783210a1f20b6b372b24ae59.tar.zst sway-0743b21cc89141c6783210a1f20b6b372b24ae59.zip |
Merge pull request #2052 from emersion/output-destroy-empty-workspace
Don't move empty workspaces when output is destroyed
-rw-r--r-- | sway/tree/container.c | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index f29a9adc..8694eb33 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -176,45 +176,6 @@ static void _container_destroy(struct sway_container *cont) { | |||
176 | free(cont); | 176 | free(cont); |
177 | } | 177 | } |
178 | 178 | ||
179 | static struct sway_container *container_output_destroy( | ||
180 | struct sway_container *output) { | ||
181 | if (!sway_assert(output, "cannot destroy null output")) { | ||
182 | return NULL; | ||
183 | } | ||
184 | |||
185 | if (output->children->length > 0) { | ||
186 | // TODO save workspaces when there are no outputs. | ||
187 | // TODO also check if there will ever be no outputs except for exiting | ||
188 | // program | ||
189 | if (root_container.children->length > 1) { | ||
190 | int p = root_container.children->items[0] == output; | ||
191 | // Move workspace from this output to another output | ||
192 | while (output->children->length) { | ||
193 | struct sway_container *child = output->children->items[0]; | ||
194 | container_remove_child(child); | ||
195 | container_add_child(root_container.children->items[p], child); | ||
196 | } | ||
197 | container_sort_workspaces(root_container.children->items[p]); | ||
198 | arrange_output(root_container.children->items[p]); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | wl_list_remove(&output->sway_output->destroy.link); | ||
203 | wl_list_remove(&output->sway_output->mode.link); | ||
204 | wl_list_remove(&output->sway_output->transform.link); | ||
205 | wl_list_remove(&output->sway_output->scale.link); | ||
206 | |||
207 | wl_list_remove(&output->sway_output->damage_destroy.link); | ||
208 | wl_list_remove(&output->sway_output->damage_frame.link); | ||
209 | |||
210 | // clear the wlr_output reference to this container | ||
211 | output->sway_output->wlr_output->data = NULL; | ||
212 | |||
213 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | ||
214 | _container_destroy(output); | ||
215 | return &root_container; | ||
216 | } | ||
217 | |||
218 | static struct sway_container *container_workspace_destroy( | 179 | static struct sway_container *container_workspace_destroy( |
219 | struct sway_container *workspace) { | 180 | struct sway_container *workspace) { |
220 | if (!sway_assert(workspace, "cannot destroy null workspace")) { | 181 | if (!sway_assert(workspace, "cannot destroy null workspace")) { |
@@ -232,7 +193,7 @@ static struct sway_container *container_workspace_destroy( | |||
232 | // destroy the WS if there are no children (TODO check for floating) | 193 | // destroy the WS if there are no children (TODO check for floating) |
233 | wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); | 194 | wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); |
234 | ipc_event_workspace(workspace, NULL, "empty"); | 195 | ipc_event_workspace(workspace, NULL, "empty"); |
235 | } else { | 196 | } else if (output) { |
236 | // Move children to a different workspace on this output | 197 | // Move children to a different workspace on this output |
237 | struct sway_container *new_workspace = NULL; | 198 | struct sway_container *new_workspace = NULL; |
238 | // TODO move floating | 199 | // TODO move floating |
@@ -253,11 +214,61 @@ static struct sway_container *container_workspace_destroy( | |||
253 | free(workspace->sway_workspace); | 214 | free(workspace->sway_workspace); |
254 | _container_destroy(workspace); | 215 | _container_destroy(workspace); |
255 | 216 | ||
256 | output_damage_whole(output->sway_output); | 217 | if (output) { |
218 | output_damage_whole(output->sway_output); | ||
219 | } | ||
257 | 220 | ||
258 | return parent; | 221 | return parent; |
259 | } | 222 | } |
260 | 223 | ||
224 | static struct sway_container *container_output_destroy( | ||
225 | struct sway_container *output) { | ||
226 | if (!sway_assert(output, "cannot destroy null output")) { | ||
227 | return NULL; | ||
228 | } | ||
229 | |||
230 | if (output->children->length > 0) { | ||
231 | // TODO save workspaces when there are no outputs. | ||
232 | // TODO also check if there will ever be no outputs except for exiting | ||
233 | // program | ||
234 | if (root_container.children->length > 1) { | ||
235 | // Move workspace from this output to another output | ||
236 | struct sway_container *other_output = | ||
237 | root_container.children->items[0]; | ||
238 | if (other_output == output) { | ||
239 | other_output = root_container.children->items[1]; | ||
240 | } | ||
241 | |||
242 | while (output->children->length) { | ||
243 | struct sway_container *workspace = output->children->items[0]; | ||
244 | container_remove_child(workspace); | ||
245 | if (workspace->children->length > 0) { | ||
246 | container_add_child(other_output, workspace); | ||
247 | } else { | ||
248 | container_workspace_destroy(workspace); | ||
249 | } | ||
250 | } | ||
251 | container_sort_workspaces(other_output); | ||
252 | arrange_output(other_output); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | wl_list_remove(&output->sway_output->destroy.link); | ||
257 | wl_list_remove(&output->sway_output->mode.link); | ||
258 | wl_list_remove(&output->sway_output->transform.link); | ||
259 | wl_list_remove(&output->sway_output->scale.link); | ||
260 | |||
261 | wl_list_remove(&output->sway_output->damage_destroy.link); | ||
262 | wl_list_remove(&output->sway_output->damage_frame.link); | ||
263 | |||
264 | // clear the wlr_output reference to this container | ||
265 | output->sway_output->wlr_output->data = NULL; | ||
266 | |||
267 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | ||
268 | _container_destroy(output); | ||
269 | return &root_container; | ||
270 | } | ||
271 | |||
261 | static void container_root_finish(struct sway_container *con) { | 272 | static void container_root_finish(struct sway_container *con) { |
262 | wlr_log(L_ERROR, "TODO: destroy the root container"); | 273 | wlr_log(L_ERROR, "TODO: destroy the root container"); |
263 | } | 274 | } |