diff options
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 746dbf1f..4db93ce8 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -33,12 +33,29 @@ static list_t *get_bfs_queue() { return bfs_queue; } +const char *container_type_to_str(enum sway_container_type type) { + switch (type) { + case C_ROOT: + return "C_ROOT"; + case C_OUTPUT: + return "C_OUTPUT"; + case C_WORKSPACE: + return "C_WORKSPACE"; + case C_CONTAINER: + return "C_CONTAINER"; + case C_VIEW: + return "C_VIEW"; + default: + return "C_UNKNOWN"; + } +} + static void notify_new_container(struct sway_container *container) { wl_signal_emit(&root_container.sway_root->events.new_container, container); ipc_event_window(container, "new"); } -static struct sway_container *container_create(enum sway_container_type type) { +struct sway_container *container_create(enum sway_container_type type) { // next id starts at 1 because 0 is assigned to root_container in layout.c static size_t next_id = 1; struct sway_container *c = calloc(1, sizeof(struct sway_container)); @@ -54,11 +71,12 @@ static struct sway_container *container_create(enum sway_container_type type) { } wl_signal_init(&c->events.destroy); + wl_signal_init(&c->events.reparent); return c; } -struct sway_container *container_destroy(struct sway_container *cont) { +static struct sway_container *_container_destroy(struct sway_container *cont) { if (cont == NULL) { return NULL; } @@ -66,13 +84,14 @@ struct sway_container *container_destroy(struct sway_container *cont) { wl_signal_emit(&cont->events.destroy, cont); struct sway_container *parent = cont->parent; - if (cont->children) { + if (cont->children != NULL) { // remove children until there are no more, container_destroy calls // container_remove_child, which removes child from this container - while (cont->children->length) { - container_destroy(cont->children->items[0]); + while (cont->children != NULL && cont->children->length != 0) { + struct sway_container *child = cont->children->items[0]; + container_remove_child(child); + container_destroy(child); } - list_free(cont->children); } if (cont->marks) { list_foreach(cont->marks, free); @@ -84,10 +103,19 @@ struct sway_container *container_destroy(struct sway_container *cont) { if (cont->name) { free(cont->name); } + list_free(cont->children); + cont->children = NULL; free(cont); return parent; } +struct sway_container *container_destroy(struct sway_container *cont) { + struct sway_container *parent = _container_destroy(cont); + parent = container_reap_empty(parent); + arrange_windows(&root_container, -1, -1); + return parent; +} + struct sway_container *container_output_create( struct sway_output *sway_output) { struct wlr_box size; @@ -144,7 +172,7 @@ struct sway_container *container_output_create( struct sway_seat *seat = NULL; wl_list_for_each(seat, &input_manager->seats, link) { if (!seat->has_focus) { - sway_seat_set_focus(seat, ws); + seat_set_focus(seat, ws); } } @@ -395,3 +423,17 @@ bool container_has_anscestor(struct sway_container *descendant, } return false; } + +static bool find_child_func(struct sway_container *con, void *data) { + struct sway_container *child = data; + return con == child; +} + +bool container_has_child(struct sway_container *con, + struct sway_container *child) { + if (child == NULL || child->type == C_VIEW || + child->children->length == 0) { + return false; + } + return container_find(con, find_child_func, child); +} |