aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Dimitris Triantafyllidis <dtr@localhost.localdomain>2021-02-22 13:32:07 +0200
committerLibravatar Tudor Brindus <me@tbrindus.ca>2021-02-22 21:23:35 -0500
commitaac1582ea90897a25408a520b8f3bde0552a69cc (patch)
tree1d65c61f6287ba1be3a03d3f492d17ae5b046cd0 /sway
parentview: Set parent for view_child subsurfaces on init (diff)
downloadsway-aac1582ea90897a25408a520b8f3bde0552a69cc.tar.gz
sway-aac1582ea90897a25408a520b8f3bde0552a69cc.tar.zst
sway-aac1582ea90897a25408a520b8f3bde0552a69cc.zip
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.
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/output.c4
-rw-r--r--sway/desktop/render.c34
2 files changed, 19 insertions, 19 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 691a285d..7871a136 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -105,8 +105,8 @@ static bool get_surface_box(struct surface_iterator_data *data,
105 data->rotation); 105 data->rotation);
106 106
107 struct wlr_box box = { 107 struct wlr_box box = {
108 .x = data->ox + _sx, 108 .x = floor(data->ox + _sx),
109 .y = data->oy + _sy, 109 .y = floor(data->oy + _sy),
110 .width = sw, 110 .width = sw,
111 .height = sh, 111 .height = sh,
112 }; 112 };
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index f314db73..20832cc4 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -346,8 +346,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
346 if (state->border_left) { 346 if (state->border_left) {
347 memcpy(&color, colors->child_border, sizeof(float) * 4); 347 memcpy(&color, colors->child_border, sizeof(float) * 4);
348 premultiply_alpha(color, con->alpha); 348 premultiply_alpha(color, con->alpha);
349 box.x = state->x; 349 box.x = floor(state->x);
350 box.y = state->content_y; 350 box.y = floor(state->content_y);
351 box.width = state->border_thickness; 351 box.width = state->border_thickness;
352 box.height = state->content_height; 352 box.height = state->content_height;
353 scale_box(&box, output_scale); 353 scale_box(&box, output_scale);
@@ -365,8 +365,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
365 memcpy(&color, colors->child_border, sizeof(float) * 4); 365 memcpy(&color, colors->child_border, sizeof(float) * 4);
366 } 366 }
367 premultiply_alpha(color, con->alpha); 367 premultiply_alpha(color, con->alpha);
368 box.x = state->content_x + state->content_width; 368 box.x = floor(state->content_x + state->content_width);
369 box.y = state->content_y; 369 box.y = floor(state->content_y);
370 box.width = state->border_thickness; 370 box.width = state->border_thickness;
371 box.height = state->content_height; 371 box.height = state->content_height;
372 scale_box(&box, output_scale); 372 scale_box(&box, output_scale);
@@ -380,8 +380,8 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
380 memcpy(&color, colors->child_border, sizeof(float) * 4); 380 memcpy(&color, colors->child_border, sizeof(float) * 4);
381 } 381 }
382 premultiply_alpha(color, con->alpha); 382 premultiply_alpha(color, con->alpha);
383 box.x = state->x; 383 box.x = floor(state->x);
384 box.y = state->content_y + state->content_height; 384 box.y = floor(state->content_y + state->content_height);
385 box.width = state->width; 385 box.width = state->width;
386 box.height = state->border_thickness; 386 box.height = state->border_thickness;
387 scale_box(&box, output_scale); 387 scale_box(&box, output_scale);
@@ -662,8 +662,8 @@ static void render_top_border(struct sway_output *output,
662 // Child border - top edge 662 // Child border - top edge
663 memcpy(&color, colors->child_border, sizeof(float) * 4); 663 memcpy(&color, colors->child_border, sizeof(float) * 4);
664 premultiply_alpha(color, con->alpha); 664 premultiply_alpha(color, con->alpha);
665 box.x = state->x; 665 box.x = floor(state->x);
666 box.y = state->y; 666 box.y = floor(state->y);
667 box.width = state->width; 667 box.width = state->width;
668 box.height = state->border_thickness; 668 box.height = state->border_thickness;
669 scale_box(&box, output_scale); 669 scale_box(&box, output_scale);
@@ -718,8 +718,8 @@ static void render_containers_linear(struct sway_output *output,
718 } 718 }
719 719
720 if (state->border == B_NORMAL) { 720 if (state->border == B_NORMAL) {
721 render_titlebar(output, damage, child, state->x, 721 render_titlebar(output, damage, child, floor(state->x),
722 state->y, state->width, colors, 722 floor(state->y), state->width, colors,
723 title_texture, marks_texture); 723 title_texture, marks_texture);
724 } else if (state->border == B_PIXEL) { 724 } else if (state->border == B_PIXEL) {
725 render_top_border(output, damage, child, colors); 725 render_top_border(output, damage, child, colors);
@@ -773,7 +773,7 @@ static void render_containers_tabbed(struct sway_output *output,
773 marks_texture = child->marks_unfocused; 773 marks_texture = child->marks_unfocused;
774 } 774 }
775 775
776 int x = cstate->x + tab_width * i; 776 int x = floor(cstate->x + tab_width * i);
777 777
778 // Make last tab use the remaining width of the parent 778 // Make last tab use the remaining width of the parent
779 if (i == parent->children->length - 1) { 779 if (i == parent->children->length - 1) {
@@ -886,8 +886,8 @@ static void render_container(struct sway_output *output,
886 struct parent_data data = { 886 struct parent_data data = {
887 .layout = con->current.layout, 887 .layout = con->current.layout,
888 .box = { 888 .box = {
889 .x = con->current.x, 889 .x = floor(con->current.x),
890 .y = con->current.y, 890 .y = floor(con->current.y),
891 .width = con->current.width, 891 .width = con->current.width,
892 .height = con->current.height, 892 .height = con->current.height,
893 }, 893 },
@@ -903,8 +903,8 @@ static void render_workspace(struct sway_output *output,
903 struct parent_data data = { 903 struct parent_data data = {
904 .layout = ws->current.layout, 904 .layout = ws->current.layout,
905 .box = { 905 .box = {
906 .x = ws->current.x, 906 .x = floor(ws->current.x),
907 .y = ws->current.y, 907 .y = floor(ws->current.y),
908 .width = ws->current.width, 908 .width = ws->current.width,
909 .height = ws->current.height, 909 .height = ws->current.height,
910 }, 910 },
@@ -938,8 +938,8 @@ static void render_floating_container(struct sway_output *soutput,
938 } 938 }
939 939
940 if (con->current.border == B_NORMAL) { 940 if (con->current.border == B_NORMAL) {
941 render_titlebar(soutput, damage, con, con->current.x, 941 render_titlebar(soutput, damage, con, floor(con->current.x),
942 con->current.y, con->current.width, colors, 942 floor(con->current.y), con->current.width, colors,
943 title_texture, marks_texture); 943 title_texture, marks_texture);
944 } else if (con->current.border == B_PIXEL) { 944 } else if (con->current.border == B_PIXEL) {
945 render_top_border(soutput, damage, con, colors); 945 render_top_border(soutput, damage, con, colors);