fix some segfaults

This commit is contained in:
Tony Crisci 2018-03-31 18:52:02 -04:00
parent 2aec85bf24
commit eda425fdab
3 changed files with 19 additions and 11 deletions

View file

@ -94,6 +94,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
// TODO handle workspace switch in the seat? // TODO handle workspace switch in the seat?
bool set_focus = bool set_focus =
focus != NULL &&
(focus == con || container_has_child(con, focus)) && (focus == con || container_has_child(con, focus)) &&
con->type != C_WORKSPACE; con->type != C_WORKSPACE;
@ -103,12 +104,13 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
struct sway_container *next_focus = NULL; struct sway_container *next_focus = NULL;
while (next_focus == NULL) { while (next_focus == NULL) {
next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW); next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW);
parent = parent->parent;
if (next_focus == NULL && parent->type == C_WORKSPACE) { if (next_focus == NULL && parent->type == C_WORKSPACE) {
next_focus = parent; next_focus = parent;
break; break;
} }
parent = parent->parent;
} }
// the structure change might have caused it to move up to the top of // the structure change might have caused it to move up to the top of
@ -440,7 +442,8 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat,
wl_list_for_each(current, &seat->focus_stack, link) { wl_list_for_each(current, &seat->focus_stack, link) {
parent = current->container->parent; parent = current->container->parent;
if (current->container == container) { if (current->container == container &&
(type == C_TYPES || container->type == type)) {
return current->container; return current->container;
} }

View file

@ -69,11 +69,11 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
if (cont->children != NULL) { if (cont->children != NULL) {
// remove children until there are no more, container_destroy calls // remove children until there are no more, container_destroy calls
// container_remove_child, which removes child from this container // container_remove_child, which removes child from this container
while (cont->children->length != 0) { while (cont->children != NULL && cont->children->length != 0) {
container_destroy(cont->children->items[0]); struct sway_container *child = cont->children->items[0];
container_remove_child(child);
container_destroy(child);
} }
list_free(cont->children);
cont->children = NULL;
} }
if (cont->marks) { if (cont->marks) {
list_foreach(cont->marks, free); list_foreach(cont->marks, free);
@ -85,13 +85,17 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
if (cont->name) { if (cont->name) {
free(cont->name); free(cont->name);
} }
list_free(cont->children);
cont->children = NULL;
free(cont); free(cont);
return parent; return parent;
} }
struct sway_container *container_destroy(struct sway_container *cont) { struct sway_container *container_destroy(struct sway_container *cont) {
cont = _container_destroy(cont); struct sway_container *parent = _container_destroy(cont);
return container_reap_empty(cont->parent); parent = container_reap_empty(parent);
arrange_windows(&root_container, -1, -1);
return parent;
} }
struct sway_container *container_output_create( struct sway_container *container_output_create(
@ -409,7 +413,8 @@ bool find_child_func(struct sway_container *con, void *data) {
bool container_has_child(struct sway_container *con, bool container_has_child(struct sway_container *con,
struct sway_container *child) { struct sway_container *child) {
if (child->type == C_VIEW || child->children->length == 0) { if (child == NULL || child->type == C_VIEW ||
child->children->length == 0) {
return false; return false;
} }
return container_find(con, find_child_func, child); return container_find(con, find_child_func, child);

View file

@ -106,11 +106,11 @@ void container_add_child(struct sway_container *parent,
} }
struct sway_container *container_reap_empty(struct sway_container *container) { struct sway_container *container_reap_empty(struct sway_container *container) {
if (!sway_assert(container, "reaping null container")) { if (container == NULL) {
return NULL; return NULL;
} }
wlr_log(L_DEBUG, "reaping %p %s", container, container->name); wlr_log(L_DEBUG, "reaping %p %s", container, container->name);
while (container != &root_container && container->children->length == 0) { while (container->type != C_VIEW && container != &root_container && container->children->length == 0) {
if (container->type == C_WORKSPACE) { if (container->type == C_WORKSPACE) {
if (!workspace_is_visible(container)) { if (!workspace_is_visible(container)) {
struct sway_container *parent = container->parent; struct sway_container *parent = container->parent;