macOS tile window yabai configuration sharing

brief introduction

yabai is a window management utility designed to work as an extension of the macOS built-in window manager. yabai allows you to freely control windows, spaces and displays using an intuitive command-line interface, with the option to set user-defined keyboard shortcuts ↗ skhd and other third-party software.

The main function of yabai is tile window management; Use the binary space partition algorithm to automatically modify the window layout, so that you can focus on the contents of the window without distraction. Other features of yabai include focus following the mouse, disabling the animation of switching spaces, creating spaces with more than 16 space limits, and so on.

github home page:
https://github.com/koekeishiya/yabai

install

The installation method is very clear in the official wiki. It is recommended to directly read the official Wiki:
https://github.com/koekeishiya/yabai/wiki

The following are my notes taken during installation. They are not specially sorted out for reference only.
https://blog.csdn.net/lxyoucan/article/details/121202575

to configure

yabai configuration

In order for others to use my computer, I can adapt. So I don't use bsp layout by default. I only load this configuration when I use the computer myself.
These configurations are specially proposed by me. When I use the computer myself, I will manually load these configurations. (I load by CapsLk + 0)

Path ~ /. config/yabai/yabairc

#!/usr/bin/env bash

set -x

# ====== Variables =============================

declare -A gaps
declare -A color

gaps["top"]="4"
gaps["bottom"]="24"
gaps["left"]="4"
gaps["right"]="4"
gaps["inner"]="4"

color["focused"]="0xffd75f5f"
color["normal"]="0x00010101"
color["preselect"]="0xE02d74da"

# Uncomment to refresh ubersicht widget on workspace change
# Make sure to replace WIDGET NAME for the name of the ubersicht widget
#ubersicht_spaces_refresh_command="osascript -e 'tell application id \"tracesOf.Uebersicht\" to refresh widget id \"WIDGET NAME\"'"

# ===== Loading Scripting Additions ============

# See: https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)#macos-big-sur---automatically-load-scripting-addition-on-startup
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"

# ===== Tiling setting =========================

# bsp / float in order to facilitate others to use the computer, the default is float. When I use it myself, I will switch to bsp
yabai -m config layout                      float

yabai -m config top_padding                 "${gaps["top"]}"
yabai -m config bottom_padding              "${gaps["bottom"]}"
yabai -m config left_padding                "${gaps["left"]}"
yabai -m config right_padding               "${gaps["right"]}"
yabai -m config window_gap                  "${gaps["inner"]}"

# Status bar spacing
yabai -m config external_bar all:28:0

yabai -m config mouse_follows_focus         off
yabai -m config focus_follows_mouse         off

yabai -m config window_topmost              off
yabai -m config window_opacity              on
yabai -m config window_shadow               float

#Window margin settings
yabai -m config window_border               off
yabai -m config window_border_width         3
#yabai -m config active_window_border_color  "${color["focused"]}"
yabai -m config active_window_border_color  '0xffd75f5f'
#yabai -m config normal_window_border_color  "${color["normal"]}"
yabai -m config insert_feedback_color       "${color["preselect"]}"

yabai -m config active_window_opacity       1.0
yabai -m config normal_window_opacity       0.90
yabai -m config split_ratio                 0.50

yabai -m config auto_balance                off

yabai -m config mouse_modifier              fn
yabai -m config mouse_action1               move
yabai -m config mouse_action2               resize

# ===== Rules ==================================
#System preference floating
yabai -m rule --add app="^System Preferences $" manage=off
#yabai -m rule --add app="^QQ$" manage=off
#yabai -m rule --add app="^Simulator$" manage=off
yabai -m rule --add app="^Reminders $" manage=off
yabai -m rule --add app="^About this machine $" manage=off
# ===== Signals ================================

yabai -m signal --add event=application_front_switched action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=display_changed action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=space_changed action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=window_created action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=window_destroyed action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=window_focused action="${ubersicht_spaces_refresh_command}"
yabai -m signal --add event=window_title_changed action="${ubersicht_spaces_refresh_command}"

set +x
printf "yabai: configuration loaded...\\n"

Path ~ /. config/yabai/itkeyrc
These configurations are specially proposed by me. When I use the computer myself, I will manually load these configurations. (I load by CapsLk + 0)

#!/usr/bin/env bash
#Because my computer is used temporarily by others occasionally, using bsp layout directly may cause others not to use it
#So I'd better start the layout management function manually
# bsp/float in order to facilitate others to use the computer, the default is float. I will switch to bsp when I use it myself
yabai -m config layout                      bsp
# on|off display no border
yabai -m config window_border               on
# border width 
yabai -m config window_border_width 6
#Active border color
yabai -m config active_window_border_color 0xff775759
#Normal border color
yabai -m config normal_window_border_color 0xff555555
# Status bar spacing
#yabai -m config external_bar all:26:0
yabai -m config external_bar all:0:0

skhdrc shortcut key configuration

Path ~ /. skhdrc

# Works without yabai:
# Open iTerm
shift + ctrl + alt + cmd - return : "${HOME}"/.config/yabai/scripts/open_iterm2.sh
# Open Chrome browser
shift + ctrl + alt + cmd - b : open -na /Applications/Google\ Chrome.app
#Load custom configuration
shift + ctrl + alt + cmd - 0 :  \
    /usr/bin/env osascript <<< \
        "display notification \"ITKEY Exclusive configuration loading\" with title \"yabai\""; \
	source /Users/itkey/.config/yabai/itkeyrc


# yabai related configuration
# ---------Space (virtual desktop)---------
# Close the current Space (virtual desktop)
shift + ctrl + alt + cmd - w : yabai -m space --destroy 
# Create a new Space on the far right
shift + ctrl + alt + cmd - n : yabai -m space --create

#Accurate switching space scheme I
shift + ctrl + alt + cmd - 1 : yabai -m space --focus 1
shift + ctrl + alt + cmd - 2 : yabai -m space --focus 2
shift + ctrl + alt + cmd - 3 : yabai -m space --focus 3
shift + ctrl + alt + cmd - 4 : yabai -m space --focus 4
shift + ctrl + alt + cmd - 5 : yabai -m space --focus 5
shift + ctrl + alt + cmd - 6 : yabai -m space --focus 6
shift + ctrl + alt + cmd - 7 : yabai -m space --focus 7
shift + ctrl + alt + cmd - 8 : yabai -m space --focus 8
shift + ctrl + alt + cmd - 9 : yabai -m space --focus 9
#shift + ctrl + alt + cmd - 0 : yabai -m space --focus 10

#Accurate switching space scheme II 
alt - 1 : yabai -m space --focus 1
alt - 2 : yabai -m space --focus 2
alt - 3 : yabai -m space --focus 3
alt - 4 : yabai -m space --focus 4
alt - 5 : yabai -m space --focus 5
alt - 6 : yabai -m space --focus 6
alt - 7 : yabai -m space --focus 7
alt - 8 : yabai -m space --focus 8
alt - 9 : yabai -m space --focus 9
alt - 0 : yabai -m space --focus 10


#If there is no next space, switch to the first one
alt - l : yabai -m space --focus next || yabai -m space --focus first
#alt - l : yabai -m space --focus next
#If there is no previous space, switch to the last one
alt - h : yabai -m space --focus prev || yabai -m space --focus last
#alt - h : yabai -m space --focus prev
#Switch to the first space
alt - k : yabai -m space --focus first
#Switch to the last space
alt - j : yabai -m space --focus last
#Switching between two space s
alt - tab : yabai -m space --focus recent

#Enables / disables gaps in the current workspace
shift + ctrl + alt + cmd - g : yabai -m space --toggle padding; yabai -m space --toggle gap

# Rotate on X and Y axes
shift + alt - x : yabai -m space --mirror x-axis
shift + alt - y : yabai -m space --mirror y-axis
# ---------Window---------
# Toggle window focus
shift + ctrl + alt + cmd - h : yabai -m window --focus west 
shift + ctrl + alt + cmd - j : yabai -m window --focus south
shift + ctrl + alt + cmd - k : yabai -m window --focus north
shift + ctrl + alt + cmd - l : yabai -m window --focus east
shift + ctrl + alt + cmd - r : yabai -m window --focus recent

# move windows
shift + alt - h : yabai -m window --warp west
shift + alt - j : yabai -m window --warp south
shift + alt - k : yabai -m window --warp north
shift + alt - l : yabai -m window --warp east
# Move window to another Space
alt + ctrl - l : yabai -m window --space next && yabai -m space --focus next
alt + ctrl - h : yabai -m window --space prev && yabai -m space --focus prev
#Equalize window size
shift + ctrl + alt + cmd - e : yabai -m space --balance 
# Rotate the window clockwise and counterclockwise
alt - r         : yabai -m space --rotate 270
shift + alt - r : yabai -m space --rotate 90
# resize window
shift + ctrl + alt + cmd - left : yabai -m window --resize left:-50:0; \
                  yabai -m window --resize right:-50:0
shift + ctrl + alt + cmd - down : yabai -m window --resize bottom:0:50; \
                  yabai -m window --resize top:0:50
shift + ctrl + alt + cmd - up : yabai -m window --resize top:0:-50; \
                  yabai -m window --resize bottom:0:-50
shift + ctrl + alt + cmd - right : yabai -m window --resize right:50:0; \
                  yabai -m window --resize left:50:0


# Sets the insertion point of the focus container
shift + lctrl + alt - h : yabai -m window --insert west
shift + lctrl + alt - j : yabai -m window --insert south
shift + lctrl + alt - k : yabai -m window --insert north
shift + lctrl + alt - l : yabai -m window --insert east

# Floating / non floating window
shift + alt - space : \
    yabai -m window --toggle float; \
    yabai -m window --toggle border

# Window full screen display
shift + ctrl + alt + cmd - f : yabai -m window --toggle zoom-fullscreen
alt - f         : yabai -m window --toggle zoom-fullscreen
shift + alt - f : yabai -m window --toggle native-fullscreen
#Switch between vertical and horizontal split layout
shift + ctrl + alt + cmd - s : yabai -m window --toggle split

#---------yabai other options---------------
# Restart Yabai
shift + lctrl + alt - r : \
    /usr/bin/env osascript <<< \
        "display notification \"Restarting Yabai\" with title \"Yabai\""; \
    launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"
#Toggles whether the current window border is displayed
shift + lctrl + alt - b : yabai -m window --toggle border 

spacebar configuration

Minimum status bar for macOS. It is very suitable for use with tile window managers such as yabai.
Installation notes, written by hand during installation, are for reference only:
https://blog.csdn.net/lxyoucan/article/details/121209267

Path ~ /. config/spacebar/spacebarrc

#!/usr/bin/env sh

spacebar -m config position             top
spacebar -m config height               26
spacebar -m config title                on
spacebar -m config spaces               on
spacebar -m config clock                on
spacebar -m config power                on
spacebar -m config padding_left         20
spacebar -m config padding_right        20
spacebar -m config spacing_left         25
spacebar -m config spacing_right        15
spacebar -m config text_font            "Helvetica Neue:Bold:12.0"
spacebar -m config icon_font            "Font Awesome 5 Free:Solid:12.0"
spacebar -m config background_color     0xff202020
spacebar -m config foreground_color     0xffa8a8a8
spacebar -m config space_icon_color     0xff458588
spacebar -m config power_icon_color     0xffcd950c
spacebar -m config battery_icon_color   0xffd75f5f
spacebar -m config dnd_icon_color       0xffa8a8a8
spacebar -m config clock_icon_color     0xffa8a8a8
spacebar -m config power_icon_strip      
spacebar -m config space_icon_strip     one two three four five six seven eight nine ten
spacebar -m config space_icon           
spacebar -m config clock_icon           
spacebar -m config dnd_icon             
#spacebar -m config clock_format         "%d/%m/%y %R"
spacebar -m config clock_format         "%m month%d day %R"
spacebar -m config right_shell          off
spacebar -m config right_shell_icon     
spacebar -m config right_shell_command  "whoami"

echo "spacebar configuration loaded.."

reference resources

Configuration refers to the sharing of some big guys. Because it's been a long time, I don't remember some addresses. I listed what I remember below.
https://github.com/koekeishiya/yabai
https://github.com/koekeishiya/skhd
https://github.com/julian-heng/yabai-config

Tags: Mac macOS

Posted on Mon, 22 Nov 2021 07:55:03 -0500 by nova