From 831f6680f41ab2ed91e5a17694bdee802cd1e789 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Mon, 28 Dec 2015 01:14:48 +0100 Subject: arrange_windows_r: Bring parent coordinates into layout calculations. This brings consistency into the algorithm (instead of resetting and then fetching again). --- sway/layout.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sway/layout.c b/sway/layout.c index d7265605..8c253fe4 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -434,7 +434,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { sway_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", container, container->name, container->width, container->height, container->x, container->y); - int x = 0, y = 0; + double x = 0, y = 0; switch (container->type) { case C_ROOT: for (i = 0; i < container->children->length; ++i) { @@ -489,8 +489,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } } int gap = swayc_gap(container); - container->x = x + gap; - container->y = y + gap; + x = container->x = x + gap; + y = container->y = y + gap; width = container->width = width - gap * 2; height = container->height = height - gap * 2; sway_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", container->name, container->x, container->y); @@ -509,10 +509,11 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { default: container->width = width; container->height = height; + x = container->x; + y = container->y; break; } - x = y = 0; double scale = 0; switch (container->layout) { case L_HORIZ: @@ -536,8 +537,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); - child->x = x + container->x; - child->y = y + container->y; + child->x = x; + child->y = y; arrange_windows_r(child, child->width * scale, height); x += child->width; } @@ -563,8 +564,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); - child->x = x + container->x; - child->y = y + container->y; + child->x = x; + child->y = y; arrange_windows_r(child, width, child->height * scale); y += child->height; } -- cgit v1.2.3-54-g00ecf From 6750975b9f91d3e0aa632add0f56fc4611b0853a Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Tue, 22 Dec 2015 12:36:20 +0100 Subject: 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. --- sway/CMakeLists.txt | 1 + sway/layout.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index 259e9ab3..23829dc3 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(sway ${PCRE_LIBRARIES} ${JSONC_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} + m ) install( 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 @@ #include #include +#include #include #include "extensions.h" #include "layout.h" @@ -379,6 +380,11 @@ void update_geometry(swayc_t *container) { swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE); swayc_t *op = ws->parent; int gap = container->is_floating ? 0 : swayc_gap(container); + if (gap % 2 != 0) { + // because gaps are implemented as "half sized margins" it's currently + // not possible to align views properly with odd sized gaps. + gap -= 1; + } struct wlc_geometry geometry = { .origin = { @@ -430,6 +436,11 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { width = container->width; height = container->height; } + // pixels are indivisable. if we don't round the pixels, then the view + // calculations will be off (e.g. 50.5 + 50.5 = 101, but in reality it's + // 50 + 50 = 100). doing it here cascades properly to all width/height/x/y. + width = floor(width); + height = floor(height); sway_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", container, 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) { sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); child->x = x; child->y = y; - arrange_windows_r(child, child->width * scale, height); + if (i == container->children->length - 1) { + double remaining_width = container->x + width - x; + arrange_windows_r(child, remaining_width, height); + } else { + arrange_windows_r(child, child->width * scale, height); + } x += child->width; } } @@ -566,7 +582,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); child->x = x; child->y = y; - arrange_windows_r(child, width, child->height * scale); + if (i == container->children->length - 1) { + double remaining_height = container->y + height - y; + arrange_windows_r(child, width, remaining_height); + } else { + arrange_windows_r(child, width, child->height * scale); + } y += child->height; } } -- cgit v1.2.3-54-g00ecf From b18f0042103b8475b5be754bec9209c2ac512a56 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Mon, 28 Dec 2015 01:07:44 +0100 Subject: handlers: geometry_request: Better debug output. Previous output was confusing. --- sway/handlers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 751e894c..b8bd9eff 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -279,8 +279,8 @@ static void handle_view_focus(wlc_handle view, bool focus) { } static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry *geometry) { - sway_log(L_DEBUG, "geometry request for %ld %dx%d : %dx%d", - handle, geometry->origin.x, geometry->origin.y, geometry->size.w, geometry->size.h); + sway_log(L_DEBUG, "geometry request for %ld %dx%d @ %d,%d", handle, + geometry->size.w, geometry->size.h, geometry->origin.x, geometry->origin.y); // If the view is floating, then apply the geometry. // Otherwise save the desired width/height for the view. // This will not do anything for the time being as WLC improperly sends geometry requests -- cgit v1.2.3-54-g00ecf