Fix crash when deleting last child in a tabbed or stacked container

There was no `current` child because the container was destroyed. This
makes it fall back to looking in the parent's current children list.
master
Ryan Dwyer 7 years ago
parent b11c9199a6
commit 32b865e610

@ -118,6 +118,17 @@ struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
struct sway_container *seat_get_active_child(struct sway_seat *seat,
struct sway_container *container);
/**
* Return the immediate child of container which was most recently focused, with
* fallback to selecting the child in the parent's `current` (rendered) children
* list.
*
* This is useful for when a tabbed container and its children are destroyed but
* still being rendered, and we have to render an appropriate child.
*/
struct sway_container *seat_get_active_current_child(struct sway_seat *seat,
struct sway_container *container);
/**
* Iterate over the focus-inactive children of the container calling the
* function on each.

@ -713,7 +713,7 @@ static void render_container_tabbed(struct sway_output *output,
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat);
struct sway_container *current = seat_get_active_child(seat, con);
struct sway_container *current = seat_get_active_current_child(seat, con);
struct border_colors *current_colors = NULL;
struct sway_container_state *pstate = &con->current;
@ -756,6 +756,7 @@ static void render_container_tabbed(struct sway_output *output,
}
// Render surface and left/right/bottom borders
if (current) {
if (current->type == C_VIEW) {
render_view(output, damage, current, current_colors);
} else {
@ -763,6 +764,7 @@ static void render_container_tabbed(struct sway_output *output,
parent_focused || current == focus);
}
}
}
/**
* Render a container's children using the L_STACKED layout.
@ -775,7 +777,7 @@ static void render_container_stacked(struct sway_output *output,
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat);
struct sway_container *current = seat_get_active_child(seat, con);
struct sway_container *current = seat_get_active_current_child(seat, con);
struct border_colors *current_colors = NULL;
struct sway_container_state *pstate = &con->current;
@ -812,6 +814,7 @@ static void render_container_stacked(struct sway_output *output,
}
// Render surface and left/right/bottom borders
if (current) {
if (current->type == C_VIEW) {
render_view(output, damage, current, current_colors);
} else {
@ -819,6 +822,7 @@ static void render_container_stacked(struct sway_output *output,
parent_focused || current == focus);
}
}
}
static void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,

@ -829,6 +829,18 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat,
return NULL;
}
struct sway_container *seat_get_active_current_child(struct sway_seat *seat,
struct sway_container *container) {
struct sway_container *child = seat_get_active_child(seat, container);
if (child) {
return child;
}
if (container->current.children->length == 1) {
return container->current.children->items[0];
}
return NULL;
}
struct sway_container *seat_get_focus(struct sway_seat *seat) {
if (!seat->has_focus) {
return NULL;

Loading…
Cancel
Save