Replies: 44 comments
-
You can use
When the number of windows is less than 2, remove the padding:
Next, you should use yabai signal to make it run automatically
Probably you need more signals to make it robust because |
Beta Was this translation helpful? Give feedback.
-
Yes, it was very helpful. Thank you. I am trying to achieve something similar to |
Beta Was this translation helpful? Give feedback.
-
Don't understand, why signals are not working # tile apps
yabai -m rule --add app="^Emacs$" sticky=off manage=on
# float apps
yabai -m rule --add app="^System Preferences$" sticky=on layer=above manage=off
# layout
yabai -m config layout bsp
yabai -m config window_gap 7
if [[ $(yabai -m query --windows --space | jq "length") == 1 ]]; then
# padding for one window
yabai -m config top_padding 0
yabai -m config bottom_padding 0
yabai -m config left_padding 0
yabai -m config right_padding 0
else
# padding for two or more windows
yabai -m config top_padding 10
yabai -m config bottom_padding 10
yabai -m config left_padding 10
yabai -m config right_padding 10
fi
# signals
yabai -m signal --add \
event=window_created \
action="[[ $(yabai -m query --windows --space | jq 'length') -gt 1 ]] \
&& yabai -m config top_padding 10 \
&& yabai -m config bottom_padding 10 \
&& yabai -m config left_padding 10 \
&& yabai -m config right_padding 10"
yabai -m signal --add \
event=window_destroyed \
action="[[ $(yabai -m query --windows --space | jq 'length') == 1 ]] \
&& yabai -m config top_padding 0 \
&& yabai -m config bottom_padding 0 \
&& yabai -m config left_padding 0 \
&& yabai -m config right_padding 0"
yabai -m config window_placement second_child
yabai -m config split_ratio 0.50
yabai -m config auto_balance off |
Beta Was this translation helpful? Give feedback.
-
The problem is we should apply different padding settings on different desktops depending on number of windows |
Beta Was this translation helpful? Give feedback.
-
In the
You can iterate over all the spaces, and for each space, get the number of windows there and then set the padding.
will output the number of windows in each space. Next, you just need to set the paddings based on the number (for example, use bash If you are not familiar with |
Beta Was this translation helpful? Give feedback.
-
For now have no idea, why the following code doesn't work. padding_refresh_command="p=\$((\$(yabai -m query --windows --space | jq 'length') == 1 ? 0 : 10)) && \
yabai -m config --space mouse top_padding \$p && \
yabai -m config --space mouse bottom_padding \$p && \
yabai -m config --space mouse left_padding \$p && \
yabai -m config --space mouse right_padding \$p"
yabai -m signal --add event=window_created action="$padding_refresh_command"
yabai -m signal --add event=window_destroyed action="$padding_refresh_command"
yabai -m signal --add event=application_launched action="$padding_refresh_command"
yabai -m signal --add event=application_terminated action="$padding_refresh_command" |
Beta Was this translation helpful? Give feedback.
-
Put all your code into my |
Beta Was this translation helpful? Give feedback.
-
Does it work after you run this code in your terminal? Cause for me it doesn't |
Beta Was this translation helpful? Give feedback.
-
I pasted all your code above to the end of my |
Beta Was this translation helpful? Give feedback.
-
Ok, here is my # load scripting-additions
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
# global settings
# yabai -m config mouse_follows_focus on
# yabai -m config focus_follows_mouse autoraise
yabai -m config window_placement second_child
yabai -m config window_shadow off
yabai -m config window_border on
yabai -m config window_border_width 5
yabai -m config active_window_border_color 0xffa35763
yabai -m config normal_window_border_color 0xff353c54
yabai -m config insert_feedback_color 0xaa7c5c9c
yabai -m config split_ratio 0.50
yabai -m config auto_balance on
yabai -m config window_gap 7
# mission-control desktop labels
yabai -m space 1 --label web
yabai -m space 2 --label code
yabai -m space 3 --label social
yabai -m space 4 --label mail
yabai -m space 5 --label media
# window rules
yabai -m rule --add app="^Firefox$" space=web
yabai -m rule --add app="^Emacs$" space=code manage=on
yabai -m rule --add app="^Telegram$" space=social
yabai -m rule --add app="^Slack$" space=social
yabai -m rule --add app="^Discord$" space=social
yabai -m rule --add app="^Spark$" space=mail manage=on
yabai -m rule --add app="^Transmission$" space=media
yabai -m rule --add app="^Spotify$" space=media manage=on
yabai -m rule --add app="^Finder$" title="(Co(py|nnect)|Move|Info|Pref)" manage=off
yabai -m rule --add app="^Spotlight$" layer=above manage=off
yabai -m rule --add app="^Stickies$" manage=off
yabai -m rule --add app="^System Preferences$" layer=above manage=off
# general space layput
yabai -m config layout bsp
# padding
window_numbers=$(yabai -m query --spaces \
| jq '.[].index' \
| xargs -I{} yabai -m query --windows --space {} \
| jq "length")
di=1
for wn in $window_numbers; do
p=$((wn == 1 ? 0 : 10))
yabai -m config --space $di top_padding $p
yabai -m config --space $di bottom_padding $p
yabai -m config --space $di left_padding $p
yabai -m config --space $di right_padding $p
di=$((di+1))
done
# padding signals
padding_refresh_command="p=\$((\$(yabai -m query --windows --space | jq 'length') == 1 ? 0 : 10)) && \
yabai -m config --space mouse top_padding \$p && \
yabai -m config --space mouse bottom_padding \$p && \
yabai -m config --space mouse left_padding \$p && \
yabai -m config --space mouse right_padding \$p"
yabai -m signal --add event=window_created action="$padding_refresh_command"
yabai -m signal --add event=window_destroyed action="$padding_refresh_command"
yabai -m signal --add event=application_launched action="$padding_refresh_command"
yabai -m signal --add event=application_terminated action="$padding_refresh_command"
# signals
yabai -m signal --add event=window_destroyed action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse"
yabai -m signal --add event=application_terminated action="yabai -m query --windows --window &> /dev/null || yabai -m window --focus mouse" |
Beta Was this translation helpful? Give feedback.
-
Yep. But in When debugging, try to simplify the code by just leaving the piece of code you want to debug on and delete (or comment out) other codes temporarily. You could remove all the rules and other personal settings, just keep the |
Beta Was this translation helpful? Give feedback.
-
Doesn't work in either cases, whatever i comment |
Beta Was this translation helpful? Give feedback.
-
If i try to set some simple signals from the terminal manually after evaluating yabairc, they work, so i thought the issue was in padding signals code, but currently don't understand, how it can work for you |
Beta Was this translation helpful? Give feedback.
-
Both initial padding setup and signals should work after you run this code in your terminal. For me it doesn't # initial setup
window_numbers=$(yabai -m query --spaces \
| jq '.[].index' \
| xargs -I{} yabai -m query --windows --space {} \
| jq "length")
di=1
for wn in $window_numbers; do
p=$((wn == 1 ? 0 : 10))
yabai -m config --space $di top_padding $p
yabai -m config --space $di bottom_padding $p
yabai -m config --space $di left_padding $p
yabai -m config --space $di right_padding $p
di=$((di+1))
done
# signals
padding_refresh_command="p=\$((\$(yabai -m query --windows --space | jq 'length') == 1 ? 0 : 10)) && \
yabai -m config --space mouse top_padding \$p && \
yabai -m config --space mouse bottom_padding \$p && \
yabai -m config --space mouse left_padding \$p && \
yabai -m config --space mouse right_padding \$p"
yabai -m signal --add event=window_created action="$padding_refresh_command"
yabai -m signal --add event=window_destroyed action="$padding_refresh_command"
yabai -m signal --add event=application_launched action="$padding_refresh_command"
yabai -m signal --add event=application_terminated action="$padding_refresh_command" |
Beta Was this translation helpful? Give feedback.
-
@yanzhang0219 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Okay. I see. But that's not important. |
Beta Was this translation helpful? Give feedback.
-
Quite strange. I still have no values for |
Beta Was this translation helpful? Give feedback.
-
Just now, I put all your code directly into my And it still works. Screen.Recording.2021-01-09.at.1.04.51.PM.mov |
Beta Was this translation helpful? Give feedback.
-
It is strange, that if i just check space info, padding_refresh_command="space_info=\$(yabai -m query --windows --space | jq)
echo \"space_info: \$space_info\" >> \"\$HOME/yabailogs.txt\""
yabai -m signal --add event=window_created action="$padding_refresh_command"
yabai -m signal --add event=window_destroyed action="$padding_refresh_command" signal action is executed, but i see nothing space_info:
space_info:
space_info:
space_info: |
Beta Was this translation helpful? Give feedback.
-
Interesting! |
Beta Was this translation helpful? Give feedback.
-
Yea, i rebooted my computer. SIP is disabled. yabai is from brew. I'll try to install the dev version
|
Beta Was this translation helpful? Give feedback.
-
Sigh 😞 |
Beta Was this translation helpful? Give feedback.
-
It seems like i skipped |
Beta Was this translation helpful? Give feedback.
-
It might be an OS version issue. Installation requirement is 11.0.1. I use 11.2 |
Beta Was this translation helpful? Give feedback.
-
Okay... 11.1 is supported as well, but not sure about 11.2. Normally for a new macOS version, yabai needs to update a byte patterns in the payload.c file. We have to wait for the adaption. |
Beta Was this translation helpful? Give feedback.
-
This worked for me as well. I am on BigSur. |
Beta Was this translation helpful? Give feedback.
-
It may work on 11.1 and previous versions, but may not work on 11.2, I suppose |
Beta Was this translation helpful? Give feedback.
-
The signal and query system are not affected by SIP and/or macOS version. |
Beta Was this translation helpful? Give feedback.
-
I tried to set this up and ran into issues too. The script runs fine, but it looks like even if a window is hidden it still appears in the query. If you actually quit the applications so you only have one left, it works. You could try filtering out non-visible windows, but then there's this: #616 |
Beta Was this translation helpful? Give feedback.
-
Can I enable following settings only if a desktop contains >=2 windows?
Beta Was this translation helpful? Give feedback.
All reactions