macOS平铺窗口yabai配置分享

简介

yabai 是一个窗口管理实用程序,旨在作为 macOS 内置窗口管理器的扩展工作。yabai 允许您使用直观的命令行界面自由控制窗口、空间和显示,并可选择使用设置用户定义的键盘快捷键↗ skhd和其他第三方软件。

yabai的主要功能是平铺窗口管理;使用二进制空间分区算法自动修改窗口布局,让您专注于窗口的内容而不会分心。yabai 的其他功能包括焦点跟随鼠标、禁用切换空间的动画、创建超过 16 个空间限制的空间等等。

在这里插入图片描述

github主页:
https://github.com/koekeishiya/yabai

安装

安装方法,官方 的wiki中写的非常的清楚。建议直接看官方的wiki:
https://github.com/koekeishiya/yabai/wiki

以下是我安装时候随手记的笔记,没有专门进行整理,仅供参考。
https://blog.csdn.net/lxyoucan/article/details/121202575

配置

yabai配置

为了让其他人使用我电脑,能够适应。所以默认我是不使用bsp layout的。只有我自己用电脑的时候我才会加载这个配置。
这些配置是我专门提出来的,当我自己用电脑的时候,会手动加载这些配置。(我是按CapsLk + 0加载)

路径~/.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 为了方便其他人用电脑默认是float,我自己用时会切换到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"]}"

# 状态栏间距
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

#窗口边距设置
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 ==================================
#系统偏好设置 浮动
yabai -m rule --add app="^系统偏好设置$" manage=off
#yabai -m rule --add app="^QQ$" manage=off
#yabai -m rule --add app="^Simulator$" manage=off
yabai -m rule --add app="^提醒事项$" manage=off
yabai -m rule --add app="^关于本机$" 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"

路径~/.config/yabai/itkeyrc
这些配置是我专门提出来的,当我自己用电脑的时候,会手动加载这些配置。(我是按CapsLk + 0加载)

#!/usr/bin/env bash
#因为我的电脑偶尔会有其他人临时用一下,直接使用bsp布局可能会导致别人不会用
#所以我还是手动开始布局管理功能吧
# bsp/float 为了方便其他人用电脑默认是float,我自己用时会切换到bsp
yabai -m config layout                      bsp
# on|off 显示|不显示边框
yabai -m config window_border               on
# 边框的宽度
yabai -m config window_border_width 6
#激活的边框颜色
yabai -m config active_window_border_color 0xff775759
#普通的边框颜色
yabai -m config normal_window_border_color 0xff555555
# 状态栏间距
#yabai -m config external_bar all:26:0
yabai -m config external_bar all:0:0

skhdrc快捷键配置

路径~/.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://blog.csdn.net/lxyoucan/article/details/121209267

路径 ~/.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     一 二 三 四 五 六 七 八 九 十
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月%d日 %R"
spacebar -m config right_shell          off
spacebar -m config right_shell_icon     
spacebar -m config right_shell_command  "whoami"

echo "spacebar configuration loaded.."

参考

配置参考了一些大佬的分享。因为时间有点久了,有部分地址不记得了。我把记得的列到了下面。
https://github.com/koekeishiya/yabai
https://github.com/koekeishiya/skhd
https://github.com/julian-heng/yabai-config

猜你喜欢

转载自blog.csdn.net/lxyoucan/article/details/121451782