sway/tree: Simplify sway_node teardown

A sway_node may end up being referenced in either a queued transaction,
pending transaction or as a dirty node. To manage this, the transaction
system has been responsible for destroying containers, workspaces and
outputs at the end of their last referenced transaction.

This significantly complicates the teardown flow of surfaces and
outputs. Instead, remove the node from transactions and dirty lists so
that the callsite can remove and free the node immediately.
This commit is contained in:
Kenny Levinsen 2025-05-26 14:19:17 +02:00 committed by Simon Ser
parent 4f59eeef05
commit e28e6484e8
16 changed files with 125 additions and 149 deletions

View file

@ -2,6 +2,7 @@
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "sway/desktop/transaction.h"
#include "sway/ipc-server.h"
#include "sway/layers.h"
#include "sway/output.h"
@ -235,7 +236,7 @@ static void output_evacuate(struct sway_output *output) {
}
if (workspace_num_sticky_containers(workspace) == 0) {
workspace_begin_destroy(workspace);
workspace_destroy(workspace);
continue;
}
}
@ -253,27 +254,6 @@ static void output_evacuate(struct sway_output *output) {
}
}
void output_destroy(struct sway_output *output) {
if (!sway_assert(output->node.destroying,
"Tried to free output which wasn't marked as destroying")) {
return;
}
if (!sway_assert(output->wlr_output == NULL,
"Tried to free output which still had a wlr_output")) {
return;
}
if (!sway_assert(output->node.ntxnrefs == 0, "Tried to free output "
"which is still referenced by transactions")) {
return;
}
destroy_scene_layers(output);
list_free(output->workspaces);
list_free(output->current.workspaces);
wlr_color_transform_unref(output->color_transform);
free(output);
}
void output_disable(struct sway_output *output) {
if (!sway_assert(output->enabled, "Expected an enabled output")) {
return;
@ -295,15 +275,24 @@ void output_disable(struct sway_output *output) {
output_evacuate(output);
}
void output_begin_destroy(struct sway_output *output) {
void output_destroy(struct sway_output *output) {
if (!sway_assert(!output->enabled, "Expected a disabled output")) {
return;
}
sway_log(SWAY_DEBUG, "Destroying output '%s'", output->wlr_output->name);
wl_signal_emit_mutable(&output->node.events.destroy, &output->node);
output->node.destroying = true;
node_set_dirty(&output->node);
transaction_remove_node(&output->node);
if (!sway_assert(output->node.ntxnrefs == 0, "Tried to free output "
"which is still referenced by transactions")) {
return;
}
destroy_scene_layers(output);
list_free(output->workspaces);
list_free(output->current.workspaces);
wlr_color_transform_unref(output->color_transform);
free(output);
}
struct sway_output *output_from_wlr_output(struct wlr_output *output) {