Skip to content

Binary Space Partitioning#77

Open
marcybelardo wants to merge 15 commits into
nferhat:mainfrom
marcybelardo:bsp
Open

Binary Space Partitioning#77
marcybelardo wants to merge 15 commits into
nferhat:mainfrom
marcybelardo:bsp

Conversation

@marcybelardo

Copy link
Copy Markdown

Hi! I really like the compositor. I noticed there was an open issue for adding bspwm-like partitioning to the compositor, so I gave it a shot. I have a simple implementation working on my system running Arch. There's still a bunch I need to fix, such as how it interacts with inner gaps, as well as other edge cases I'm probably not taking into account. Please feel free to comment on this or reject it! I'd like to keep working on this if you'd have me.

Here is what it looks like on my system, just punched in a bunch of terminals:
image

I have this set in my compositor.toml:

layouts = ["tile", "floating", "binary-space-partition"]
nmaster = 1
mwfact = 0.5
inner-gaps = 5
outer-gaps = 10

@nferhat

nferhat commented Aug 21, 2025

Copy link
Copy Markdown
Owner

Hello! Thank you for giving it a shot!

To be honest, this first implementation doesn't look that bad, though maybe instead of doing this iterative approach, we could just create the BSP tree on the fly when calculating the layout?

Because the proportion_lengths business I got around works well when you only have one single axis of splitting, and was meant to combat floating-point errors when you have, say, 3 windows to split a 1370 height (which results in either under or overshooting, depending on whether you use round, floor or ceil)

Calculating the tree should be pretty trivial since we only have at max 6-7 windows, so this shouldn't be too bad, plus, it would make:

  • Finding the insert position for the SwapTileGrab much much easier
  • Adding inner gaps becomes easy, just shrink each rect of the tree by a specified amount

Regardless, this first attempt looks very promising

@marcybelardo

Copy link
Copy Markdown
Author

Sounds good! I'll try something out and put in more commits~

@marcybelardo

Copy link
Copy Markdown
Author

@nferhat So I made something new, still pretty naive but it builds the tree when we calculate layout. I based the implementation on how bspwm handles its nodes.

Basically, a node can only have zero or two children. A node with no children is a leaf and is set to display a tile, but when a new tile is added, the first node becomes a branch that basically "manages" the split for the next two leaf nodes. Then, we set the second child to potentially become a new leaf.

From here, I can set it up to determine whether to use the first child or second as the splitting point to support other kinds of splitting (spiral, etc), but this version mostly does longest side fine. I'm still having an issue where the tiles are smaller than expected, but I think that's fixable too.

@nferhat

nferhat commented Sep 1, 2025

Copy link
Copy Markdown
Owner

Hey, this looks pretty nice, +the tests look fine. Going to test this locally and see!

By the way if you could cherry-pick the docs typos into a separate PR I would be glad

@nferhat

nferhat commented Sep 1, 2025

Copy link
Copy Markdown
Owner

I'm still having an issue where the tiles are smaller than expected, but I think that's fixable too.

Seems like you are subtracting inner-gaps for each horizontal split, when setting them to 0 the issue doesn't happen

@marcybelardo

Copy link
Copy Markdown
Author

@nferhat Ah darn yeah, okay I got it working. I put all the inner gaps handling inside the BspTree because it gets kinda tricky with the numbers of tiles in the same plane.

I'm probably going to work on the spiral/dwindle options now too, and maybe I'll try doing a focus-window-up/down/left/right as well, as per #44.

Should it still be called BSP by the way? DWM and Hyprland refer to it as Dwindle, maybe have the module called "Tree" and then dwindle, spiral, etc. can be config options?

@marcybelardo

Copy link
Copy Markdown
Author

I have spiral functionality working now in addition to the binary space implementation. I'll probably start on focus window directions now.

Here's what spiral looks like:
Uploading 1757708721.png…

@nferhat

nferhat commented Sep 13, 2025

Copy link
Copy Markdown
Owner

I have spiral functionality working now in addition to the binary space implementation. I'll probably start on focus window directions now.

Here's what spiral looks like:
Uploading 1757708721.png…

Seems like you were too hasty and didn't wait for the image to upload. But seeing it locally, looks good!

@marcybelardo

Copy link
Copy Markdown
Author

Seems like you were too hasty and didn't wait for the image to upload. But seeing it locally, looks good!

Yeah I thought it was just taking its time lol

I'm working on the focus directions on a different branch, so if this is good to go, you can merge it if you like! But of course if you'd like to me to add the documentation first, I'll do so.

@t3kkm0tt

Copy link
Copy Markdown

When will this be finished

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.

3 participants