mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 16:36:26 +01:00
fix more close segfaults
This commit is contained in:
parent
32ef182f47
commit
2c165e1288
5 changed files with 41 additions and 7 deletions
|
@ -134,6 +134,8 @@ struct sway_container *container_workspace_destroy(struct sway_container *contai
|
|||
struct sway_container *container_output_destroy(struct sway_container *container);
|
||||
struct sway_container *container_view_destroy(struct sway_container *container);
|
||||
|
||||
struct sway_container *container_close(struct sway_container *container);
|
||||
|
||||
// TODO move to layout.c
|
||||
struct sway_container *container_set_layout(struct sway_container *container,
|
||||
enum sway_container_layout layout);
|
||||
|
|
|
@ -19,11 +19,8 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
|
|||
"Can only kill views and containers with this command");
|
||||
break;
|
||||
case C_CONTAINER:
|
||||
con = container_destroy(con);
|
||||
arrange_windows(con, -1, -1);
|
||||
break;
|
||||
case C_VIEW:
|
||||
view_close(con->sway_view);
|
||||
container_close(con);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,10 +112,45 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
|
|||
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;
|
||||
}
|
||||
|
||||
static void container_close_func(struct sway_container *container, void *data) {
|
||||
if (container->type == C_VIEW) {
|
||||
view_close(container->sway_view);
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *container_close(struct sway_container *con) {
|
||||
if (!sway_assert(con != NULL, "container_close called with a NULL container")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (con->type) {
|
||||
case C_TYPES:
|
||||
wlr_log(L_ERROR, "tried to close an invalid container");
|
||||
break;
|
||||
case C_ROOT:
|
||||
wlr_log(L_ERROR, "tried to close the root container");
|
||||
break;
|
||||
case C_OUTPUT:
|
||||
container_output_destroy(con);
|
||||
break;
|
||||
case C_WORKSPACE:
|
||||
container_workspace_destroy(con);
|
||||
break;
|
||||
case C_CONTAINER:
|
||||
container_for_each_descendant_dfs(con, container_close_func, NULL);
|
||||
break;
|
||||
case C_VIEW:
|
||||
view_close(con->sway_view);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return con->parent;
|
||||
}
|
||||
|
||||
struct sway_container *container_output_create(
|
||||
struct sway_output *sway_output) {
|
||||
struct wlr_box size;
|
||||
|
|
|
@ -110,7 +110,7 @@ struct sway_container *container_reap_empty(struct sway_container *container) {
|
|||
wlr_log(L_DEBUG, "Reaping %p %s '%s'", container,
|
||||
container_type_to_str(container->type), container->name);
|
||||
while (container->type != C_ROOT && container->type != C_OUTPUT
|
||||
&& container->children->length == 0) {
|
||||
&& container->children && container->children->length == 0) {
|
||||
if (container->type == C_WORKSPACE) {
|
||||
if (!workspace_is_visible(container)) {
|
||||
struct sway_container *parent = container->parent;
|
||||
|
|
|
@ -84,7 +84,7 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
|
|||
}
|
||||
wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
|
||||
struct sway_container *parent = container_destroy(view);
|
||||
arrange_windows(parent, -1, -1);
|
||||
arrange_windows(&root_container, -1, -1);
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue