Fix #5643, #5064: rounding issues in floating-point -> integer conversions

Currently, various floating-point expressions involving
the coordinates of borders, titlebars and content surfaces
are directly assigned to integers, and so they are rounded
towards zero.

This results in off-by-one distances between these elements
when the signs of their coordinates differ.

Fixed by wrapping these expressions with a call to
floor before the assignment.
This commit is contained in:
Dimitris Triantafyllidis 2021-02-22 13:32:07 +02:00 committed by Tudor Brindus
parent 1a6471be17
commit aac1582ea9
2 changed files with 19 additions and 19 deletions

View file

@ -105,8 +105,8 @@ static bool get_surface_box(struct surface_iterator_data *data,
data->rotation); data->rotation);
struct wlr_box box = { struct wlr_box box = {
.x = data->ox + _sx, .x = floor(data->ox + _sx),
.y = data->oy + _sy, .y = floor(data->oy + _sy),
.width = sw, .width = sw,
.height = sh, .height = sh,
}; };

View file

@ -346,8 +346,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
if (state->border_left) { if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = state->x; box.x = floor(state->x);
box.y = state->content_y; box.y = floor(state->content_y);
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->content_height; box.height = state->content_height;
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -365,8 +365,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = state->content_x + state->content_width; box.x = floor(state->content_x + state->content_width);
box.y = state->content_y; box.y = floor(state->content_y);
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->content_height; box.height = state->content_height;
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -380,8 +380,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = state->x; box.x = floor(state->x);
box.y = state->content_y + state->content_height; box.y = floor(state->content_y + state->content_height);
box.width = state->width; box.width = state->width;
box.height = state->border_thickness; box.height = state->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -662,8 +662,8 @@ static void render_top_border(struct sway_output *output,
// Child border - top edge // Child border - top edge
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = state->x; box.x = floor(state->x);
box.y = state->y; box.y = floor(state->y);
box.width = state->width; box.width = state->width;
box.height = state->border_thickness; box.height = state->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
@ -718,8 +718,8 @@ static void render_containers_linear(struct sway_output *output,
} }
if (state->border == B_NORMAL) { if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, state->x, render_titlebar(output, damage, child, floor(state->x),
state->y, state->width, colors, floor(state->y), state->width, colors,
title_texture, marks_texture); title_texture, marks_texture);
} else if (state->border == B_PIXEL) { } else if (state->border == B_PIXEL) {
render_top_border(output, damage, child, colors); render_top_border(output, damage, child, colors);
@ -773,7 +773,7 @@ static void render_containers_tabbed(struct sway_output *output,
marks_texture = child->marks_unfocused; marks_texture = child->marks_unfocused;
} }
int x = cstate->x + tab_width * i; int x = floor(cstate->x + tab_width * i);
// Make last tab use the remaining width of the parent // Make last tab use the remaining width of the parent
if (i == parent->children->length - 1) { if (i == parent->children->length - 1) {
@ -886,8 +886,8 @@ static void render_container(struct sway_output *output,
struct parent_data data = { struct parent_data data = {
.layout = con->current.layout, .layout = con->current.layout,
.box = { .box = {
.x = con->current.x, .x = floor(con->current.x),
.y = con->current.y, .y = floor(con->current.y),
.width = con->current.width, .width = con->current.width,
.height = con->current.height, .height = con->current.height,
}, },
@ -903,8 +903,8 @@ static void render_workspace(struct sway_output *output,
struct parent_data data = { struct parent_data data = {
.layout = ws->current.layout, .layout = ws->current.layout,
.box = { .box = {
.x = ws->current.x, .x = floor(ws->current.x),
.y = ws->current.y, .y = floor(ws->current.y),
.width = ws->current.width, .width = ws->current.width,
.height = ws->current.height, .height = ws->current.height,
}, },
@ -938,8 +938,8 @@ static void render_floating_container(struct sway_output *soutput,
} }
if (con->current.border == B_NORMAL) { if (con->current.border == B_NORMAL) {
render_titlebar(soutput, damage, con, con->current.x, render_titlebar(soutput, damage, con, floor(con->current.x),
con->current.y, con->current.width, colors, floor(con->current.y), con->current.width, colors,
title_texture, marks_texture); title_texture, marks_texture);
} else if (con->current.border == B_PIXEL) { } else if (con->current.border == B_PIXEL) {
render_top_border(soutput, damage, con, colors); render_top_border(soutput, damage, con, colors);