Refactor destroy functions and save workspaces when there's no outputs

This changes the destroy functions to the following:

* output_begin_destroy
* output_destroy
* workspace_begin_destroy
* workspace_destroy
* container_begin_destroy
* container_destroy
* view_begin_destroy
* view_destroy

The terminology was `destroy` and `free`, and it has been changed to
`begin_destroy` and `destroy` respectively.

When the last output is disconnected, its workspaces will now be stashed
in the root. Upon connection of a new output they will be restored.

There is a new function `workspace_consider_destroy` which decides
whether the given workspace should be destroyed or not (ie. empty and
not visible).

Calling container_begin_destroy will no longer automatically reap the
parents. In some places we want to reap the parents and in some we
don't, so this is left to the caller.

container_reap_empty_recursive and container_reap_empty have been
combined into one function and it will recurse up the tree.
This commit is contained in:
Ryan Dwyer 2018-08-20 15:54:30 +10:00
parent f53c28d52a
commit b6058703fa
19 changed files with 267 additions and 308 deletions

View file

@ -35,7 +35,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
wl_signal_init(&view->events.unmap);
}
void view_free(struct sway_view *view) {
void view_destroy(struct sway_view *view) {
if (!sway_assert(view->surface == NULL, "Tried to free mapped view")) {
return;
}
@ -75,14 +75,14 @@ void view_free(struct sway_view *view) {
* destroying flag will make the view get freed when the transaction is
* finished.
*/
void view_destroy(struct sway_view *view) {
void view_begin_destroy(struct sway_view *view) {
if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
return;
}
view->destroying = true;
if (!view->swayc) {
view_free(view);
view_destroy(view);
}
}
@ -560,7 +560,9 @@ void view_unmap(struct sway_view *view) {
}
bool was_fullscreen = view->swayc->is_fullscreen;
struct sway_container *surviving_ancestor = container_destroy(view->swayc);
struct sway_container *parent = view->swayc->parent;
container_begin_destroy(view->swayc);
struct sway_container *surviving_ancestor = container_reap_empty(parent);
// If the workspace wasn't reaped
if (surviving_ancestor && surviving_ancestor->type >= C_WORKSPACE) {