itgoyo / 500Days-Of-Github

⭐ 瞎JB折腾Mac/Linux/Windows过程中遇到的所有问题和解决方式 ⭐
https://itgoyo.github.io/500Days-Of-Github
142 stars 14 forks source link

Mac安装Yabai的过程 #224

Open itgoyo opened 4 years ago

itgoyo commented 4 years ago

我的Yabai配置文件地址:https://github.com/itgoyo/yabai-config 视频安装教程:https://space.bilibili.com/12767066

重要2020-12-8补充:你们最好先更新brew到最新版本使用命令 brew update -v 如果你们不先更新brew的话,导致你们brew install yabai或者是spacebar的版本都不会是最新版本的

1. 什么是平铺式窗口管理器 (Tiling window manager)

首先它是一个窗口管理器,可以快速选中需要操作的窗口,平铺窗口的特点就是不会相互重叠覆盖, 看两个图就能明白: 下面这个是普通的 mac 窗口布局

下面这个是经过 yabai 管理后的窗口布局 平铺式窗口管理器允许窗口分组、 窗口分割、快速切换、调整窗口大小、切换焦点位置等等。

可以去这里看下 i3wm 的介绍,你会有更加直观的印象。 (i3wm 是一款很出名的平铺式窗口管理器,可惜 mac 用不了)

2. yabai 是什么

mac 用不了 i3wm,只能去找下替代品,找了半天,找到了 yabai, 名字是挺奇怪的,用起来感觉还不错。 yabai 是在 chunkwm 的基础上重写的,而 chunkwm 是在 kwm 的基础上重写的... 不知道以后会不会有 yabai2...

3. 安装 yabai

  1. 关闭 SIP (系统完整性保护) 具体参考这里: https://www.jianshu.com/p/fe78d2036192

  2. 安装 homebrew 大部分 mac 应该都装了,没装的参考官网步骤即可: https://brew.sh/

  3. 安装 yabai

brew tap koekeishiya/formulae
brew install yabai
sudo yabai --install-sa
  1. 安装快捷键支持:
brew install koekeishiya/formulae/skhd
  1. 拷贝默认配置:
curl https://raw.githubusercontent.com/koekeishiya/yabai/master/examples/yabairc --output ~/.yabairc
curl https://raw.githubusercontent.com/koekeishiya/yabai/master/examples/skhdrc --output ~/.skhdrc
  1. 配置字体 需要本机安装下 https://fontawesome.com/v4.7.0/, 直接下载压缩包解压点击字体文件即可,后续的定制化需要用到这些字体图标

  2. 启动服务

brew services start skhd
brew services start yabai

第一次启动会请求授权,请求授权后 restart 即可

brew services restart skhd
brew services restart yabai

启动后会发现窗口不太好控制了 (不能浮动), 使用快捷键 ctrl+alt+d 就能切回普通的浮动模式,ctrl+alt+a 可以切回你需要熟悉的平铺模式。

全部安装完成后,最好重启下电脑。

4. 自定义配置

这里贴一下我的配置,里面包含了一些中文注释

vim ~/.skhdrc
# open terminal
# cmd - return : /Applications/iTerm2.app

# focus window(同一个空间切换窗口焦点)
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

# swap window(同一个空间调整窗口位置)
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

# move window
# shift + cmd - h : yabai -m window --warp west
# shift + cmd - j : yabai -m window --warp south
# shift + cmd - k : yabai -m window --warp north
# shift + cmd - l : yabai -m window --warp east

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

# make floating window fill screen
# shift + alt - up     : yabai -m window --grid 1:1:0:0:1:1

# make floating window fill left-half of screen
# shift + alt - left   : yabai -m window --grid 1:2:0:0:1:1

# make floating window fill right-half of screen
# shift + alt - right  : yabai -m window --grid 1:2:1:0:1:1

# create desktop, move window and follow focus - uses jq for parsing json (brew install jq)
shift + cmd - n : yabai -m space --create && \
                  index="$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')" && \
                  yabai -m window --space "${index}" && \
                  yabai -m space --focus "${index}"

# create desktop and follow focus - uses jq for parsing json (brew install jq)
cmd + alt - n : yabai -m space --create && \
                index="$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')" && \
                yabai -m space --focus "${index}"

# destroy desktop
cmd + alt - w : yabai -m space --destroy

# 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

# send window to desktop and follow focus(将当前活跃窗口发送到指定空间)
# shift + cmd - x : yabai -m window --space recent; yabai -m space --focus recent
# shift + cmd - z : yabai -m window --space prev; yabai -m space --focus prev
# shift + cmd - c : 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
shift + cmd - 0 : yabai -m window --space 10; yabai -m space --focus 10

# focus monitor(切换显示器焦点)
# ctrl + alt - x  : yabai -m display --focus recent
# ctrl + alt - z  : yabai -m display --focus prev
# ctrl + alt - c  : yabai -m display --focus next
ctrl + alt - 1  : yabai -m display --focus 1
ctrl + alt - 2  : yabai -m display --focus 2
ctrl + alt - 3  : yabai -m display --focus 3

# send window to monitor and follow focus(将当前活跃窗口发送到指定显示器)
# ctrl + cmd - x  : yabai -m window --display recent; yabai -m display --focus recent
# ctrl + cmd - z  : yabai -m window --display prev; yabai -m display --focus prev
# 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
ctrl + cmd - 2  : yabai -m window --display 2; yabai -m display --focus 2
ctrl + cmd - 3  : yabai -m window --display 3; yabai -m display --focus 3

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

# increase window size(增加窗口大小aswd)
shift + alt - a : yabai -m window --resize left:-20:0
shift + alt - s : yabai -m window --resize bottom:0:20
shift + alt - w : yabai -m window --resize top:0:-20
shift + alt - d : yabai -m window --resize right:20:0

# decrease window size(减少窗口大小aswd)
shift + cmd - a : yabai -m window --resize left:20:0
shift + cmd - s : yabai -m window --resize bottom:0:-20
shift + cmd - w : yabai -m window --resize top:0:20
shift + cmd - d : yabai -m window --resize right:-20:0

# set insertion point in focused container
ctrl + alt - h : yabai -m window --insert west
ctrl + alt - j : yabai -m window --insert south
ctrl + alt - k : yabai -m window --insert north
ctrl + alt - l : yabai -m window --insert east

# rotate tree(逆时针旋转空间多个窗口)
alt - r : yabai -m space --rotate 90

# mirror tree y-axis(纵轴调换窗口)
alt - y : yabai -m space --mirror y-axis

# mirror tree x-axis(横轴调换窗口)
alt - x : yabai -m space --mirror x-axis

# toggle desktop offset
alt - a : yabai -m space --toggle padding; yabai -m space --toggle gap

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

# toggle window fullscreen zoom(单个窗口进入或退出全屏)
alt - f : yabai -m window --toggle zoom-fullscreen

# toggle window native fullscreen(单个窗口进入或退出真全屏-上方的icon都会消失)
shift + alt - f : yabai -m window --toggle native-fullscreen

# toggle window border
shift + alt - b : yabai -m window --toggle border

# toggle window split type(切换分割方式)
alt - e : yabai -m window --toggle split

# float / unfloat window and center on screen(控制窗口是否进入float模式,进入的话就不会自动被排列)
alt - t : yabai -m window --toggle float;\
          yabai -m window --grid 4:4:1:1:2:2

# toggle sticky (show on all spaces)
alt - s : yabai -m window --toggle sticky

# toggle topmost (keep above other windows)
alt - o : yabai -m window --toggle topmost

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

# change layout of desktop(更换layout方式)
ctrl + alt - a : yabai -m space --layout bsp
ctrl + alt - d : yabai -m space --layout float
vim ~/.yabairc
#!/usr/bin/env sh

# bar settings
# 打开状态栏
yabai -m config status_bar                   on
yabai -m config status_bar_text_font         "Helvetica Neue:Bold:12.0"
yabai -m config status_bar_icon_font         "FontAwesome:Regular:12.0"
yabai -m config status_bar_background_color  0xff202020
yabai -m config status_bar_foreground_color  0xffa8a8a8
# 使用font-awesome替代罗马数字
yabai -m config status_bar_space_icon_strip                8 9  
yabai -m config status_bar_power_icon_strip   
yabai -m config status_bar_space_icon        
yabai -m config status_bar_clock_icon        

# global settings
yabai -m config mouse_follows_focus          off
yabai -m config focus_follows_mouse          off
yabai -m config window_placement             second_child
yabai -m config window_topmost               off
yabai -m config window_opacity               off
yabai -m config window_opacity_duration      0.0
yabai -m config window_shadow                off
yabai -m config window_border                off
yabai -m config window_border_placement      inset
yabai -m config window_border_width          1
yabai -m config window_border_radius         -1.0
yabai -m config active_window_border_topmost off
yabai -m config active_window_border_color   0xff775759
yabai -m config normal_window_border_color   0xff505050
yabai -m config insert_window_border_color   0xffd75f5f
yabai -m config active_window_opacity        1.0
yabai -m config normal_window_opacity        0.95
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

# general space settings(设置间隔,都设置成0)
yabai -m config layout                       bsp
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_gap                   0

echo "yabai configuration loaded.."

font-awesome 图标可以直接在这里复制拷贝进来,就是直接复制图标 (不是文字),当然本地需要先安装字体。

配置后需要重启服务。

5. 自动隐藏 mac 自带菜单栏

自动隐藏自带菜单栏可以极大提高整体美观度,可以通过下面这个路径来进行设置:系统偏好设置 -> 通用 -> 勾选自动隐藏和显示菜单

6. 最终效果

最最重要的几个快捷键:

原文地址:https://www.kancloud.cn/ichenpeng/blog/1445752

itgoyo commented 4 years ago

!!!重点!!! 如果想使用border的功能,要安装低版本的【好像是2.1.4还是多少来着忘记了】

brew unlink yabai

brew install https://raw.githubusercontent.com/koekeishiya/homebrew-formulae/026eefaade6cc3e73fc98beb6122fced164d5e10/yabai.rb
itgoyo commented 4 years ago

但是个人使用感受上面Border上确实感觉不是很受用,还是用Hazeover比较舒服一些

最新的破解版本: https://share.weiyun.com/cunpN6BW

itgoyo commented 3 years ago

最新版本对于boder的支持已经很好了,至少相比于之前的要好上不少,但是我的窗口快速移动的是moom,导致border在我移动的时候没有跟上来,反正就是错位的意思,我就把border的开关改成了off

itgoyo commented 3 years ago

MacOS Big Sur版本出现插件不能启动的解决方式: cannot focus space due to an error with the scripting-addition

sudo yabai --load-sa

详细参考:https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)

itgoyo commented 3 years ago

Big Sur快捷键不起反应,输入以下代码即可

sudo yabai --uninstall-sa
sudo yabai --install-sa
sudo yabai --load-sa
itgoyo commented 3 years ago

如果在终端输入yabai出现,cannot focus space due to an error with the scripting-addition 输入以下命令行修复:

brew services stop yabai
brew services stop skhd

sudo yabai --uninstall-sa
sudo yabai --install-sa

brew services start yabai
brew services start skhd

sudo yabai --load-sa
itgoyo commented 3 years ago

冥王峡谷安装过程的所有命令

695  export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
  696  brew install koekeishiya/formulae/yabai
  697  sudo yabai --install-sa
  698  sudo yabai --load-sa
  699  brew services start yabai
  700  brew upgrade yabai
  701  brew install cmacrae/formulae/spacebar
  702  brew services start spacebar
  703  ls
  704  cd .config
  705  ls
  706  cd
  707  rm -f "${HOME}"/.{yabai,skhd}rc
  708  git clone https://github.com/itgoyo/yabai-config.git "${HOME}"/.config/yabai
  709  ln -s "${HOME}/.config/yabai/yabai/yabairc" "${HOME}/.yabairc"
  710  ln -s "${HOME}/.config/yabai/yabai/skhdrc" "${HOME}/.skhdrc"
  711  cd .config
  712  ls
  713  brew services start spacebar
  714  brew services start yabai
  715  sudo yabai --load-sa
  716  code .config/yabai
  717  sudo yabai --install-sa
  718  sudo yabai --load-sa
  719  clear
  720  cd .config
  721  ls
  722  cd yabai
  723  ls
  724  cd
  725  ls
  726  ll
  727  open .
  728  code .config/yabai
  729  mkdir -p ~/.config/spacebar
  730  touch ~/.config/spacebar/spacebarrc
  731  chmod +x ~/.config/spacebar/spacebarrc
  732  code .config/spacebar
  733  brew services start yabai
  734  brew services start spacebar
  735  code .config/yabai
  736  yabai -m space --create
  737  brew services start yabai
  738  yabai -m space --create
  739  sudo yabai --uninstall-sa
  740  sudo yabai --install-sa
  741  sudo yabai --load-sa
  742  yabai -m space --create
  743  yabai -m space --destory
  744  code .skhdrc
  745  '/usr/bin/env osascript <<< \\n        "display notification \"Restarting Yabai\" with title \"Yabai\""; \\n    launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"'
  746  'yabai -m window --insert west'
  747  yabai -m window --insert west
  748  yabai -m window --insert south
  749  sudo yabai --load-sa
  750  'yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"'
  751  brew services stop yabai
  752  brew upgrade yabai
  753  sudo yabai --uninstall-sa
  754  sudo yabai --install-sa
  755  brew services start yabai
  756  touch .config/skhd/skhdrc
  757  mkdir -p ~/.config/skhd
  758  touch .config/skhd/skhdrc
  759  code .config/skhd/skhdrc
  760  brew services restart yabai
  761  brew install koekeishiya/formulae/skhd
  762  export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
  763  brew install koekeishiya/formulae/skhd
  764  brew services start skhd
  765  code .config/skhd/skhdrc
  766  brew services start yabai
  767  code .config/skhd/skhdrc
  768  yabai -m space --focus 2
  769  yabai
  770  yabai -m space --focus 2
  771  ls
  772  chmod -x .config/skhd/skhdrc
  773  yabai -m space --focus 2
  774  chmod -x .skhdrc
  775  chmod -x .config/skhd/skhdrc
  776  code .config/skhd/skhdrc
  777  yabai -m space --focus 2
  778  yabai
  779  yabai -v
  780  brew services stop yabai
  781  brew services stop skhd
  782  sudo yabai --uninstall-sa
  783  sudo yabai --install-sa
  784  brew services start yabai
  785  brew services start skhd
  786  sudo yabai --load-sa
itgoyo commented 3 years ago

Big Sur这个系统里面,每次重启都需要自行的在终端输入sudo yabai --load-sa这行命令yabai才能正常启动, 为了解决这种情况,作者给出了解决方案: sudo visudo -f /private/etc/sudoers.d/yabai 然后编辑; <user> ALL = (root) NOPASSWD: /usr/local/bin/yabai --load-sa 里面的<user>就是你的用户名,如果不知道是什么你可以在终端输入whoami 我的内容如下:

itgoyo ALL = (root) NOPASSWD: /usr/local/bin/yabai --load-sa

然后在yabairc配置文件里面的首行复制一下命令:

sudo yabai --load-sa
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"