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/render.c | 2 +- sway/desktop/transaction.c | 39 +++++++++++++-------------------------- sway/desktop/xdg_shell.c | 6 +++--- sway/desktop/xwayland.c | 8 ++++---- 4 files changed, 21 insertions(+), 34 deletions(-) (limited to 'sway/desktop') diff --git a/sway/desktop/render.c b/sway/desktop/render.c index fee19a33..3343fb31 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -957,7 +957,7 @@ static void render_floating(struct sway_output *soutput, } for (int k = 0; k < ws->current.floating->length; ++k) { struct sway_container *floater = ws->current.floating->items[k]; - if (floater->fullscreen_mode != FULLSCREEN_NONE) { + if (floater->pending.fullscreen_mode != FULLSCREEN_NONE) { continue; } render_floating_container(soutput, damage, floater); 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(); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 14880dcd..4c13f91f 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -70,13 +70,13 @@ static void popup_unconstrain(struct sway_xdg_popup *popup) { struct sway_view *view = popup->child.view; struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup; - struct sway_output *output = view->container->workspace->output; + struct sway_output *output = view->container->pending.workspace->output; // the output box expressed in the coordinate system of the toplevel parent // of the popup struct wlr_box output_toplevel_sx_box = { - .x = output->lx - view->container->content_x, - .y = output->ly - view->container->content_y, + .x = output->lx - view->container->pending.content_x, + .y = output->ly - view->container->pending.content_y, .width = output->width, .height = output->height, }; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 4cd5f9d0..3ed65083 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -527,10 +527,10 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { view->natural_height = ev->height; container_floating_resize_and_center(view->container); - configure(view, view->container->content_x, - view->container->content_y, - view->container->content_width, - view->container->content_height); + configure(view, view->container->pending.content_x, + view->container->pending.content_y, + view->container->pending.content_width, + view->container->pending.content_height); node_set_dirty(&view->container->node); } else { configure(view, view->container->current.content_x, -- cgit v1.2.3