koekeishiya / yabai

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

Auto minimizing "Carousel" mode #1609

Open Bellavene opened 1 year ago

Bellavene commented 1 year ago

I am trying to implement an auto minimizer/un-minimizer with three or four windows, but feel that I am a bit dumb to make it perfect. The main window should be untouchable, un-minimizing should take the window back to the first one on the right side. Any suggestions? Also tried a variation of stacking to the last window, but it is even worse.

.yabairc

yabai -m signal --add event=window_created action="yabai-count-minimize"
yabai -m signal --add event=window_destroyed action="yabai-count-minimize"

yabai-count-minimize

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')
STACK=$(yabai -m query --windows --space | jq 'sort_by(.frame.y, .frame.x ) | .[1].id')
STACK2=$(yabai -m query --windows --space | jq 'sort_by(.frame.y, .frame.x ) | .[2].id')
STACK3=$(echo $WINDOWS_ARRAY | jq -re "sort_by(.frame.x, .frame.y, .id) | .[3].id")
LAST_MIN=$(yabai -m query --windows --space | jq -r '.[] | select(."is-minimized"==true).id' | tac | head -n 1)

case $NUMBER_OF_WINDOWS in
    [0-1])
        yabai -m config split_ratio 0.65
        ;;
    2)
        yabai -m window --deminimize $LAST_MIN;yabai -m window last --insert south
        yabai -m window --focus $STACK
        yabai -m config split_ratio 0.5
        yabai -m window $STACK --insert north
        yabai -m space --balance x-axis
        ;;
    3)
        yabai -m config split_ratio 0.5
        yabai -m window $STACK --insert north
        yabai -m space --balance x-axis
        ;;
    *)
        yabai -m config split_ratio 0.5
        yabai -m window $STACK3 --minimize
        yabai -m window $STACK --insert north
        yabai -m space --balance x-axis
        ;;
esac

https://user-images.githubusercontent.com/77557804/219257720-f31f4448-6e64-46ff-824a-577bf705d900.mp4

matru commented 1 year ago

@Bellavene that's a good implementation of tabbed view on the stack layout. Nice! Sorry for taking it out of context, but are you the original author, as I have not seen it before?

Bellavene commented 1 year ago

@Bellavene that's a good implementation of tabbed view on the stack layout. Nice! Sorry for taking it out of context, but are you the original author, as I have not seen it before?

Yes, thank you. Borrowed another script here as a starting point. Too bad we don't have a usual window counter in yabai and Asmund stated many times that he doesn't want to implement it. It would simplify a lot of things and will work as intended.

Bellavene commented 1 year ago

So far this version worked best for me, calls fewer queries. You must set window_placement first_child and insert_feedback_color 0x00000000 in .yabairc

#!/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')
STACK=$(echo $WINDOWS_ARRAY | jq -re "sort_by(.frame.y) | .[2].id")
LAST_MIN=$(yabai -m query --windows --space | jq -r '.[] | select(."is-minimized"==true).id' | tac | head -n 1)

case $NUMBER_OF_WINDOWS in
    0)
        yabai -m config split_ratio 0.35
        ;;
    1)
        yabai -m config split_type auto
        yabai -m config split_ratio 0.5
        ;;
    2)
        yabai -m config split_ratio 0.5
        yabai -m config split_type horizontal
        yabai -m window $STACK --insert south
        yabai -m window --deminimize $LAST_MIN && sleep 0.2; yabai -m window $STACK --insert south
        yabai -m window --focus north
        yabai -m window first --insert north
        ;;
    3)
        yabai -m window --warp first
        yabai -m window first --insert north
        ;;
    *)
        yabai -m window uncle --minimize
        sleep 0.4
        yabai -m window --warp first
        yabai -m window first --insert north
        ;;
esac

https://user-images.githubusercontent.com/77557804/219988180-e23df6da-ab53-4cb9-9674-24eae0758cf4.mp4

Bellavene commented 1 year ago

The more I use it, the more I like it. Perfect for macbooks little screens. I wish only that we could polish it a bit. Best would be to implement it right in yabai without scripts, or at least add a yabai global setting for new windows location point, at first window or last one. And ideally would be with 4 windows instead of 3 (too buggy to implement through scripts). Right now, it sometimes adds new window at master stack if application is opened fresh and master window was selected.

IMHO, That's how stage manager should have worked at the beginning, not that useless nonsense they've made.