diff options
author | Kenny Levinsen <kl@kl.wtf> | 2021-02-12 23:22:51 +0100 |
---|---|---|
committer | Tudor Brindus <me@tbrindus.ca> | 2021-02-16 22:05:00 -0500 |
commit | a047b5ee4a2a67d30d93641ff86531d54b8e0879 (patch) | |
tree | 271666c6254e4fabf943c1153224059411a5ce56 /sway/input | |
parent | 28cadf558090854ace1df1a0a64f5fbc059541c0 (diff) |
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.
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 16 | ||||
-rw-r--r-- | sway/input/seat.c | 20 | ||||
-rw-r--r-- | sway/input/seatop_default.c | 32 | ||||
-rw-r--r-- | sway/input/seatop_move_floating.c | 6 | ||||
-rw-r--r-- | sway/input/seatop_move_tiling.c | 38 | ||||
-rw-r--r-- | sway/input/seatop_resize_floating.c | 32 | ||||
-rw-r--r-- | sway/input/seatop_resize_tiling.c | 24 |
7 files changed, 84 insertions, 84 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index b40e0299..cbb5c6e9 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -824,8 +824,8 @@ static void check_constraint_region(struct sway_cursor *cursor) { struct sway_container *con = view->container; - double sx = cursor->cursor->x - con->content_x + view->geometry.x; - double sy = cursor->cursor->y - con->content_y + view->geometry.y; + double sx = cursor->cursor->x - con->pending.content_x + view->geometry.x; + double sy = cursor->cursor->y - con->pending.content_y + view->geometry.y; if (!pixman_region32_contains_point(region, floor(sx), floor(sy), NULL)) { @@ -836,8 +836,8 @@ static void check_constraint_region(struct sway_cursor *cursor) { double sy = (boxes[0].y1 + boxes[0].y2) / 2.; wlr_cursor_warp_closest(cursor->cursor, NULL, - sx + con->content_x - view->geometry.x, - sy + con->content_y - view->geometry.y); + sx + con->pending.content_x - view->geometry.x, + sy + con->pending.content_y - view->geometry.y); cursor_rebase(cursor); } @@ -1157,8 +1157,8 @@ void cursor_warp_to_container(struct sway_cursor *cursor, return; } - double x = container->x + container->width / 2.0; - double y = container->y + container->height / 2.0; + double x = container->pending.x + container->pending.width / 2.0; + double y = container->pending.y + container->pending.height / 2.0; wlr_cursor_warp(cursor->cursor, NULL, x, y); cursor_unhide(cursor); @@ -1271,8 +1271,8 @@ static void warp_to_constraint_cursor_hint(struct sway_cursor *cursor) { struct sway_view *view = view_from_wlr_surface(constraint->surface); struct sway_container *con = view->container; - double lx = sx + con->content_x - view->geometry.x; - double ly = sy + con->content_y - view->geometry.y; + double lx = sx + con->pending.content_x - view->geometry.x; + double ly = sy + con->pending.content_y - view->geometry.y; wlr_cursor_warp(cursor->cursor, NULL, lx, ly); diff --git a/sway/input/seat.c b/sway/input/seat.c index 3c0d9a29..e6e1d4fb 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -309,8 +309,8 @@ static void handle_seat_node_destroy(struct wl_listener *listener, void *data) { // Setting focus_inactive focus = seat_get_focus_inactive(seat, &root->node); seat_set_raw_focus(seat, next_focus); - if (focus->type == N_CONTAINER && focus->sway_container->workspace) { - seat_set_raw_focus(seat, &focus->sway_container->workspace->node); + if (focus->type == N_CONTAINER && focus->sway_container->pending.workspace) { + seat_set_raw_focus(seat, &focus->sway_container->pending.workspace->node); } seat_set_raw_focus(seat, focus); } @@ -1086,7 +1086,7 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { } struct sway_workspace *new_workspace = node->type == N_WORKSPACE ? - node->sway_workspace : node->sway_container->workspace; + node->sway_workspace : node->sway_container->pending.workspace; struct sway_container *container = node->type == N_CONTAINER ? node->sway_container : NULL; @@ -1135,10 +1135,10 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) { // Put the container parents on the focus stack, then the workspace, then // the focused container. if (container) { - struct sway_container *parent = container->parent; + struct sway_container *parent = container->pending.parent; while (parent) { seat_set_raw_focus(seat, &parent->node); - parent = parent->parent; + parent = parent->pending.parent; } } if (new_workspace) { @@ -1327,7 +1327,7 @@ struct sway_container *seat_get_focus_inactive_tiling(struct sway_seat *seat, struct sway_node *node = current->node; if (node->type == N_CONTAINER && !container_is_floating_or_child(node->sway_container) && - node->sway_container->workspace == workspace) { + node->sway_container->pending.workspace == workspace) { return node->sway_container; } } @@ -1344,7 +1344,7 @@ struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, struct sway_node *node = current->node; if (node->type == N_CONTAINER && container_is_floating_or_child(node->sway_container) && - node->sway_container->workspace == workspace) { + node->sway_container->pending.workspace == workspace) { return node->sway_container; } } @@ -1392,7 +1392,7 @@ struct sway_workspace *seat_get_focused_workspace(struct sway_seat *seat) { return NULL; } if (focus->type == N_CONTAINER) { - return focus->sway_container->workspace; + return focus->sway_container->pending.workspace; } if (focus->type == N_WORKSPACE) { return focus->sway_workspace; @@ -1405,8 +1405,8 @@ struct sway_workspace *seat_get_last_known_workspace(struct sway_seat *seat) { wl_list_for_each(current, &seat->focus_stack, link) { struct sway_node *node = current->node; if (node->type == N_CONTAINER && - node->sway_container->workspace) { - return node->sway_container->workspace; + node->sway_container->pending.workspace) { + return node->sway_container->pending.workspace; } else if (node->type == N_WORKSPACE) { return node->sway_workspace; } diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c index 10d97309..f9eb8c8a 100644 --- a/sway/input/seatop_default.c +++ b/sway/input/seatop_default.c @@ -60,7 +60,7 @@ static bool edge_is_external(struct sway_container *cont, enum wlr_edges edge) { return false; } } - cont = cont->parent; + cont = cont->pending.parent; } return true; } @@ -70,25 +70,25 @@ static enum wlr_edges find_edge(struct sway_container *cont, if (!cont->view || (surface && cont->view->surface != surface)) { return WLR_EDGE_NONE; } - if (cont->border == B_NONE || !cont->border_thickness || - cont->border == B_CSD) { + if (cont->pending.border == B_NONE || !cont->pending.border_thickness || + cont->pending.border == B_CSD) { return WLR_EDGE_NONE; } - if (cont->fullscreen_mode) { + if (cont->pending.fullscreen_mode) { return WLR_EDGE_NONE; } enum wlr_edges edge = 0; - if (cursor->cursor->x < cont->x + cont->border_thickness) { + if (cursor->cursor->x < cont->pending.x + cont->pending.border_thickness) { edge |= WLR_EDGE_LEFT; } - if (cursor->cursor->y < cont->y + cont->border_thickness) { + if (cursor->cursor->y < cont->pending.y + cont->pending.border_thickness) { edge |= WLR_EDGE_TOP; } - if (cursor->cursor->x >= cont->x + cont->width - cont->border_thickness) { + if (cursor->cursor->x >= cont->pending.x + cont->pending.width - cont->pending.border_thickness) { edge |= WLR_EDGE_RIGHT; } - if (cursor->cursor->y >= cont->y + cont->height - cont->border_thickness) { + if (cursor->cursor->y >= cont->pending.y + cont->pending.height - cont->pending.border_thickness) { edge |= WLR_EDGE_BOTTOM; } @@ -251,7 +251,7 @@ static void handle_tablet_tool_tip(struct sway_seat *seat, // Handle moving a tiling container if (config->tiling_drag && mod_pressed && !is_floating_or_child && - cont->fullscreen_mode == FULLSCREEN_NONE) { + cont->pending.fullscreen_mode == FULLSCREEN_NONE) { seatop_begin_move_tiling(seat, cont); return; } @@ -386,7 +386,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, struct sway_container *cont_to_focus = cont; enum sway_container_layout layout = container_parent_layout(cont); if (layout == L_TABBED || layout == L_STACKED) { - cont_to_focus = seat_get_focus_inactive_view(seat, &cont->parent->node); + cont_to_focus = seat_get_focus_inactive_view(seat, &cont->pending.parent->node); } seat_set_focus_container(seat, cont_to_focus); @@ -402,9 +402,9 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, BTN_LEFT : BTN_RIGHT; if (button == btn_resize) { edge = 0; - edge |= cursor->cursor->x > cont->x + cont->width / 2 ? + edge |= cursor->cursor->x > cont->pending.x + cont->pending.width / 2 ? WLR_EDGE_RIGHT : WLR_EDGE_LEFT; - edge |= cursor->cursor->y > cont->y + cont->height / 2 ? + edge |= cursor->cursor->y > cont->pending.y + cont->pending.height / 2 ? WLR_EDGE_BOTTOM : WLR_EDGE_TOP; const char *image = NULL; @@ -451,9 +451,9 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, if (mod_pressed && button == btn_resize) { struct sway_container *floater = container_toplevel_ancestor(cont); edge = 0; - edge |= cursor->cursor->x > floater->x + floater->width / 2 ? + edge |= cursor->cursor->x > floater->pending.x + floater->pending.width / 2 ? WLR_EDGE_RIGHT : WLR_EDGE_LEFT; - edge |= cursor->cursor->y > floater->y + floater->height / 2 ? + edge |= cursor->cursor->y > floater->pending.y + floater->pending.height / 2 ? WLR_EDGE_BOTTOM : WLR_EDGE_TOP; seatop_begin_resize_floating(seat, floater, edge); return; @@ -463,7 +463,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, // Handle moving a tiling container if (config->tiling_drag && (mod_pressed || on_titlebar) && state == WLR_BUTTON_PRESSED && !is_floating_or_child && - cont && cont->fullscreen_mode == FULLSCREEN_NONE) { + cont && cont->pending.fullscreen_mode == FULLSCREEN_NONE) { struct sway_container *focus = seat_get_focused_container(seat); bool focused = focus == cont || container_has_ancestor(focus, cont); if (on_titlebar && !focused) { @@ -674,7 +674,7 @@ static void handle_pointer_axis(struct sway_seat *seat, bool on_border = edge != WLR_EDGE_NONE; bool on_titlebar = cont && !on_border && !surface; bool on_titlebar_border = cont && on_border && - cursor->cursor->y < cont->content_y; + cursor->cursor->y < cont->pending.content_y; bool on_contents = cont && !on_border && surface; bool on_workspace = node && node->type == N_WORKSPACE; float scroll_factor = diff --git a/sway/input/seatop_move_floating.c b/sway/input/seatop_move_floating.c index 6683be21..ddcd4c53 100644 --- a/sway/input/seatop_move_floating.c +++ b/sway/input/seatop_move_floating.c @@ -15,7 +15,7 @@ static void finalize_move(struct sway_seat *seat) { // We "move" the container to its own location // so it discovers its output again. - container_floating_move_to(e->con, e->con->x, e->con->y); + container_floating_move_to(e->con, e->con->pending.x, e->con->pending.y); transaction_commit_dirty(); seatop_begin_default(seat); @@ -70,8 +70,8 @@ void seatop_begin_move_floating(struct sway_seat *seat, return; } e->con = con; - e->dx = cursor->cursor->x - con->x; - e->dy = cursor->cursor->y - con->y; + e->dx = cursor->cursor->x - con->pending.x; + e->dy = cursor->cursor->y - con->pending.y; seat->seatop_impl = &seatop_impl; seat->seatop_data = e; diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c index 7d9ecd8f..446612c6 100644 --- a/sway/input/seatop_move_tiling.c +++ b/sway/input/seatop_move_tiling.c @@ -120,8 +120,8 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { // Deny moving within own workspace if this is the only child struct sway_container *con = node->sway_container; - if (workspace_num_tiling_views(e->con->workspace) == 1 && - con->workspace == e->con->workspace) { + if (workspace_num_tiling_views(e->con->pending.workspace) == 1 && + con->pending.workspace == e->con->pending.workspace) { e->target_node = NULL; e->target_edge = WLR_EDGE_NONE; return; @@ -133,8 +133,8 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { enum wlr_edges edge = WLR_EDGE_NONE; enum sway_container_layout layout = container_parent_layout(con); struct wlr_box parent; - con->parent ? container_get_box(con->parent, &parent) : - workspace_get_box(con->workspace, &parent); + con->pending.parent ? container_get_box(con->pending.parent, &parent) : + workspace_get_box(con->pending.workspace, &parent); if (layout == L_HORIZ || layout == L_TABBED) { if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) { edge = WLR_EDGE_TOP; @@ -161,7 +161,7 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { desktop_damage_box(&e->drop_box); return; } - con = con->parent; + con = con->pending.parent; } // Use the hovered view - but we must be over the actual surface @@ -174,23 +174,23 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { } // Find the closest edge - size_t thickness = fmin(con->content_width, con->content_height) * 0.3; + size_t thickness = fmin(con->pending.content_width, con->pending.content_height) * 0.3; size_t closest_dist = INT_MAX; size_t dist; e->target_edge = WLR_EDGE_NONE; - if ((dist = cursor->cursor->y - con->y) < closest_dist) { + if ((dist = cursor->cursor->y - con->pending.y) < closest_dist) { closest_dist = dist; e->target_edge = WLR_EDGE_TOP; } - if ((dist = cursor->cursor->x - con->x) < closest_dist) { + if ((dist = cursor->cursor->x - con->pending.x) < closest_dist) { closest_dist = dist; e->target_edge = WLR_EDGE_LEFT; } - if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) { + if ((dist = con->pending.x + con->pending.width - cursor->cursor->x) < closest_dist) { closest_dist = dist; e->target_edge = WLR_EDGE_RIGHT; } - if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) { + if ((dist = con->pending.y + con->pending.height - cursor->cursor->y) < closest_dist) { closest_dist = dist; e->target_edge = WLR_EDGE_BOTTOM; } @@ -200,10 +200,10 @@ static void handle_motion_postthreshold(struct sway_seat *seat) { } e->target_node = node; - e->drop_box.x = con->content_x; - e->drop_box.y = con->content_y; - e->drop_box.width = con->content_width; - e->drop_box.height = con->content_height; + e->drop_box.x = con->pending.content_x; + e->drop_box.y = con->pending.content_y; + e->drop_box.width = con->pending.content_width; + e->drop_box.height = con->pending.content_height; resize_box(&e->drop_box, e->target_edge, thickness); desktop_damage_box(&e->drop_box); } @@ -234,11 +234,11 @@ static void finalize_move(struct sway_seat *seat) { } struct sway_container *con = e->con; - struct sway_container *old_parent = con->parent; - struct sway_workspace *old_ws = con->workspace; + struct sway_container *old_parent = con->pending.parent; + struct sway_workspace *old_ws = con->pending.workspace; struct sway_node *target_node = e->target_node; struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ? - target_node->sway_workspace : target_node->sway_container->workspace; + target_node->sway_workspace : target_node->sway_container->pending.workspace; enum wlr_edges edge = e->target_edge; int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT; bool swap = edge == WLR_EDGE_NONE && target_node->type == N_CONTAINER; @@ -285,8 +285,8 @@ static void finalize_move(struct sway_seat *seat) { int index = list_find(siblings, con); struct sway_container *sibling = index == 0 ? siblings->items[1] : siblings->items[index - 1]; - con->width = sibling->width; - con->height = sibling->height; + con->pending.width = sibling->pending.width; + con->pending.height = sibling->pending.height; con->width_fraction = sibling->width_fraction; con->height_fraction = sibling->height_fraction; } diff --git a/sway/input/seatop_resize_floating.c b/sway/input/seatop_resize_floating.c index 78dfe29f..8400a4b3 100644 --- a/sway/input/seatop_resize_floating.c +++ b/sway/input/seatop_resize_floating.c @@ -118,21 +118,21 @@ static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { // Determine the amounts we need to bump everything relative to the current // size. - int relative_grow_width = width - con->width; - int relative_grow_height = height - con->height; - int relative_grow_x = (e->ref_con_lx + grow_x) - con->x; - int relative_grow_y = (e->ref_con_ly + grow_y) - con->y; + int relative_grow_width = width - con->pending.width; + int relative_grow_height = height - con->pending.height; + int relative_grow_x = (e->ref_con_lx + grow_x) - con->pending.x; + int relative_grow_y = (e->ref_con_ly + grow_y) - con->pending.y; // Actually resize stuff - con->x += relative_grow_x; - con->y += relative_grow_y; - con->width += relative_grow_width; - con->height += relative_grow_height; + con->pending.x += relative_grow_x; + con->pending.y += relative_grow_y; + con->pending.width += relative_grow_width; + con->pending.height += relative_grow_height; - con->content_x += relative_grow_x; - con->content_y += relative_grow_y; - con->content_width += relative_grow_width; - con->content_height += relative_grow_height; + con->pending.content_x += relative_grow_x; + con->pending.content_y += relative_grow_y; + con->pending.content_width += relative_grow_width; + con->pending.content_height += relative_grow_height; arrange_container(con); transaction_commit_dirty(); @@ -169,10 +169,10 @@ void seatop_begin_resize_floating(struct sway_seat *seat, e->edge = edge == WLR_EDGE_NONE ? WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT : edge; e->ref_lx = seat->cursor->cursor->x; e->ref_ly = seat->cursor->cursor->y; - e->ref_con_lx = con->x; - e->ref_con_ly = con->y; - e->ref_width = con->width; - e->ref_height = con->height; + e->ref_con_lx = con->pending.x; + e->ref_con_ly = con->pending.y; + e->ref_width = con->pending.width; + e->ref_height = con->pending.height; seat->seatop_impl = &seatop_impl; seat->seatop_data = e; diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c index c5fe269e..869d11b5 100644 --- a/sway/input/seatop_resize_tiling.c +++ b/sway/input/seatop_resize_tiling.c @@ -53,19 +53,19 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, if (e->h_con) { container_set_resizing(e->h_con, false); container_set_resizing(e->h_sib, false); - if (e->h_con->parent) { - arrange_container(e->h_con->parent); + if (e->h_con->pending.parent) { + arrange_container(e->h_con->pending.parent); } else { - arrange_workspace(e->h_con->workspace); + arrange_workspace(e->h_con->pending.workspace); } } if (e->v_con) { container_set_resizing(e->v_con, false); container_set_resizing(e->v_sib, false); - if (e->v_con->parent) { - arrange_container(e->v_con->parent); + if (e->v_con->pending.parent) { + arrange_container(e->v_con->pending.parent); } else { - arrange_workspace(e->v_con->workspace); + arrange_workspace(e->v_con->pending.workspace); } } transaction_commit_dirty(); @@ -82,16 +82,16 @@ static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) { if (e->h_con) { if (e->edge & WLR_EDGE_LEFT) { - amount_x = (e->h_con_orig_width - moved_x) - e->h_con->width; + amount_x = (e->h_con_orig_width - moved_x) - e->h_con->pending.width; } else if (e->edge & WLR_EDGE_RIGHT) { - amount_x = (e->h_con_orig_width + moved_x) - e->h_con->width; + amount_x = (e->h_con_orig_width + moved_x) - e->h_con->pending.width; } } if (e->v_con) { if (e->edge & WLR_EDGE_TOP) { - amount_y = (e->v_con_orig_height - moved_y) - e->v_con->height; + amount_y = (e->v_con_orig_height - moved_y) - e->v_con->pending.height; } else if (e->edge & WLR_EDGE_BOTTOM) { - amount_y = (e->v_con_orig_height + moved_y) - e->v_con->height; + amount_y = (e->v_con_orig_height + moved_y) - e->v_con->pending.height; } } @@ -143,7 +143,7 @@ void seatop_begin_resize_tiling(struct sway_seat *seat, if (e->h_con) { container_set_resizing(e->h_con, true); container_set_resizing(e->h_sib, true); - e->h_con_orig_width = e->h_con->width; + e->h_con_orig_width = e->h_con->pending.width; } } if (edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) { @@ -154,7 +154,7 @@ void seatop_begin_resize_tiling(struct sway_seat *seat, if (e->v_con) { container_set_resizing(e->v_con, true); container_set_resizing(e->v_sib, true); - e->v_con_orig_height = e->v_con->height; + e->v_con_orig_height = e->v_con->pending.height; } } |