tree/container: add placeholder leaf scaffolding

Add is_placeholder and swallows fields plus
container_init_border_rects, used by upcoming append_layout
support. No behaviour change.
This commit is contained in:
codegax 2026-04-25 14:00:00 -06:00
parent c857ca3a97
commit 850e50b9b7
2 changed files with 31 additions and 4 deletions

View file

@ -141,11 +141,19 @@ struct sway_container {
list_t *marks; // char *
// append_layout placeholder: view==NULL, swallows holds matchers for the
// view that should be installed here. swallows_json retains the original
// i3-shaped array so IPC can echo it verbatim for round-trip.
bool is_placeholder;
list_t *swallows; // struct criteria *
struct {
struct wl_signal destroy;
} events;
};
void container_init_border_rects(struct sway_container *c, bool *failed);
struct sway_container *container_create(struct sway_view *view);
void container_destroy(struct sway_container *con);

View file

@ -8,6 +8,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_subcompositor.h>
#include "sway/config.h"
#include "sway/criteria.h"
#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
@ -43,6 +44,13 @@ static struct wlr_scene_rect *alloc_rect_node(struct wlr_scene_tree *parent,
return rect;
}
void container_init_border_rects(struct sway_container *c, bool *failed) {
c->border.top = alloc_rect_node(c->border.tree, failed);
c->border.bottom = alloc_rect_node(c->border.tree, failed);
c->border.left = alloc_rect_node(c->border.tree, failed);
c->border.right = alloc_rect_node(c->border.tree, failed);
}
struct sway_container *container_create(struct sway_view *view) {
struct sway_container *c = calloc(1, sizeof(struct sway_container));
if (!c) {
@ -87,10 +95,7 @@ struct sway_container *container_create(struct sway_view *view) {
if (view) {
// only containers with views can have borders
c->border.top = alloc_rect_node(c->border.tree, &failed);
c->border.bottom = alloc_rect_node(c->border.tree, &failed);
c->border.left = alloc_rect_node(c->border.tree, &failed);
c->border.right = alloc_rect_node(c->border.tree, &failed);
container_init_border_rects(c, &failed);
}
if (!failed && !scene_descriptor_assign(&c->scene_tree->node,
@ -460,6 +465,13 @@ void container_destroy(struct sway_container *con) {
list_free_items_and_destroy(con->marks);
if (con->swallows) {
for (int i = 0; i < con->swallows->length; ++i) {
criteria_destroy(con->swallows->items[i]);
}
list_free(con->swallows);
}
if (con->view && con->view->container == con) {
con->view->container = NULL;
if (con->view->destroying) {
@ -509,11 +521,18 @@ void container_reap_empty(struct sway_container *con) {
if (con->view) {
return;
}
// Placeholders are intentionally view-less; do not reap them.
if (con->is_placeholder) {
return;
}
struct sway_workspace *ws = con->pending.workspace;
while (con) {
if (con->pending.children->length) {
return;
}
if (con->is_placeholder) {
return;
}
struct sway_container *parent = con->pending.parent;
container_begin_destroy(con);
con = parent;