MacOS平铺窗口管理配置记录分享
# MacOS平铺窗口管理## 方案1:yabai
+ 软件准备
- (https://github.com/koekeishiya/yabai)
- (https://github.com/koekeishiya/skhd)
- (https://github.com/koekeishiya/limelight)
- ()
- ()
- (https://github.com/AdamWagner/stackline)
- ()
> 注:M1芯片 在官方没有merge的情况下,使用https://github.com/xorpse/yabai
### 安装
安装过程
0. 禁用SIP
> 禁用系统完整性保护(Disable System Integrity Protection)
+ yabai 的以下功能需要(部分)禁用系统完整性保护:
- 在没有动画的情况下聚焦/创建/破坏空间
- 向左、向右或向另一个显示器移动空间(及其窗口)
- 去除窗口阴影
- 启用窗口透明度
- 控制窗口层(使窗口出现在最上面)
- 粘性窗口(使窗口出现在所有空间)
- 通过单击其框架中的任意位置来移动窗口
- 为任何给定窗口切换画中画
- 聚焦和非活动窗口的边框
```
recovery(恢复模式)下,解锁SIP
# 查看SIP状态
$ csrutil status
System Integrity Protection status: enable/disabled.
注意:如果是 enable ,代表SIP开启;
如果是 disabled ,代表SIP关闭,即解锁SIP。
关机重启,进入OpenCore引导选择界面,进入recovery模式,打开工具->终端;执行以下命令
csrutil disable
csrutil authenticated-root disable
```
+ 在OpenCore中关闭SIP
```
NVRAM
Add
7C436110-AB2A-4BBB-A880-FE41995C9F82
csr-active-config 类型<Data>值: 67000000
```
```
brew install koekeishiya/formulae/yabai
# install the scripting addition
sudo yabai --install-sa
# if macOS Big Sur, load the scripting addition manually; follow instructions below to automate on startup
sudo yabai --load-sa
# 启用 yabai
brew services start yabai
首次启动会申请权限,允许它即可。
# 更新
# stop, and upgrade yabai
brew services stop yabai
brew upgrade yabai
# uninstall the scripting addition
sudo yabai --uninstall-sa
# installing the scripting addition will restart Dock.app
sudo yabai --install-sa
# finally, start yabai
brew services start yabai
```
+ 配置
```
# 每个用户的 yabai 配置文件必须是可执行的;它只是一个在 yabai 启动之前运行的 shell 脚本。它必须放置在以下位置之一(按顺序):
$XDG_CONFIG_HOME/yabai/yabairc
$HOME/.config/yabai/yabairc
$HOME/.yabairc
# create empty configuration file and make it executable
touch ~/.yabairc
chmod +x ~/.yabairc
```
+ 配置例子
```
#窗口平铺or浮动 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 0
# 底部填充
yabai -m config bottom_padding 5
yabai -m config left_padding 5
yabai -m config right_padding5
yabai -m config window_gap 5
# Override gaps for space 2 only
yabai -m config --space 2 window_gap 0
# on or off (default: off)
yabai -m config auto_balance off
# Floating point value between 0 and 1 (default: 0.5)
yabai -m config split_ratio 0.5
# 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 on
yabai -m config active_window_opacity 1.0
yabai -m config normal_window_opacity 0.9
#窗口与状态栏之间的间距设置
# 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:5: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:5:5
```
+ skhdrc快捷键配置
```
# Works without yabai:
# 打开iTerm
shift + ctrl + alt + cmd - return : "${HOME}"/.config/yabai/scripts/open_iterm2.sh
# 打开Chrome浏览器
shift + ctrl + alt + cmd - b : open -na /Applications/Google\ Chrome.app
#加载专属配置
shift + ctrl + alt + cmd - 0 :\
/usr/bin/env osascript <<< \
"display notification \"ITKEY 专属配置加载中\" with title \"yabai\""; \
source /Users/itkey/.config/yabai/itkeyrc
# yabai相关配置
# ---------Space(虚拟桌面)---------
# 关闭当前 Space(虚拟桌面)
shift + ctrl + alt + cmd - w : yabai -m space --destroy
# 创建一下新的Space在最右侧
shift + ctrl + alt + cmd - n : yabai -m space --create
#精准切换space 方案一
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
#精准切换space 方案二
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
#下一个space如果没有则切换到第1个
alt - l : yabai -m space --focus next || yabai -m space --focus first
#alt - l : yabai -m space --focus next
#上一个space如果没有则切换到最后1个
alt - h : yabai -m space --focus prev || yabai -m space --focus last
#alt - h : yabai -m space --focus prev
#切换到第1个space
alt - k : yabai -m space --focus first
#切换到最后1个space
alt - j : yabai -m space --focus last
#两个space之间相互切换
alt - tab : yabai -m space --focus recent
#启用/禁用当前工作区中的间隙
shift + ctrl + alt + cmd - g : yabai -m space --toggle padding; yabai -m space --toggle gap
# 在 X 和 Y 轴上旋转
shift + alt - x : yabai -m space --mirror x-axis
shift + alt - y : yabai -m space --mirror y-axis
# ---------窗口---------
# 切换窗口焦点
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
# 移动窗口
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
# 窗口移动到别的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
#均衡窗口大小
shift + ctrl + alt + cmd - e : yabai -m space --balance
# 顺时针和逆时针旋转窗口
alt - r : yabai -m space --rotate 270
shift + alt - r : yabai -m space --rotate 90
# 调整窗口大小
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
# 设置焦点容器的插入点
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
# 浮动/非浮动窗口
shift + alt - space : \
yabai -m window --toggle float; \
yabai -m window --toggle border
# 窗口全屏显示
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
#切换垂直|水平分割布局
shift + ctrl + alt + cmd - s : yabai -m window --toggle split
#--------- yabai 其他选项---------------
# 重启 Yabai
shift + lctrl + alt - r : \
/usr/bin/env osascript <<< \
"display notification \"正在重启 Yabai\" with title \"Yabai\""; \
launchctl kickstart -k "gui/${UID}/homebrew.mxcl.yabai"
#切换当前窗口边框是否显示
shift + lctrl + alt - b : yabai -m window --toggle border
```
+ spacebar配置
> macOS 的最小状态栏。非常适合与 yabai 等平铺窗口管理器一起使用。
```
https://github.com/cmacrae/spacebar
安装
可以使用 Homebrew 从cmacrae/formulae水龙头安装空格键.
brew install cmacrae/formulae/spacebar
brew services start spacebar
辅助功能权限
空格键使用 macOS 辅助功能 API - 启动空格键后,系统会提示您授予访问权限。
打开 System Preferences.app 并导航到安全和隐私,然后是隐私,然后是辅助功能。单击底部的锁定图标并输入您的密码以允许更改列表。选中空格键旁边的框以允许访问权限。
配置
空格键是config通过其消息套接字设置属性来配置的。这不仅意味着您可以尝试实时更改配置,还意味着空格键的配置文件只是一个 shell 脚本——通常只是一个spacebar -m config 语句序列。
空格键的配置文件必须是可执行的,并且默认在以下位置(按此顺序)查找:
$XDG_CONFIG_HOME/spacebar/spacebarrc
$HOME/.config/spacebar/spacebarrc
$HOME/.spacebarrc
入门
首先,创建一个空的配置文件并使其可执行:
mkdir -p ~/.config/spacebar
touch ~/.config/spacebar/spacebarrc
chmod +x ~/.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 I II III IV V VI VII VIII IX X
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 right_shell on
spacebar -m config right_shell_icon ?
spacebar -m config right_shell_command"whoami"
echo "spacebar configuration loaded.."
字体乱码解决
安装字体
下载页面:
https://fontawesome.com/v5.15/how-to-use/on-the-desktop/setup/getting-started
最终下载地址是:
https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-desktop.zip
```
- [白苹果禁用方法请参考](https://github.com/koekeishiya/yabai/wiki/Disabling-System-Integrity-Protection)
- (
https://blog.csdn.net/lxyoucan/article/details/111984354)
- (https://blog.csdn.net/lxyoucan/article/details/121209267)
> 参考资料
- [《macOS平铺窗口yabai配置分享》](https://blog.csdn.net/lxyoucan/article/details/121451782)
- [文档地址](https://docs.google.com/presentation/d/1_QmeV3yoDrTvvjDCroOWdhHpvzCtoRUYtq0qmByiYwA/edit?usp=sharing)
- (https://www.cnblogs.com/tdg-yyx/p/15972309.html)
页:
[1]