Skip to content

patch/layout_tile.c: round client width after multiplying by mfact - #472

Draft
whileAlice wants to merge 1 commit into
bakkeby:masterfrom
whileAlice:round-client-width
Draft

patch/layout_tile.c: round client width after multiplying by mfact#472
whileAlice wants to merge 1 commit into
bakkeby:masterfrom
whileAlice:round-client-width

Conversation

@whileAlice

@whileAlice whileAlice commented Dec 22, 2025

Copy link
Copy Markdown

This PR intends to fix off-by-one errors that appear when using the default tiled layout, resulting in clients not reaching their full width:

off-by-one

I see that upstream doesn't multiply by mfact when calculating client width, so the problem doesn't exist there.

I also noticed that there are other instances of non-rounded multiplication by mfact throughout different patches, which I believe also result in this problem. If my solution is acceptable, I'll extend it to those instances as well.

Comment thread patch/layout_tile.c
sw = (mw - iv) * (1 - m->mfact);
mw = (mw - iv) * m->mfact;
sw = round((mw - iv) * (1 - m->mfact));
mw = round((mw - iv) * m->mfact);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure if using round is the right approach here.

Let's say that you have an mfact value of 0.5, mw being an even number like 1024 and iv being an odd number like 5.

With mfact being applied we can expect that both sw and mw will end up with the same float value of 509.5.

When we round that number we would then expect it to round the same way for both numbers, increasing them both to 510. In total the master and stack areas plus gap ends up taking 510 + 510 + 5 = 1025, which is one pixel more than there is room for.

The problem with the original code is that there is a remainder pixel that gets truncated when the float value is cast to an int.

The solution should give that pixel either to the stack area or to the master area. Let's go with the assumption that the remainder pixel should go to the master area.

I think the better approach here is to first calculate the stack area width based on the mfact, and deduct that from the total when calculating the master area. E.g. something like this:

		sw = (mw - iv) * (1.0 - m->mfact);
		mw = (mw - iv - sw);

For layouts that have more than two areas it would also be possible to calculate the remaining pixels (e.g. 2) and distribute those evenly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! This sounds like a much better approach. I'm drafting this one and I'll get back to it soonish.

@whileAlice
whileAlice marked this pull request as draft January 7, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants