From a047b5ee4a2a67d30d93641ff86531d54b8e0879 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Fri, 12 Feb 2021 23:22:51 +0100 Subject: container: Move pending state to state struct Pending state is currently inlined directly in the container struct, while the current state is in a state struct. A side-effect of this is that it is not immediately obvious that pending double-buffered state is accessed, nor is it obvious what state is double-buffered. Instead, use the state struct for both current and pending. --- sway/desktop/transaction.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'sway/desktop/transaction.c') diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 9f488963..6c392bab 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -128,8 +128,8 @@ static void copy_workspace_state(struct sway_workspace *ws, // Set focused_inactive_child to the direct tiling child struct sway_container *focus = seat_get_focus_inactive_tiling(seat, ws); if (focus) { - while (focus->parent) { - focus = focus->parent; + while (focus->pending.parent) { + focus = focus->pending.parent; } } state->focused_inactive_child = focus; @@ -139,32 +139,19 @@ static void copy_container_state(struct sway_container *container, struct sway_transaction_instruction *instruction) { struct sway_container_state *state = &instruction->container_state; - state->layout = container->layout; - state->x = container->x; - state->y = container->y; - state->width = container->width; - state->height = container->height; - state->fullscreen_mode = container->fullscreen_mode; - state->parent = container->parent; - state->workspace = container->workspace; - state->border = container->border; - state->border_thickness = container->border_thickness; - state->border_top = container->border_top; - state->border_left = container->border_left; - state->border_right = container->border_right; - state->border_bottom = container->border_bottom; - state->content_x = container->content_x; - state->content_y = container->content_y; - state->content_width = container->content_width; - state->content_height = container->content_height; + if (state->children) { + list_free(state->children); + } + + memcpy(state, &container->pending, sizeof(struct sway_container_state)); if (!container->view) { - if (state->children) { - state->children->length = 0; - } else { - state->children = create_list(); - } - list_cat(state->children, container->children); + // We store a copy of the child list to avoid having it mutated after + // we copy the state. + state->children = create_list(); + list_cat(state->children, container->pending.children); + } else { + state->children = NULL; } struct sway_seat *seat = input_manager_current_seat(); -- cgit v1.2.3-54-g00ecf