mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
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.
This commit is contained in:
parent
831f6680f4
commit
6750975b9f
|
@ -32,6 +32,7 @@ target_link_libraries(sway
|
|||
${PCRE_LIBRARIES}
|
||||
${JSONC_LIBRARIES}
|
||||
${WAYLAND_SERVER_LIBRARIES}
|
||||
m
|
||||
)
|
||||
|
||||
install(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <wlc/wlc.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue