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

How to split a stack when it's the only node in the current bsp tree? #671

Closed
alextremblay opened this issue Sep 25, 2020 · 8 comments
Closed
Labels
question Request for information or help, not an issue

Comments

@alextremblay
Copy link

alextremblay commented Sep 25, 2020

Hello,

I recently discovered the newly-added stack feature of yabai, and I'm super excited to start using it

I've figured out how to combine all the windows in a given space into a stack, but i'm having trouble figuring out how to split a window off of the stack.

I can see in the documentation for yabai -m window --stack it says "Any kind of warp operation performed on a stacked window will unstack it."
but when i try to break a window out of the stack into a new split, I try yabai -m window --warp east and I get could not locate a eastward managed window

Basically, the use case I'm trying to achieve is this:

  1. Have a particular space which is stacked by default, all new windows are stacked onto the first stack
  2. split the stack horizontally, with topmost window of stack moving into its own space on the right, and the rest of the stack remaining on the left
  3. move additional windows from the main stack to the right, stacking onto the existing window / stack on the right
  4. move windows on the right stack back to the main stack, one by one, until all windows are merged and the whole space is one single stack

If my use case is doable, I'd love to get any guidance I can on how to accomplish it. Thank you!

@Liquidmantis
Copy link

Liquidmantis commented Sep 25, 2020

Are you setting the space to stacking mode in order to collect all the windows to a stack? If not, and your space is still in bsp, I wonder if it would work to pop a window off the stack by setting it to floating, then setting it to bsp. That might create a split. Unfortunately, I drunkenly decided to try the Big Sur beta and can't really run Yabai to be able to test right now.

@alextremblay
Copy link
Author

For item 1, I see that I can set a space to --layout stack, which is perfect, but i don't know if i can then split the stack if the whole space layout is stack?

For item 3 and 4 I've got this working, which is nice: yabai -m window <east|west> --stack $(yabai -m query --windows --window | jq '.id')

@alextremblay
Copy link
Author

@Liquidmantis well there's an idea... toggle the window float property twice, forcing it to re-enter bsp as a split, instead of a stacked window

That works if the space layout is bsp, but not if the space layout is stack
But if the space layout is bsp, then all new windows get split instead of stacked...

unless i create a rule to stack all newly-created windows...

@alextremblay
Copy link
Author

Ok, so I've got partial success...
I've got a "stack current window to the right or make split if no stack command" command:
window=$(yabai -m query --windows --window | jq -r '.id') && yabai -m window east --stack $window || yabai -m window $window --toggle float && yabai -m window $window --toggle float

If there's no split, it will successfully create a split. and if there is a split, it will move the current window to the region of the eastward window, but won't stack. it will leave the current window floating. I can't figure out why

@koekeishiya
Copy link
Owner

You need proper precedence for your commands. This should work:

 window=$(yabai -m query --windows --window | jq -r '.id') && yabai -m window east --stack $window || (yabai -m window $window --toggle float && yabai -m window $window --toggle float)

@koekeishiya koekeishiya added the question Request for information or help, not an issue label Sep 26, 2020
@alextremblay
Copy link
Author

That was exactly what I needed. Thank you so much!

For reference, I've now got it set up as a bash script called stack, triggered by skhd with arrow keys:

#!/usr/bin/env bash

dir=$1
# dir should be one of east,west,north,south

window=$(yabai -m query --windows --window | jq -r '.id') 

# Stack this window onto existing stack if possible
yabai -m window $dir --stack $window 
if [[ $? -ne 0 ]]; then
    # otherwise, float and un-float this window to reinsert it into 
    # the bsp tree as a new window
    yabai -m window --insert $dir
    yabai -m window $window --toggle float 
    yabai -m window $window --toggle float
fi

so far it's working really well :)

@b4rlw
Copy link

b4rlw commented Apr 27, 2022

Also, if you use this code, don't forget brew install jq like I did, may save you half an hour :)

@bangedorrunt
Copy link

bangedorrunt commented Sep 25, 2022

@alextremblay many thanks for the script. it's working really well
Always wish Yabai has its own stack layout so we don't have to do these workarounds :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for information or help, not an issue
Projects
None yet
Development

No branches or pull requests

5 participants