Preface

Long-time Linux users should be familiar with i3wm, which is significantly different from the floating (float) desktops of Mac and Windows operating systems, which are called tiling desktops. When I learned about the open source project yabai for Mac, I couldn’t wait to start using it.

Installation

Equipment status:

Homebrew is installed (You can refer to the official website)

Closed SIP

Monterey12.4

It is best to refer to Official Documents for installation, after all, the official one is the latest and most accurate.

The following is a record of your own process, which is available for your reference.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Install yabai
brew install koekeishiya/formulae/yabai
sudo yabai --install-sa
# Start yabai
brew services start yabai

# Install skhd
brew install koekeishiya/formulae/skhd
# Start skhd
brew services start skhd

########### macOS Big Sur or Monterey More Steps ###########
sudo yabai --load-sa
sudo visudo -f /private/etc/sudoers.d/yabai
# Change <user> to you own username
# yuesir ALL = (root) NOPASSWD: /usr/local/bin/yabai --load-sa
<user> ALL = (root) NOPASSWD: /usr/local/bin/yabai --load-sa
# Add to .yabairc
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"

yabai can be used with skhd, the option Secure Keyboard Entry must be disabled (off by default).

After the system starts yabai and skhd for the first time, macOS will prompt for permission to access the secondary functions. After adding permissions to System Preferences->Installability and Privacy->Privacy, execute the following command.

 Authorization assistance functions

1
2
3
# Restart
brew services restart yabai
brew services restart skhd

This is still not working properly, and you still need to configure the relevant files yourself.

Configuration

1
2
3
4
5
6
# Create yabai config
touch ~/.yabairc
chmod +x ~/.yabairc
# Create skhd config
touch ~/.skhdrc
chmod +x ~/.skhdrc

.yabairc Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env sh

# 这里参考了 yabai 的 wiki 。具体步骤下面讲
sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"

# 窗口布局 bsp: 平铺 float: 浮动
yabai -m config layout                       bsp
# 默认拆分规则 first_child second_child
yabai -m config window_placement             second_child
# 窗口间距设置
yabai -m config top_padding                  5
yabai -m config bottom_padding               5
yabai -m config left_padding                 5
yabai -m config right_padding                5
yabai -m config window_gap                   4
# 自动平衡所有窗口始终占据相同的空间
yabai -m config auto_balance                 off
# 如果禁用自动平衡,此项属性定义的是新窗口占用的空间量。0.5意为旧窗口占用50%
yabai -m config split_ratio                 0.50
# 鼠标修饰键 意思就是按着这个键就可以使用鼠标单独修改窗口大小了
yabai -m config mouse_modifier               fn
# fn + 左键 移动
yabai -m config mouse_action1                move
# fn + 右键 
yabai -m config mouse_action2                resize
# 焦点跟随鼠标 默认off: 关闭  autoraise:自动提升 autofocus: 自动对焦
yabai -m config focus_follows_mouse          autofocus
# 设置鼠标是否跟随当前活动窗口 默认 off: 关闭 on: 开启
yabai -m config mouse_follows_focus          on

# 浮动窗口问题在顶部
yabai -m config window_topmost               on
# 修改窗口阴影 on: 打开 off: 关闭 float: 只显示浮动窗口的阴影
yabai -m config window_shadow                float

# 窗口透明度设置
yabai -m config window_opacity               on
# 配置活动窗口不透明度
yabai -m config active_window_opacity        1.0             
yabai -m config normal_window_opacity        0.9
yabai -m config window_opacity_duration      0.0

# 在主显示器上的每个空间顶部添加 20 填充 底部添加 0 填充
# yabai -m config external_bar main:20:0
# 在所有显示器上的每个空间顶部添加 0 填充 底部添加 0 填充
yabai -m config external_bar all:0:5

# ================================ 规则 ================================
# 打开系统偏好设置,不使用平铺模式
yabai -m rule --add app="^系统偏好设置$" manage=off
yabai -m rule --add app="^提醒事项$" manage=off
yabai -m rule --add app="^关于本机$" manage=off

echo "yabai configuration loaded.."

.skhdrc Example:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# ================================ 窗口设置 ================================
# focus window : 激活窗口快捷键  h: 左  j: 下  k: 右 l: 上 
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 
# 交换窗口位置
shift + alt - h : yabai -m window --swap west
shift + alt - j : yabai -m window --swap south
shift + alt - k : yabai -m window --swap north
shift + alt - l : yabai -m window --swap east
# 移动窗口位置
shift + cmd - h : yabai -m window --warp west
shift + cmd - j : yabai -m window --warp south
# 因与IDEA shift + cmd + K push code 冲突,故注释了此快捷键
# shift + cmd - k : yabai -m window --warp north
shift + cmd - l : yabai -m window --warp east
# 浮动窗口设置 参考了Magent默认设置。因为之前用习惯了。。。。
# 恢复原始窗口大小
ctrl + alt - 0 : yabai -m space --balance
# 把浮动窗口左右平分整个屏幕  rows:cols:start-x:star-y:width:height  m行:n列:x:y:w:h
# 最大化
ctrl + alt - return : yabai -m window --grid 1:1:0:0:1:1
# 2分屏上
ctrl + alt - up     : yabai -m window --grid 2:1:0:0:2:1
# 2分屏左
ctrl + alt - left   : yabai -m window --grid 1:2:0:0:1:1
# 2分屏右
ctrl + alt - right  : yabai -m window --grid 1:2:1:1:1:1
# 2分屏下
ctrl + alt - down   : yabai -m window --grid 2:1:0:1:2:1
# 4分屏左上
ctrl + alt - u : yabai -m window --grid 2:2:0:0:1:1
# 4分屏右上
ctrl + alt - i : yabai -m window --grid 2:2:0:1:1:1
# 4分屏左下
ctrl + alt - j : yabai -m window --grid 2:2:1:0:1:1
# 4分屏右下
ctrl + alt - k : yabai -m window --grid 2:2:1:1:1:1
# 3分屏左1
ctrl + alt - d : yabai -m window --grid 1:3:0:0:1:1
# 3分屏左2
ctrl + alt - e : yabai -m window --grid 1:3:0:0:2:1
# 3分屏中1
ctrl + alt - f : yabai -m window --grid 1:3:1:0:1:1
# 3分屏右2
ctrl + alt - t : yabai -m window --grid 1:3:1:0:2:1
# 3分屏右1
ctrl + alt - g : yabai -m window --grid 1:3:3:0:1:1
# 9分屏居中
ctrl + alt - c : yabai -m window --grid 3:3:1:1:1:1

# 浮动/不浮动窗口 float / unfloat window and center on screen
alt - t : yabai -m window --toggle float;yabai -m window --grid 4:4:1:1:2:2

alt - r         : yabai -m space --rotate 90

# 调整窗口大小
ctrl + alt + cmd - left : yabai -m window --resize left:-50:0; yabai -m window --resize right:-50:0
ctrl + alt + cmd - down : yabai -m window --resize bottom:0:50; yabai -m window --resize top:0:50
ctrl + alt + cmd - up : yabai -m window --resize top:0:-50; yabai -m window --resize bottom:0:-50
ctrl + alt + cmd - right : yabai -m window --resize right:50:0; yabai -m window --resize left:50:0

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

# ================================ 多桌面配置  ================================
# 创建一个新桌面,并把当前活动的窗口发送到新桌面,并且自动跳转到新桌面 需要jq支持 brew install jq
shift + cmd - n : yabai -m space --create && index="$(yabai -m query --spaces --display | jq '.| length')" && yabai -m window --space "${index}" && yabai -m space --focus "${index}"

# 切换回最近的一个桌面
alt - x : yabai -m space --focus recent
# 切换回第一个桌面
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
# 关闭当前桌面
cmd + alt - w : yabai -m space --destroy

# 把窗口发送到桌面,并跟随过去 send window to desktop and follow focus
shift + cmd - z : 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
shift + cmd - 7 : yabai -m window --space  7; yabai -m space --focus 7
shift + cmd - 8 : yabai -m window --space  8; yabai -m space --focus 8
shift + cmd - 9 : yabai -m window --space  9; yabai -m space --focus 9

# ================================ APPS ================================
# iTerm2
cmd - return : open -a iTerm

# ================================ 多显示器配置 ================================
# focus monitora : 
# ctrl + alt - z  : yabai -m display --focus prev
# ctrl + alt - 3  : yabai -m display --focus 3

# send window to monitor and follow focus
# ctrl + cmd - c  : yabai -m window --display next; yabai -m display --focus next
# ctrl + cmd - 1  : yabai -m window --display 1; yabai -m display --focus 1

# move floating window
# shift + ctrl - a : yabai -m window --move rel:-20:0
# shift + ctrl - s : yabai -m window --move rel:0:20

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

# decrease window size
# shift + cmd - s : yabai -m window --resize bottom:0:-20
# shift + cmd - w : yabai -m window --resize top:0:20

# set insertion point in focused container
# ctrl + alt - h : yabai -m window --insert west

# toggle window zoom
# alt - d : yabai -m window --toggle zoom-parent
# alt - f : yabai -m window --toggle zoom-fullscreen

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

# 浮动/不浮动窗口 float / unfloat window and center on screen
#alt - t : yabai -m window --toggle float;yabai -m window --grid 4:4:1:1:2:2

# toggle sticky(+float), topmost, picture-in-picture
# alt - p : yabai -m window --toggle sticky;\
#           yabai -m window --toggle topmost;\
#           yabai -m window --toggle pip

Use

After using it for a few days, I found that skhd’s shortcuts often conflict with application or system shortcuts, which is a bit troublesome.

In addition, there are more shortcut keys, you need to use more to remember familiar, I use it again for a period of time to see the situation first.

The effect would be something like the following:

 Renderings

Looked almost well, just haven’t played around with it, efficiency didn’t improve much, unfortunately.

Thanks

yabai Open Source Project

skhd Open Source Project

Toretto