view: Use pending rather than current dimensions in positioning

This should fix race conditions (such as #671) when multiple
position changes occur in rapid succession.
This commit is contained in:
John Lindgren 2023-02-09 01:27:30 -05:00 committed by Consolatis
parent 0181e5f4ae
commit cf6eb29ef5

View file

@ -310,10 +310,10 @@ view_store_natural_geometry(struct view *view)
* natural_geometry width/height may still be zero in which case we set * natural_geometry width/height may still be zero in which case we set
* some fallback values. This is the case with foot and Qt applications. * some fallback values. This is the case with foot and Qt applications.
*/ */
if (wlr_box_empty(&view->current)) { if (wlr_box_empty(&view->pending)) {
set_fallback_geometry(view); set_fallback_geometry(view);
} else { } else {
view->natural_geometry = view->current; view->natural_geometry = view->pending;
} }
} }
@ -322,8 +322,8 @@ view_center(struct view *view)
{ {
assert(view); assert(view);
int x, y; int x, y;
if (view_compute_centered_position(view, view->current.width, if (view_compute_centered_position(view, view->pending.width,
view->current.height, &x, &y)) { view->pending.height, &x, &y)) {
view_move(view, x, y); view_move(view, x, y);
} }
} }
@ -417,8 +417,8 @@ view_apply_region_geometry(struct view *view)
geo.width -= margin.left + margin.right; geo.width -= margin.left + margin.right;
geo.height -= margin.top + margin.bottom; geo.height -= margin.top + margin.bottom;
if (view->current.width == geo.width if (view->pending.width == geo.width
&& view->current.height == geo.height) { && view->pending.height == geo.height) {
/* move horizontally/vertically without changing size */ /* move horizontally/vertically without changing size */
view_move(view, geo.x, geo.y); view_move(view, geo.x, geo.y);
} else { } else {
@ -439,8 +439,8 @@ view_apply_tiled_geometry(struct view *view, struct output *output)
} }
struct wlr_box dst = view_get_edge_snap_box(view, output, view->tiled); struct wlr_box dst = view_get_edge_snap_box(view, output, view->tiled);
if (view->current.width == dst.width if (view->pending.width == dst.width
&& view->current.height == dst.height) { && view->pending.height == dst.height) {
/* move horizontally/vertically without changing size */ /* move horizontally/vertically without changing size */
view_move(view, dst.x, dst.y); view_move(view, dst.x, dst.y);
} else { } else {
@ -755,7 +755,7 @@ view_adjust_for_layout_change(struct view *view)
} else if (!view_apply_special_geometry(view)) { } else if (!view_apply_special_geometry(view)) {
/* reposition view if it's offscreen */ /* reposition view if it's offscreen */
if (!wlr_output_layout_intersects(layout, NULL, if (!wlr_output_layout_intersects(layout, NULL,
&view->current)) { &view->pending)) {
view_center(view); view_center(view);
} }
} }
@ -811,17 +811,17 @@ view_move_to_edge(struct view *view, const char *direction)
int x = 0, y = 0; int x = 0, y = 0;
if (!strcasecmp(direction, "left")) { if (!strcasecmp(direction, "left")) {
x = usable.x + margin.left + rc.gap; x = usable.x + margin.left + rc.gap;
y = view->current.y; y = view->pending.y;
} else if (!strcasecmp(direction, "up")) { } else if (!strcasecmp(direction, "up")) {
x = view->current.x; x = view->pending.x;
y = usable.y + margin.top + rc.gap; y = usable.y + margin.top + rc.gap;
} else if (!strcasecmp(direction, "right")) { } else if (!strcasecmp(direction, "right")) {
x = usable.x + usable.width - view->current.width x = usable.x + usable.width - view->pending.width
- margin.right - rc.gap; - margin.right - rc.gap;
y = view->current.y; y = view->pending.y;
} else if (!strcasecmp(direction, "down")) { } else if (!strcasecmp(direction, "down")) {
x = view->current.x; x = view->pending.x;
y = usable.y + usable.height - view->current.height y = usable.y + usable.height - view->pending.height
- margin.bottom - rc.gap; - margin.bottom - rc.gap;
} else { } else {
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge");