summaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-12-22 12:36:20 +0100
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-12-28 14:58:17 +0100
commit6750975b9f91d3e0aa632add0f56fc4611b0853a (patch)
tree27b2b8d85c070a8f8c00aa5b5e561e9fd6d977ca /sway/layout.c
parentarrange_windows_r: Bring parent coordinates into layout calculations. (diff)
downloadsway-6750975b9f91d3e0aa632add0f56fc4611b0853a.tar.gz
sway-6750975b9f91d3e0aa632add0f56fc4611b0853a.tar.zst
sway-6750975b9f91d3e0aa632add0f56fc4611b0853a.zip
arrange_windows_r: Round pixels to match reality, fixes calculations.
If the width or height of a container can't be evenly distributed to its children, then the layout algorithm still thought it got it right (due to using decimals) which caused a gap of one or more pixels for some window arrangements. This is fixed by this patch by first rounding off the width and height (so that decimals are never introduced) and then adjusting the last view in a container to fill the remaining pixels (which now is counted correctly due to the decimals being removed). Also, due to the way gaps are implemented, an odd sized gap can never be aligned properly, so just adjust to closest even number.
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/sway/layout.c b/sway/layout.c
index 8c253fe4..d5fdbf0b 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -1,5 +1,6 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <math.h>
3#include <wlc/wlc.h> 4#include <wlc/wlc.h>
4#include "extensions.h" 5#include "extensions.h"
5#include "layout.h" 6#include "layout.h"
@@ -379,6 +380,11 @@ void update_geometry(swayc_t *container) {
379 swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE); 380 swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE);
380 swayc_t *op = ws->parent; 381 swayc_t *op = ws->parent;
381 int gap = container->is_floating ? 0 : swayc_gap(container); 382 int gap = container->is_floating ? 0 : swayc_gap(container);
383 if (gap % 2 != 0) {
384 // because gaps are implemented as "half sized margins" it's currently
385 // not possible to align views properly with odd sized gaps.
386 gap -= 1;
387 }
382 388
383 struct wlc_geometry geometry = { 389 struct wlc_geometry geometry = {
384 .origin = { 390 .origin = {
@@ -430,6 +436,11 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
430 width = container->width; 436 width = container->width;
431 height = container->height; 437 height = container->height;
432 } 438 }
439 // pixels are indivisable. if we don't round the pixels, then the view
440 // calculations will be off (e.g. 50.5 + 50.5 = 101, but in reality it's
441 // 50 + 50 = 100). doing it here cascades properly to all width/height/x/y.
442 width = floor(width);
443 height = floor(height);
433 444
434 sway_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", container, 445 sway_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", container,
435 container->name, container->width, container->height, container->x, container->y); 446 container->name, container->width, container->height, container->x, container->y);
@@ -539,7 +550,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
539 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); 550 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale);
540 child->x = x; 551 child->x = x;
541 child->y = y; 552 child->y = y;
542 arrange_windows_r(child, child->width * scale, height); 553 if (i == container->children->length - 1) {
554 double remaining_width = container->x + width - x;
555 arrange_windows_r(child, remaining_width, height);
556 } else {
557 arrange_windows_r(child, child->width * scale, height);
558 }
543 x += child->width; 559 x += child->width;
544 } 560 }
545 } 561 }
@@ -566,7 +582,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
566 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); 582 sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale);
567 child->x = x; 583 child->x = x;
568 child->y = y; 584 child->y = y;
569 arrange_windows_r(child, width, child->height * scale); 585 if (i == container->children->length - 1) {
586 double remaining_height = container->y + height - y;
587 arrange_windows_r(child, width, remaining_height);
588 } else {
589 arrange_windows_r(child, width, child->height * scale);
590 }
570 y += child->height; 591 y += child->height;
571 } 592 }
572 } 593 }