]> git.mdlowis.com Git - proto/labwc.git/commitdiff
regions: perform rounding more carefully
authorJohn Lindgren <john@jlindgren.net>
Sat, 21 Oct 2023 18:02:21 +0000 (14:02 -0400)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 21 Oct 2023 18:49:04 +0000 (20:49 +0200)
Add percentages (x + width, y + height) before scaling so that there is
no gap between regions due to rounding variations

src/regions.c

index 353ae255f7b66f5332c1d0f7cdc56ab76d421126..ad05cf2e93af26b3c96d19d4716d0fcbbedc31f7 100644 (file)
@@ -208,10 +208,19 @@ regions_update_geometry(struct output *output)
        wl_list_for_each(region, &output->regions, link) {
                geo = &region->geo;
                perc = &region->percentage;
-               geo->x = usable.x + usable.width * perc->x / 100;
-               geo->y = usable.y + usable.height * perc->y / 100;
-               geo->width = usable.width * perc->width / 100;
-               geo->height = usable.height * perc->height / 100;
+               /*
+                * Add percentages (x + width, y + height) before scaling
+                * so that there is no gap between regions due to rounding
+                * variations
+                */
+               int left = usable.width * perc->x / 100;
+               int right = usable.width * (perc->x + perc->width) / 100;
+               int top = usable.height * perc->y / 100;
+               int bottom = usable.height * (perc->y + perc->height) / 100;
+               geo->x = usable.x + left;
+               geo->y = usable.y + top;
+               geo->width = right - left;
+               geo->height = bottom - top;
                region->center.x = geo->x + geo->width / 2;
                region->center.y = geo->y + geo->height / 2;
        }