koekeishiya / yabai

A tiling window manager for macOS based on binary space partitioning
MIT License
22.48k stars 630 forks source link

Something is wrong with first/last insert commands #2281

Open Bellavene opened 1 month ago

Bellavene commented 1 month ago

I have this config, that tries to match a master layout:

yabai -m config                     \
    split_ratio         0.3     \
    split_type          auto        \
    window_placement        first_child

yabai -m signal --add event=window_focused action="yabai-master-first"
yabai -m signal --add event=window_created action="yabai -m space --balance x-axis"
yabai -m signal --add event=window_destroyed action="yabai -m space --balance x-axis"
yabai -m signal --add event=window_deminimized action="yabai -m space --balance x-axis"
yabai -m signal --add event=window_minimized action="yabai -m space --balance x-axis"

yabai-master-first

#!/bin/zsh
CURRENT_DISPLAY=$(yabai -m query --windows --window | jq '.display')
WINDOWS_ARRAY=$(yabai -m query --windows --space $(yabai -m query --spaces --space | jq '.index') --display $CURRENT_DISPLAY | jq -r 'map(select(.["is-minimized"]==false and .["is-floating"]==false))')
NUMBER_OF_WINDOWS=$(echo $WINDOWS_ARRAY | jq -r 'length')

case $NUMBER_OF_WINDOWS in
    [0-1])
        yabai -m config split_type auto
        ;;
    2)
        yabai -m config split_type auto
        yabai -m window first --insert north
        ;;
    3)
        yabai -m config split_type horizontal
        yabai -m window first --insert north
        ;;
    *)
        yabai -m config split_type horizontal
        yabai -m window first --insert north
        ;;
esac

Now open two different application windows. If the focus is on the "master" window at the right, and I try to open another window of the same application as "master", it doesn't insert to the first window in tree, it opens as a child window of the "master"... When more than two windows are open, it works correctly.

If I rewrote this script for second_child and insert to last/south insertion points, it behaves even more unpredicted.

Can we do something about it? Why it misbehaves when it wants to? And why we can't add at least an option to always open windows at the start or end of the tree? Like window_placement first_window. And auto_balance x-axis would be also helpful. Sounds easy to do... Or just add a master layout, as many was asking for. Bsp layout is beautiful, no doubts. But it is not practical for most people with usual screen aspect ratios.

Bellavene commented 1 month ago

Can we add yabai -m window --insert first/last?