Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3+ column/row bsp layout #157

Closed
net opened this issue Jul 25, 2019 · 7 comments
Closed

3+ column/row bsp layout #157

net opened this issue Jul 25, 2019 · 7 comments

Comments

@net
Copy link

net commented Jul 25, 2019

Is it possible to create a 3+ column or row layout like shown in this chunkwm gif?

6863954c-2db4-11e7-8332-221cecb52ce5

I vaguely remember being able to rotate a subtree back in kwm, but that doesn't seem possible anymore.

I've been able to create stacked rows by changing split_ratio, but it hasn't been very reliable.

@dominiklohmann
Copy link
Collaborator

Here's what you need.

# toggle split between vertical and horizontal
yabai -m window --toggle split

# balance all windows 
yabai -m space --balance

# config: always keep windows balance
yabai -m config auto_balance on

You can also convert all splits to vertical splits by creating a signal: on the signal event=window_created execute the below file (gotta be an external file so you can grab the arguments).

From the signal you could filter also filter for a specific display or space index. There's many ways to improve on this.

#! /usr/bin/env sh

# make this file executable using:
#     chmod +x /path/to/this/script
# create a signal using: 
#     yabai -m signal --add event=window_created action="/path/to/this/script"

# get the window id of the newly created window
wid="${2}"

# if the split is horizontal, toggle it to vertical
yabai -m query --windows --window "${wid}" | jq -re '.split == "horizontal"' \
    && yabai -m window "${wid}" --toggle split

@net
Copy link
Author

net commented Jul 25, 2019

@dominiklohmann thank you!

@net net closed this as completed Jul 25, 2019
@dominiklohmann
Copy link
Collaborator

dominiklohmann commented Jul 25, 2019

Here's an even simpler version. Just save this in a file and execute it somewhere from your yabairc.

Using insert directions for this has the additional advantage of avoiding the flicker effect of toggling the split whenever a new window is created.

#! /usr/bin/env zsh

if [ "${#}" -eq 0 ]; then
	# enable auto balance
	yabai -m config auto_balance on

	# register events
	for event in window_focused application_activated; do
		yabai -m signal --add label="${0}_${event}" event="${event}" \
			action="${0}"
	done

	# when loading the script, convert all existing splits to horizontal
	yabai -m query --windows \
		| jq -r '.[] | select(.split == "horizontal").id' \
		| xargs -I{} yabai -m window {} --toggle split

	exit
fi

yabai -m window --insert "$(jq -nr \
	--arg window_placement "$(yabai -m config window_placement)" \
	--argjson display "$(yabai -m query --displays --display)" \
	'[["west", "east"], ["north", "south"]][if $display | .frame | .w >= .h then 0 else 1 end][if $window_placement == "first_child" then 0 else 1 end]')"

Edit: @net I updated the above script to work with vertical monitors as well (using rows over cols automatically) and simplified it a bit.

@pencilcheck
Copy link

pencilcheck commented Jan 31, 2020

Not perfect, nor 3+ column row bsp layout but this solves my issue that I can't bring the focused window to the bigger portal of the bsp tree

Create this script and put it somewhere and follow the instructions

#! /usr/bin/env zsh

# put this line in your .skhdrc (you can change the command to whatever makes sense)
#     shift + alt - q : /path/to/script
# remember to make it executable
#     $ chmod a+x /path/to/script

# Force bsp layout reset
ctrl + alt - d : yabai -m space --layout float
ctrl + alt - a : yabai -m space --layout bsp

# swap currently focused to the last window (the biggest one)
yabai -m window --swap last

@koekeishiya
Copy link
Owner

Any reason why yabai -m window --swap largest does not work for that purpose?

@rheaSPK
Copy link

rheaSPK commented Sep 24, 2022

Hi, I was also wondering if a three column layout was possible, and the suggestions didn't really help me. The following approach might be very buggy and certainly not elegant, but it rearranges the windows to a 3 column layout, which is fine for me. Maybe it helps.

alt - t : yabai -m space --layout bsp;\
    yabai -m space --mirror y-axis;\
    yabai -m window --focus largest;\
    yabai -m window --insert east;\
    yabai -m window --focus next;\
    yabai -m window --focus next;\
    yabai -m window --warp largest;\
    yabai -m window --resize left:-200:0; \
    yabai -m window --resize right:500:0; \

@owenarden
Copy link

Here's an even simpler version. Just save this in a file and execute it somewhere from your yabairc.

Using insert directions for this has the additional advantage of avoiding the flicker effect of toggling the split whenever a new window is created.

#! /usr/bin/env zsh

if [ "${#}" -eq 0 ]; then
	# enable auto balance
	yabai -m config auto_balance on

	# register events
	for event in window_focused application_activated; do
		yabai -m signal --add label="${0}_${event}" event="${event}" \
			action="${0}"
	done

	# when loading the script, convert all existing splits to horizontal
	yabai -m query --windows \
		| jq -r '.[] | select(.split == "horizontal").id' \
		| xargs -I{} yabai -m window {} --toggle split

	exit
fi

yabai -m window --insert "$(jq -nr \
	--arg window_placement "$(yabai -m config window_placement)" \
	--argjson display "$(yabai -m query --displays --display)" \
	'[["west", "east"], ["north", "south"]][if $display | .frame | .w >= .h then 0 else 1 end][if $window_placement == "first_child" then 0 else 1 end]')"

Edit: @net I updated the above script to work with vertical monitors as well (using rows over cols automatically) and simplified it a bit.

This approach had been working well for me, but the 6.0 release breaks it since application_activated was removed. I tried just naively replacing application_activated with application_front_switched, but it didn't seem to work. I haven't done much investigation yet, but wondered if anyone has a fix already, or an idea of what the right thing to do would be.

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

No branches or pull requests

6 participants