From beaf8a57542d27394394e0af582108351c4b91b6 Mon Sep 17 00:00:00 2001 From: Nico Date: Sun, 19 Oct 2025 21:01:31 +1100 Subject: [PATCH] yabai: init --- flake.nix | 2 +- modules/desktop/de/yabai.nix | 20 ++++++++ stow/.config/sketchybar/plugins/space.sh | 14 +----- stow/.config/sketchybar/sketchybarrc | 26 ++++++++++ stow/.config/skhd/skhdrc | 54 +++++++++++++++++++- stow/.config/yabai/yabairc | 64 ++++++++++++++++++++++++ 6 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 modules/desktop/de/yabai.nix mode change 100755 => 120000 stow/.config/sketchybar/plugins/space.sh create mode 100644 stow/.config/yabai/yabairc diff --git a/flake.nix b/flake.nix index c2ac45a..9f726e4 100644 --- a/flake.nix +++ b/flake.nix @@ -92,7 +92,7 @@ ./modules/games/darwin.nix ./modules/applications/darwin.nix ./modules/desktop/de/darwin.nix - ./modules/desktop/de/aerospace.nix + ./modules/desktop/de/yabai.nix ./modules/desktop/programs/sketchybar.nix ./modules/hardware/darwin.nix ./modules/nix/darwin.nix diff --git a/modules/desktop/de/yabai.nix b/modules/desktop/de/yabai.nix new file mode 100644 index 0000000..fea6961 --- /dev/null +++ b/modules/desktop/de/yabai.nix @@ -0,0 +1,20 @@ +{ config, pkgs, lib, ... }: + +{ + services.yabai = { + enable = true; + enableScriptingAddition = true; + extraConfig = builtins.readFile ../../../stow/.config/yabai/yabairc; + }; + + system.defaults.spaces.spans-displays = lib.mkForce false; + + environment.systemPackages = with pkgs; [ + skhd + matugen + ]; + + homebrew.brews = [ + "FelixKratz/formulae/borders" + ]; +} diff --git a/stow/.config/sketchybar/plugins/space.sh b/stow/.config/sketchybar/plugins/space.sh deleted file mode 100755 index b9bf8f6..0000000 --- a/stow/.config/sketchybar/plugins/space.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/local/bin/bash - -# The $SELECTED variable is available for space components and indicates if -# the space invoking this script (with name: $NAME) is currently selected: -# https://felixkratz.github.io/SketchyBar/config/components#space----associate-mission-control-spaces-with-an-item - -#sketchybar --set "$NAME" background.drawing="$SELECTED" - -if [ $SELECTED = 'true' ]; then - sketchybar --set "$NAME" background.color=0xfff48fb1 -else - sketchybar --set "$NAME" background.color=0xffffffff -fi diff --git a/stow/.config/sketchybar/plugins/space.sh b/stow/.config/sketchybar/plugins/space.sh new file mode 120000 index 0000000..9836491 --- /dev/null +++ b/stow/.config/sketchybar/plugins/space.sh @@ -0,0 +1 @@ +aerospace.sh \ No newline at end of file diff --git a/stow/.config/sketchybar/sketchybarrc b/stow/.config/sketchybar/sketchybarrc index 60e45a2..3f89abf 100755 --- a/stow/.config/sketchybar/sketchybarrc +++ b/stow/.config/sketchybar/sketchybarrc @@ -66,6 +66,32 @@ for sid in $(aerospace list-workspaces --all); do done # background.corner_radius=0 \ + + +# Yabai Workspace Indictators +# +SPACE_ICONS=("1" "2" "3" "4" "5" "6" "7" "8" "9") +for i in "${!SPACE_ICONS[@]}" +do + sid="$(($i+1))" + space=( + space="$sid" + icon="${SPACE_ICONS[i]}" + background.drawing=true \ + icon.drawing=false \ + background.height=28 \ + background.border_width=0 \ + background.padding_right=0 \ + background.padding_left=0 \ + label.color=$PRIMARY_COLOUR \ + label="$sid" \ + script="$PLUGIN_DIR/space.sh" + click_script="yabai -m space --focus $sid" + ) + sketchybar --add space space."$sid" left --set space."$sid" "${space[@]}" +done + + # Focused window title sketchybar --add item front_app left \ --set front_app icon="󱂬 " \ diff --git a/stow/.config/skhd/skhdrc b/stow/.config/skhd/skhdrc index 7a22dd5..efd256d 100644 --- a/stow/.config/skhd/skhdrc +++ b/stow/.config/skhd/skhdrc @@ -1,2 +1,52 @@ -alt + shift - b : /opt/homebrew/bin/firefox --new-window -alt + shift - f : open ~ +# +# Applications +# + +alt + shift - b : /Applications/Zen.app/Contents/MacOS/zen --new-window # new browser window +alt - s : screencapture -i -c # screenshot +alt + shift - f : open ~ # new finder window + +# +# Yabai +# + +# Workspaces +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 + shift - 1 : yabai -m window --space 1 --focus +alt + shift - 2 : yabai -m window --space 2 --focus +alt + shift - 3 : yabai -m window --space 3 --focus +alt + shift - 4 : yabai -m window --space 4 --focus +alt + shift - 5 : yabai -m window --space 5 --focus +alt + shift - 6 : yabai -m window --space 6 --focus +alt + shift - 7 : yabai -m window --space 7 --focus +alt + shift - 8 : yabai -m window --space 8 --focus +alt + shift - 9 : yabai -m window --space 9 --focus + +# Focus next space by mission-control index if one exists, otherwise focus the first space +alt - home : yabai -m space --focus next || yabai -m space --focus first +# Focus previous space by mission-control index if one exists, otherwise focus the last space +alt - end : yabai -m space --focus prev || yabai -m space --focus last + +# Layout/Focus +alt - c : yabai -m space --rotate 90 +alt - f : yabai -m window --toggle zoom-fullscreen +alt - space : yabai -m window --toggle float + +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 + +alt + shift - h : yabai -m window --swap west +alt + shift - j : yabai -m window --swap south +alt + shift - k : yabai -m window --swap north +alt + shift - l : yabai -m window --swap east diff --git a/stow/.config/yabai/yabairc b/stow/.config/yabai/yabairc new file mode 100644 index 0000000..371c12f --- /dev/null +++ b/stow/.config/yabai/yabairc @@ -0,0 +1,64 @@ +# Scripting Addon +# https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release)#configure-scripting-addition + +yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa" +sudo yabai --load-sa + + +# Remove existing signals (in case of restart) +yabai -m signal --remove "sketchybar_space_change" 2>/dev/null +yabai -m signal --remove "sketchybar_front_app" 2>/dev/null + +# Sketchybar Intergration +yabai -m signal --add event=space_changed action="sketchybar --trigger space_change" label="sketchybar_space_change" +yabai -m signal --add event=window_focused action="sketchybar --trigger front_app_switched" label="sketchybar_front_app" + +# autostart +sketchybar & disown +borders & disown +sh ~/.cache/matugen-jankyborders.sh & disown +skhd & disown + +# space labels +yabai -m space 1 --label browser +yabai -m space 2 --label terminal +yabai -m space 3 --label spare +yabai -m space 4 --label gaming +yabai -m space 5 --label social +yabai -m space 6 --label music + +# layout +yabai -m config layout bsp +yabai -m config split_ratio 0.5 + +# padding +yabai -m config top_padding 6 +yabai -m config bottom_padding 12 +yabai -m config left_padding 12 +yabai -m config right_padding 12 +yabai -m config window_gap 12 + +# mouse support +yabai -m config mouse_modifier alt # set mouse interaction modifier key +yabai -m config mouse_action1 move # set modifier + left-click drag to move window +yabai -m config mouse_action2 resize # set modifier + right-click drag to resize window +yabai -m config focus_follows_mouse autofocus # disabled while holding mouse modifier (eg. for menubar) +yabai -m config mouse_follows_focus on + +# appearance +yabai -m config window_shadow float # window shadow only on floating windows + +yabai -m config window_opacity on +yabai -m config active_window_opacity 1.0 +yabai -m config normal_window_opacity 0.95 + +# window rules +yabai -m rule --add app="^(Calculator|System Preferences|System Settings|Archive Utility)$" manage=off +yabai -m rule --add title="^Preferences" manage=off +yabai -m rule --add title="^Settings" manage=off +yabai -m rule --add app="^Steam$" manage=off +yabai -m rule --add app="^Weather$" manage=off +# Anki card preview & Anki browser +yabai -m rule --add title="^Preview" manage=off +yabai -m rule --add title="^Anki" manage=off +yabai -m rule --add title="^Browse" manage=off