yabai是一个macOS的上的平铺桌面程序,可以达到类似linux上i3wm之类的效果。

-w1920

需要开启显示器具有单独的空间

安装

# yabai
brew install koekeishiya/formulae/yabai

# spacebar 用于代替原生status bar,需在设置中设置为自动隐藏
brew install cmacrae/formulae/spacebar

# skhd 快捷键管理工具,可以用其他的程序代理
brew install koekeishiya/formulae/skhd

sudo yabai --install-sa

# 如果是Big Sur则还需要执行该行

sudo yabai --load-sa

启动

brew services start yabai
brew services start skhd
brew services start spacebar

配置文件

yabai配置

touch ~/.yabairc
chmod +x ~/.yabairc

配置文件内容

# bsp or float (default: bsp)
yabai -m config layout bsp

# Override default layout for space 2 only
# yabai -m config --space 2 layout float

# New window spawns to the left if vertical split, or top if horizontal split
yabai -m config window_placement first_child

# New window spawns to the right if vertical split, or bottom if horizontal split
yabai -m config window_placement second_child


# Set all padding and gaps to 20pt (default: 0)
yabai -m config top_padding    20
yabai -m config bottom_padding 20
yabai -m config left_padding   20
yabai -m config right_padding  20
yabai -m config window_gap     20

# Override gaps for space 2 only
# yabai -m config --space 2 window_gap 0

# on or off (default: off)
yabai -m config auto_balance on

# set mouse interaction modifier key (default: fn)
yabai -m config mouse_modifier fn

# set modifier + left-click drag to resize window (default: move)
yabai -m config mouse_action1 move

# set modifier + right-click drag to resize window (default: resize)
yabai -m config mouse_action2 resize

# set focus follows mouse mode (default: off, options: off, autoraise, autofocus)
yabai -m config focus_follows_mouse autoraise

# set mouse follows focus mode (default: off)
# yabai -m config mouse_follows_focus on

# floating windows are always on top (default: off)
yabai -m config window_topmost on

# modify window shadows (default: on, options: on, off, float)
# example: show shadows only for floating windows
yabai -m config window_shadow float

# window opacity (default: off)
# example: render all unfocused windows with 90% opacity
# 窗口透明度设置
yabai -m config window_opacity off
yabai -m config active_window_opacity 1.0
yabai -m config normal_window_opacity 0.95

# add 20 padding to the top and 0 padding to the bottom of every space located on the main display
yabai -m config external_bar main:20:0
# add 20 padding to the top and bottom of all spaces regardless of the display it belongs to
yabai -m config external_bar all:20:20


# 临时性的App 也就是manage=off不受到yabai平铺式的限制,之前怎么弹出来就怎么弹出来
otherApp='^(IINA|Calendar|日历|System Preferences|系统偏好设置|Xnip|GoLand|微信)$'
yabai -m rule --add app="${otherApp}" manage=off


space_1='(iTerm2)'
yabai -m rule --add label=space_1 app=$(space_1) space=2

# space_1='(iTerm2)'
# yabai -m rule --add label=space_1 app=$(space_1) space=1

yabai -m rule --add label=safari app="^Safari$" space=2

# ====== Border settings =======================
normal_border_color="010101"
focused_border_color="FFD700"
preselect_border_color="2d74da"


yabai -m config window_border               on
yabai -m config window_border_width         2
yabai -m config active_window_border_color  "0xE0${focused_border_color}"
yabai -m config insert_window_border_color  "0xE0${preselect_border_color}"
yabai -m config normal_window_border_color  "0x00${normal_border_color}"


skhd 配置

touch ~/.skhdrc
chmod +x ~/.skhdrc

配置内容

# opens iTerm2(暂时隐藏了,因为权限太高了,导致AS快捷键都捕获不到,热键冲突)
#alt - return : "${HOME}"/.config/yabai/scripts/open_iterm2.sh


# Show system statistics


# Navigation
alt - h : yabai -m window --focus west
alt - j : yabai -m window --focus south
alt - k : yabai -m window --focus north
alt - l : yabai -m window --focus east

# Moving 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


# Resize windows
shift+ cmd - h : \
    yabai -m window --resize left:-20:0 ; \
    yabai -m window --resize right:-20:0

shift + cmd - j : \
    yabai -m window --resize bottom:0:20 ; \
    yabai -m window --resize top:0:20

shift + cmd - k : \
    yabai -m window --resize top:0:-20 ; \
    yabai -m window --resize bottom:0:-20

shift + cmd - l : \
    yabai -m window --resize right:20:0 ; \
    yabai -m window --resize left:20:0

# Float and center window
shift + alt - c : yabai -m window --toggle float;\
                  yabai -m window --grid 4:4:1:1:2:2

# Equalize size of windows
lctrl + alt - 0 : yabai -m space --balance

# Enable / Disable gaps in current workspace
lctrl + alt - g : yabai -m space --toggle padding; yabai -m space --toggle gap

# Rotate windows clockwise and anticlockwise
alt - r         : yabai -m space --rotate 90
shift + alt - r : yabai -m space --rotate 270

# Rotate on X and Y Axis
shift + alt - x : yabai -m space --mirror x-axis
shift + alt - y : yabai -m space --mirror y-axis

# Set insertion point for focused 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

# Float / Unfloat window (更换 layout 方式) w
shift + alt - space : yabai -m window --toggle float

# Restart Yabai
shift + cmd + alt - r :
    /usr/bin/env osascript <<< \
        "display notification \"Restarting Yabai\" with title \"Yabai\""; \
    launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"

# Make window native fullscreen
alt - f         : yabai -m window --toggle zoom-fullscreen
# lctrl + alt - s       : yabai -m window --toggle split
shift + alt - f : yabai -m window --toggle native-fullscreen

# toggle window split type
alt - e : yabai -m window --toggle split

# increase window size 竖直方向才能用 top  水平方向才能用 left
shift + alt - d : yabai -m window --resize left:-20:0
shift + alt - w : yabai -m window --resize top:0:-20


# decrease window size
shift + alt - a : yabai -m window --resize left:20:0
shift + alt - s : yabai -m window --resize top:0:20


# fast focus desktop (切换空间焦点)
 cmd + alt - x : yabai -m space --focus recent
 cmd + alt - z : yabai -m space --focus prev
 cmd + alt - c : yabai -m space --focus next
# 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

# create new space
ctrl - n : yabai -m space --create
ctrl - m : yabai -m space --destroy

# destroy empty spaces
shift + cmd + alt - w : echo "destroy empty spaces";\
                        yabai -m query --spaces \
                        | jq 'reverse | .[] | select((.windows | length) == 0) | .index' \
                        | xargs -I{} yabai -m space {} --destroy \;

# send window to space
ctrl + shift - 1 : yabai -m window --space 1
ctrl + shift - 2 : yabai -m window --space 2
ctrl + shift - 3 : yabai -m window --space 3
ctrl + shift - 4 : yabai -m window --space 4
ctrl + shift - 5 : yabai -m window --space 5
ctrl + shift - 6 : yabai -m window --space 6
ctrl + shift - 7 : yabai -m window --space 7
ctrl + shift - 8 : yabai -m window --space 8
ctrl + shift - 9 : yabai -m window --space 9
ctrl + shift - 0 : yabai -m window --space 10

# Move focus container to workspace
shift + cmd - m : yabai -m window --space last && yabai -m space --focus last
shift + cmd - b : yabai -m window --space prev && yabai -m space --focus prev
shift + cmd - n : yabai -m window --space next && yabai -m space --focus next
shift + cmd - 1 : yabai -m window --space 1 && yabai -m space --focus 1
shift + cmd - 2 : yabai -m window --space 2 && yabai -m space --focus 2
shift + cmd - 3 : yabai -m window --space 3 && yabai -m space --focus 3
shift + cmd - 4 : yabai -m window --space 4 && yabai -m space --focus 4
shift + cmd - 5 : yabai -m window --space 5 && yabai -m space --focus 5
shift + cmd - 6 : yabai -m window --space 6 && yabai -m space --focus 6


alt + ctrl - f : yabai -m space --layout float && \
                 yabai -m config window_border off
alt + ctrl - b : yabai -m space --layout bsp && \
                 yabai -m config window_border on



spacebar配置

需要先安装Font-Awesome字体

 mkdir -p ~/.config/spacebar
 touch ~/.config/spacebar/spacebarrc
 chmod +x ~/.config/spacebar/spacebarrc
 vscode ~/.config/spacebar/spacebarrc

配置文件内容

spacebar -m config position           top
spacebar -m config height             26
spacebar -m config spacing_left       25
spacebar -m config spacing_right      15
spacebar -m config text_font          "Helvetica Neue:Bold:13.0"
spacebar -m config icon_font          "Hack Nerd Font Mono:Regular:13.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 space_icon_strip   1 2 3 4 5 6 7 8 9 10
spacebar -m config power_icon_strip    
spacebar -m config space_icon         
spacebar -m config clock_icon         
spacebar -m config dnd_icon           
spacebar -m config clock_format       "%Y-%m-%d %R:%S"

重启

brew services restart yabai
brew services restart skhd
brew services restart spacebar

标签: none