mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-03-21 08:59:28 +01:00
Merge pull request #46 from ryan4yin/darwin-wm
feat: window manager for darwin - yabai
This commit is contained in:
@@ -55,6 +55,9 @@ in {
|
||||
nushell # my custom shell
|
||||
gnugrep # replacee macos's grep
|
||||
gnutar # replacee macos's tar
|
||||
|
||||
# darwin only apps
|
||||
utm # virtual machine
|
||||
];
|
||||
environment.variables =
|
||||
{
|
||||
@@ -159,7 +162,6 @@ in {
|
||||
# "anki"
|
||||
"shadowsocksx-ng" # proxy tool
|
||||
"iina" # video player
|
||||
"syncthing" # file sync
|
||||
"raycast" # (HotKey: alt/option + space)search, caculate and run scripts(with many plugins)
|
||||
"stats" # beautiful system status monitor in menu bar
|
||||
"eudic" # 欧路词典
|
||||
|
||||
@@ -88,7 +88,8 @@
|
||||
};
|
||||
|
||||
# customize settings that not supported by nix-darwin directly
|
||||
# see the source code of https://github.com/rgcr/m-cli to get all the available options
|
||||
# All available settings can be found here:
|
||||
# https://github.com/yannbertrand/macos-defaults
|
||||
CustomUserPreferences = {
|
||||
".GlobalPreferences" = {
|
||||
# automatically switch to a new space when switching to the application
|
||||
@@ -113,6 +114,16 @@
|
||||
DSDontWriteNetworkStores = true;
|
||||
DSDontWriteUSBStores = true;
|
||||
};
|
||||
"com.apple.spaces" = {
|
||||
"spans-displays" = 0; # Display have seperate spaces
|
||||
};
|
||||
"com.apple.WindowManager" = {
|
||||
EnableStandardClickToShowDesktop = 0; # Click wallpaper to reveal desktop
|
||||
StandardHideDesktopIcons = 0; # Show items on desktop
|
||||
HideDesktop = 0; # Do not hide items on desktop & stage manager
|
||||
StageManagerHideWidgets = 0;
|
||||
StandardHideWidgets = 0;
|
||||
};
|
||||
"com.apple.screensaver" = {
|
||||
# Require password immediately after sleep or screen saver begins
|
||||
askForPassword = 1;
|
||||
|
||||
3
modules/darwin/wm/default.nix
Normal file
3
modules/darwin/wm/default.nix
Normal file
@@ -0,0 +1,3 @@
|
||||
{mylib, ...}: {
|
||||
imports = mylib.scanPaths ./.;
|
||||
}
|
||||
18
modules/darwin/wm/skhd.nix
Normal file
18
modules/darwin/wm/skhd.nix
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
config,
|
||||
username,
|
||||
...
|
||||
}: {
|
||||
services.skhd = {
|
||||
enable = true;
|
||||
skhdConfig = builtins.readFile ./skhdrc;
|
||||
};
|
||||
|
||||
# custom log path for debugging
|
||||
launchd.user.agents.skhd.serviceConfig = let
|
||||
homeDir = config.users.users."${username}".home;
|
||||
in {
|
||||
StandardErrorPath = "${homeDir}/Library/Logs/skhd.stderr.log";
|
||||
StandardOutPath = "${homeDir}/Library/Logs/skhd.stdout.log";
|
||||
};
|
||||
}
|
||||
69
modules/darwin/wm/skhdrc
Normal file
69
modules/darwin/wm/skhdrc
Normal file
@@ -0,0 +1,69 @@
|
||||
# 配置语法 : <modifier> - <key> : <command>
|
||||
# modifier 可以是单个键比如 cmd, alt, ctrl, 也可以是组合键比如 ctrl + shift, ctrl + alt
|
||||
# ================================ 打开终端 ================================
|
||||
# 启动终端
|
||||
cmd - return : open -a kitty
|
||||
# 关闭当前窗口,这个不需要加,macOS 默认是 cmd + q,我 Linux 也这么设置的
|
||||
# ================================ 窗口设置 ================================
|
||||
# =============== 为了避免快捷键冲突改用了 ctrl 作为 modifier =================
|
||||
# https://github.com/koekeishiya/yabai/wiki/Commands
|
||||
# 切换为平铺模式
|
||||
alt - e : yabai -m space --layout bsp
|
||||
# 切换为堆叠模式
|
||||
alt - s : yabai -m space --layout stack
|
||||
# 浮动/不浮动窗口 float
|
||||
alt - f : yabai -m window --toggle float
|
||||
|
||||
# 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
|
||||
|
||||
# 调整窗口大小
|
||||
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}" && yabai -m space --layout bsp
|
||||
|
||||
# 在 stack 模式下通过方向键切换窗口
|
||||
ctrl - down : yabai -m window --focus stack.next || yabai -m window --focus south
|
||||
ctrl - up : yabai -m window --focus stack.prev || yabai -m window --focus north
|
||||
# 在 bsp 模式下通过方向键切换窗口
|
||||
cmd - left : yabai -m window --focus west
|
||||
cmd - right : yabai -m window --focus east
|
||||
|
||||
# 切换回最近的一个桌面
|
||||
alt - x : yabai -m space --focus recent
|
||||
# 在 9 个桌面之间切换
|
||||
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
|
||||
|
||||
|
||||
32
modules/darwin/wm/yabai.nix
Normal file
32
modules/darwin/wm/yabai.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
username,
|
||||
...
|
||||
}: let
|
||||
homeDir = config.users.users."${username}".home;
|
||||
in {
|
||||
services.yabai = {
|
||||
enable = true;
|
||||
|
||||
# Whether to enable yabai's scripting-addition.
|
||||
# SIP must be disabled for this to work.
|
||||
# https://github.com/koekeishiya/yabai/wiki/Disabling-System-Integrity-Protection
|
||||
enableScriptingAddition = true;
|
||||
# config = {};
|
||||
extraConfig = builtins.readFile ./yabairc;
|
||||
};
|
||||
|
||||
# custom log path for debugging
|
||||
launchd.user.agents.yabai.serviceConfig = {
|
||||
StandardErrorPath = "${homeDir}/Library/Logs/yabai.stderr.log";
|
||||
StandardOutPath = "${homeDir}/Library/Logs/yabai.stdout.log";
|
||||
};
|
||||
|
||||
launchd.daemons.yabai-sa = {
|
||||
# https://github.com/koekeishiya/yabai/issues/1287
|
||||
script = lib.mkForce ''
|
||||
echo "skip it"
|
||||
'';
|
||||
};
|
||||
}
|
||||
61
modules/darwin/wm/yabairc
Normal file
61
modules/darwin/wm/yabairc
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# wiki 要求在配置最前面加这个,看起来是跟 sudo 权限相关的东西
|
||||
sudo yabai --load-sa
|
||||
yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
|
||||
|
||||
## 输出 debug 日志,出问题时方便排查
|
||||
yabai -m config debug_output on
|
||||
|
||||
# 窗口平铺
|
||||
yabai -m space --layout bsp
|
||||
# 默认拆分规则 first_child second_child
|
||||
yabai -m config window_placement second_child
|
||||
# 窗口间距设置
|
||||
yabai -m config top_padding 10
|
||||
yabai -m config bottom_padding 10
|
||||
yabai -m config left_padding 10
|
||||
yabai -m config right_padding 10
|
||||
yabai -m config window_gap 10
|
||||
# 自动平衡所有窗口始终占据相同的空间
|
||||
yabai -m config auto_balance off
|
||||
# 如果禁用自动平衡,此项属性定义的是新窗口占用的空间量。0.5意为旧窗口占用50%
|
||||
yabai -m config split_ratio 0.50
|
||||
# 鼠标修饰键 意思就是按着这个键就可以使用鼠标单独修改窗口大小了
|
||||
yabai -m config mouse_modifier ctrl
|
||||
# ctrl + 鼠标左键 移动窗口
|
||||
yabai -m config mouse_action1 move
|
||||
# ctrl + 鼠标右键 调整窗口大小
|
||||
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 0.98
|
||||
yabai -m config normal_window_opacity 0.9
|
||||
yabai -m config window_opacity_duration 0.0
|
||||
|
||||
|
||||
# 在所有显示器上的每个空间顶部添加 0 填充 底部添加 0 填充
|
||||
yabai -m config external_bar all:0:0
|
||||
|
||||
# ================================ 规则 ================================
|
||||
# 打开系统偏好设置,不使用平铺模式
|
||||
yabai -m rule --add app="^系统偏好设置$" manage=off
|
||||
yabai -m rule --add app="^提醒事项$" manage=off
|
||||
yabai -m rule --add app="^关于本机$" manage=off
|
||||
# float system preferences
|
||||
yabai -m rule --add app="^System Preferences$" manage=off
|
||||
# show digital colour meter topmost and on all spaces
|
||||
yabai -m rule --add app="^Digital Colou?r Meter$" sticky=on
|
||||
|
||||
echo "yabai configuration loaded.."
|
||||
Reference in New Issue
Block a user