diff --git a/build/nixpkgs/packages/sketchybar-window-focus/default.nix b/build/nixpkgs/packages/sketchybar-window-focus/default.nix new file mode 100644 index 00000000..fc236004 --- /dev/null +++ b/build/nixpkgs/packages/sketchybar-window-focus/default.nix @@ -0,0 +1,48 @@ +{ coreutils +, jq +, nix-project-lib +}: + +let + progName = "sketchybar-window-focus"; + meta.description = "Signal SketchyBar for latest window state"; +in + +nix-project-lib.writeShellCheckedExe progName +{ + inherit meta; + path = [ + coreutils + jq + ]; +} +'' +set -eu +set -o pipefail + +export PATH="/opt/homebrew/bin:$PATH" # For yabai + +yabai -m query --windows --window \ +| jq -r ' + if .["is-floating"] then "float" + elif .["has-fullscreen-zoom"] then "fullscreen_zoom" + elif .["has-parent-zoom"] then "parent_zoom" + elif .["stack-index"] > 0 then "stack" + else "default" + end + , .["stack-index"]' \ +| { + read -r STATE + read -r STACK_INDEX + STACK_LAST=0 + if [ "$STACK_INDEX" -gt 0 ] + then STACK_LAST="$( + yabai -m query --windows --window stack.last \ + | jq '.["stack-index"]')" + fi + sketchybar --trigger window_focus \ + STATE="$STATE" \ + STACK_INDEX="$STACK_INDEX" \ + STACK_LAST="$STACK_LAST" +} +'' diff --git a/home/modules/base/gui/darwin/xdg/configFile/default.nix b/home/modules/base/gui/darwin/xdg/configFile/default.nix index 80bcb4f8..930115a1 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/default.nix +++ b/home/modules/base/gui/darwin/xdg/configFile/default.nix @@ -17,6 +17,9 @@ in { --replace @SKETCHYBAR_LUA_SO@ "${pkgs.sketchybar-lua}" substituteInPlace "$out/colors.lua" \ --replace @COLORS_UNIFYING@ "${colors.semantic.unifying}" \ + --replace @COLORS_INFO@ "${colors.semantic.info}" \ + --replace @COLORS_WARNING@ "${colors.semantic.warning}" \ + --replace @COLORS_URGENT@ "${colors.semantic.urgent}" \ --replace @COLORS_PRIMARY_BG@ "${colors.semantic.background}" \ --replace @COLORS_PRIMARY_FG@ "${colors.semantic.foreground}" \ --replace @COLORS_SECONDARY_BG@ "${colors.semantic.background_highlighted}" \ @@ -40,7 +43,7 @@ in { chmod +x "$out/sketchybarrc" ''; "skhd/skhdrc".text = import skhd/skhdrc.nix config pkgs colors; - "yabai/yabairc".text = import yabai/yabairc.nix colors; + "yabai/yabairc".text = import yabai/yabairc.nix pkgs colors; "yabai/yabairc".executable = true; "borders/bordersrc".text = import borders/bordersrc.nix colors; "borders/bordersrc".executable = true; diff --git a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/colors.lua b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/colors.lua index e5d385ec..9dca5c2f 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/colors.lua +++ b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/colors.lua @@ -1,5 +1,8 @@ return { unifying = tonumber("@COLORS_UNIFYING@"), + info = tonumber("@COLORS_INFO@"), + warning = tonumber("@COLORS_WARNING@"), + urgent = tonumber("@COLORS_URGENT@"), primary = { background = tonumber("@COLORS_PRIMARY_BG@"), foreground = tonumber("@COLORS_PRIMARY_FG@") diff --git a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/icons.lua b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/icons.lua index 4d34536d..6152b897 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/icons.lua +++ b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/icons.lua @@ -2,13 +2,12 @@ return { loading = "􀖇", apple = "􀣺", preferences = "􀺽", - volume = { _100 = "􀊩", _66 = "􀊧", _33 = "􀊥", _10 = "􀊡", - _0 = "􀊣" + _0 = "􀊣", }, wifi = {connected = "􀙇", disconnected = "􀙈"}, battery = { @@ -17,6 +16,13 @@ return { _50 = "􀺶", _25 = "􀛩", _0 = "􀛪", - charging = "􀢋" - } + charging = "􀢋", + }, + yabai = { + stack = "􀏭", + fullscreen_zoom = "􀏜", + parent_zoom = "􀥃", + float = "􀢌", + grid = "􀧍", + }, } diff --git a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/front_app.lua b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/front_app.lua index 1428b96e..2f1a636b 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/front_app.lua +++ b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/front_app.lua @@ -7,11 +7,4 @@ local front_app = sbar.add("item", { front_app:subscribe("front_app_switched", function(env) front_app:set({label = {string = env.INFO}}) - - -- Or equivalently: - -- sbar.set(env.NAME, { - -- label = { - -- string = env.INFO - -- } - -- }) end) diff --git a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/init.lua b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/init.lua index 7ec4492b..736c07a9 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/init.lua +++ b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/init.lua @@ -1,5 +1,6 @@ require("items.apple") require("items.spaces") +require("items.yabai") require("items.front_app") require("items.media") diff --git a/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/yabai.lua b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/yabai.lua new file mode 100644 index 00000000..2fc380ce --- /dev/null +++ b/home/modules/base/gui/darwin/xdg/configFile/sketchybar/items/yabai.lua @@ -0,0 +1,31 @@ +local icons = require("icons") +local colors = require("colors") + +local yabai = sbar.add("item", { + icon = { + color = colors.info, + font = {style = "Bold"}, + width = 0, + }, + label = { + color = colors.info, + width = 0, + }, +}) + +yabai:subscribe("window_focus", function(env) + local icon = icons.yabai[env.STATE] or "" + local label = "" + if env.STATE == "stack" then + label = "[" .. env.STACK_INDEX .. "/" .. env.STACK_LAST .. "]" + end + local icon_width, label_width = 0, 0 + if icon ~= "" then icon_width = 30 end + if label ~= "" then label_width = 40 end + sbar.animate("sin", 10, function() + yabai:set({ + icon = { string = icon, width = icon_width }, + label = { string = label, width = label_width }, + }) + end) +end) diff --git a/home/modules/base/gui/darwin/xdg/configFile/skhd/skhdrc.nix b/home/modules/base/gui/darwin/xdg/configFile/skhd/skhdrc.nix index fc94cd80..a3ac220f 100644 --- a/home/modules/base/gui/darwin/xdg/configFile/skhd/skhdrc.nix +++ b/home/modules/base/gui/darwin/xdg/configFile/skhd/skhdrc.nix @@ -44,6 +44,8 @@ let ''; space-create = "${space-create-script}/bin/space-create"; + window-focus = "${pkgs.sketchybar-window-focus}/bin/sketchybar-window-focus"; + in '' # Strategy for keybindings: # @@ -90,14 +92,36 @@ passthru < lalt - escape ; default lalt - return : "${kitty}" --single-instance --wait-for-single-instance-window-close --directory ~ # focus window -lalt - h : yabai -m window --focus west \ - || yabai -m display --focus west -lalt - j : yabai -m window --focus south \ - || yabai -m display --focus south -lalt - k : yabai -m window --focus north \ - || yabai -m display --focus north -lalt - l : yabai -m window --focus east \ - || yabai -m display --focus east +lalt - h : yabai -m window --focus west || yabai -m display --focus west +lalt - j : yabai -m window --focus south || yabai -m display --focus south +lalt - k : yabai -m window --focus north || yabai -m display --focus north +lalt - l : yabai -m window --focus east || yabai -m display --focus east + +# swap window, or move if floating +lalt + shift - h : yabai -m window --swap west || yabai -m window --move rel:-20:0 +lalt + shift - j : yabai -m window --swap south || yabai -m window --move rel:0:20 +lalt + shift - k : yabai -m window --swap north || yabai -m window --move rel:0:-20 +lalt + shift - l : yabai -m window --swap east || yabai -m window --move rel:20:0 + +# warp window or fit to grid if floating +lalt + shift + cmd - h : yabai -m window --warp west || yabai -m window --grid 1:2:0:0:1:1 ; "${window-focus}" +lalt + shift + cmd - j : yabai -m window --warp south ; "${window-focus}" +lalt + shift + cmd - k : yabai -m window --warp north || yabai -m window --grid 1:1:0:0:1:1 ; "${window-focus}" +lalt + shift + cmd - l : yabai -m window --warp east || yabai -m window --grid 1:2:1:0:1:1 ; "${window-focus}" + +# stack window +lalt + shift + ctrl - h : yabai -m window west --stack $(yabai -m query --windows --window | jq -r '.id') ; "${window-focus}" +lalt + shift + ctrl - j : yabai -m window south --stack $(yabai -m query --windows --window | jq -r '.id') ; "${window-focus}" +lalt + shift + ctrl - k : yabai -m window north --stack $(yabai -m query --windows --window | jq -r '.id') ; "${window-focus}" +lalt + shift + ctrl - l : yabai -m window east --stack $(yabai -m query --windows --window | jq -r '.id') ; "${window-focus}" + +# set insertion point in focused container +lalt + cmd - i : yabai -m window --insert cancel +lalt + cmd - h : yabai -m window --insert west +lalt + cmd - j : yabai -m window --insert south +lalt + cmd - k : yabai -m window --insert north +lalt + cmd - l : yabai -m window --insert east +lalt + cmd - s : yabai -m window --insert stack # increase window size size < lalt - h : yabai -m window --resize left:-20:0 @@ -111,148 +135,66 @@ size < lalt + shift - j : yabai -m window --resize bottom:0:-20 size < lalt + shift - k : yabai -m window --resize top:0:20 size < lalt + shift - l : yabai -m window --resize right:-20:0 -# set insertion point in focused container -lalt + cmd - i : yabai -m window --insert cancel -lalt + cmd - h : yabai -m window --insert west -lalt + cmd - j : yabai -m window --insert south -lalt + cmd - k : yabai -m window --insert north -lalt + cmd - l : yabai -m window --insert east - -# swap or move window -lalt + shift - h : yabai -m window --swap west \ - || yabai -m window --move rel:-20:0 -lalt + shift - j : yabai -m window --swap south \ - || yabai -m window --move rel:0:20 -lalt + shift - k : yabai -m window --swap north \ - || yabai -m window --move rel:0:-20 -lalt + shift - l : yabai -m window --swap east \ - || yabai -m window --move rel:20:0 - -# warp window -lcmd + shift - h [ - "google chrome beta" ~ - * : yabai -m window --warp west -] -lcmd + shift - j [ - "google chrome beta" ~ - * : yabai -m window --warp south -] -lcmd + shift - k [ - "google chrome beta" ~ - * : yabai -m window --warp north -] -lcmd + shift - l [ - "google chrome beta" ~ - * : yabai -m window --warp east -] - -# make floating window fill left-half of screen -lalt + cmd + shift - h : yabai -m window --grid 1:2:0:0:1:1 -# make floating window fill screen -lalt + cmd + shift - k : yabai -m window --grid 1:1:0:0:1:1 -# make floating window fill right-half of screen -lalt + cmd + shift - l : yabai -m window --grid 1:2:1:0:1:1 - -# balance size of windows -lalt - 0 : yabai -m space --balance -size < lalt - 0 : yabai -m space --balance - -# fast focus space -lalt - 0x2C : yabai -m space --focus last -lalt - 0x2B : yabai -m space --focus prev -lalt - 0x2F : yabai -m space --focus next -lalt - 1 : yabai -m space --focus 1 -lalt - 2 : yabai -m space --focus 2 -lalt - 3 : yabai -m space --focus 3 -lalt - 4 : yabai -m space --focus 4 -lalt - 5 : yabai -m space --focus 5 -lalt - 6 : yabai -m space --focus 6 -lalt - 7 : yabai -m space --focus 7 -lalt - 8 : yabai -m space --focus 8 -lalt - 9 : yabai -m space --focus 9 +# focus space +lalt - 0x2C : yabai -m space --focus last ; "${window-focus}" +lalt - 0x2B : yabai -m space --focus prev ; "${window-focus}" +lalt - 0x2F : yabai -m space --focus next ; "${window-focus}" +lalt - 1 : yabai -m space --focus 1 ; "${window-focus}" +lalt - 2 : yabai -m space --focus 2 ; "${window-focus}" +lalt - 3 : yabai -m space --focus 3 ; "${window-focus}" +lalt - 4 : yabai -m space --focus 4 ; "${window-focus}" +lalt - 5 : yabai -m space --focus 5 ; "${window-focus}" +lalt - 6 : yabai -m space --focus 6 ; "${window-focus}" +lalt - 7 : yabai -m space --focus 7 ; "${window-focus}" +lalt - 8 : yabai -m space --focus 8 ; "${window-focus}" +lalt - 9 : yabai -m space --focus 9 ; "${window-focus}" # move window to space lalt + shift - 0x2C : yabai -m window --space last lalt + shift - 0x2B : yabai -m window --space prev lalt + shift - 0x2F : yabai -m window --space next -lalt + shift - 1 : yabai -m window --space 1 -lalt + shift - 2 : yabai -m window --space 2 -lalt + shift - 3 : yabai -m window --space 3 -lalt + shift - 4 : yabai -m window --space 4 -lalt + shift - 5 : yabai -m window --space 5 -lalt + shift - 6 : yabai -m window --space 6 -lalt + shift - 7 : yabai -m window --space 7 -lalt + shift - 8 : yabai -m window --space 8 -lalt + shift - 9 : yabai -m window --space 9 +lalt + shift - 1 : yabai -m window --space 1 +lalt + shift - 2 : yabai -m window --space 2 +lalt + shift - 3 : yabai -m window --space 3 +lalt + shift - 4 : yabai -m window --space 4 +lalt + shift - 5 : yabai -m window --space 5 +lalt + shift - 6 : yabai -m window --space 6 +lalt + shift - 7 : yabai -m window --space 7 +lalt + shift - 8 : yabai -m window --space 8 +lalt + shift - 9 : yabai -m window --space 9 # move space -lcmd + shift - 0x2C [ - "google chrome beta" ~ - * : "${space-move}" last -] -lcmd + shift - 0x2B [ - "google chrome beta" ~ - * : "${space-move}" prev -] -lcmd + shift - 0x2F [ - "google chrome beta" ~ - * : "${space-move}" next -] -lcmd + shift - 1 [ - "google chrome beta" ~ - * : "${space-move}" 1 -] -lcmd + shift - 2 [ - "google chrome beta" ~ - * : "${space-move}" 2 -] -lcmd + shift - 3 [ - "google chrome beta" ~ - * : "${space-move}" 3 -] -lcmd + shift - 4 [ - "google chrome beta" ~ - * : "${space-move}" 4 -] -lcmd + shift - 5 [ - "google chrome beta" ~ - * : "${space-move}" 5 -] -lcmd + shift - 6 [ - "google chrome beta" ~ - * : "${space-move}" 6 -] -lcmd + shift - 7 [ - "google chrome beta" ~ - * : "${space-move}" 7 -] -lcmd + shift - 8 [ - "google chrome beta" ~ - * : "${space-move}" 8 -] -lcmd + shift - 9 [ - "google chrome beta" ~ - * : "${space-move}" 9 -] +lalt + shift + cmd - 0x2C : "${space-move}" last +lalt + shift + cmd - 0x2B : "${space-move}" prev +lalt + shift + cmd - 0x2F : "${space-move}" next +lalt + shift + cmd - 1 : "${space-move}" 1 +lalt + shift + cmd - 2 : "${space-move}" 2 +lalt + shift + cmd - 3 : "${space-move}" 3 +lalt + shift + cmd - 4 : "${space-move}" 4 +lalt + shift + cmd - 5 : "${space-move}" 5 +lalt + shift + cmd - 6 : "${space-move}" 6 +lalt + shift + cmd - 7 : "${space-move}" 7 +lalt + shift + cmd - 8 : "${space-move}" 8 +lalt + shift + cmd - 9 : "${space-move}" 9 + +# focus window within stack +lalt + ctrl - 0x2B : yabai -m window --focus stack.prev +lalt + ctrl - 0x2F : yabai -m window --focus stack.next # create spaces lalt + cmd - 0x2C : "${space-create}" last lalt + cmd - 0x2B : "${space-create}" prev lalt + cmd - 0x2F : "${space-create}" next -# send window to space and follow focus -lalt + cmd + shift - 0x2C : yabai -m window --space last && yabai -m space --focus last -lalt + cmd + shift - 0x2B : yabai -m window --space prev && yabai -m space --focus prev -lalt + cmd + shift - 0x2F : yabai -m window --space next && yabai -m space --focus next -lalt + cmd + shift - 1 : yabai -m window --space 1 && yabai -m space --focus 1 -lalt + cmd + shift - 2 : yabai -m window --space 2 && yabai -m space --focus 2 -lalt + cmd + shift - 3 : yabai -m window --space 3 && yabai -m space --focus 3 -lalt + cmd + shift - 4 : yabai -m window --space 4 && yabai -m space --focus 4 -lalt + cmd + shift - 5 : yabai -m window --space 5 && yabai -m space --focus 5 -lalt + cmd + shift - 6 : yabai -m window --space 6 && yabai -m space --focus 6 -lalt + cmd + shift - 7 : yabai -m window --space 7 && yabai -m space --focus 7 -lalt + cmd + shift - 8 : yabai -m window --space 8 && yabai -m space --focus 8 -lalt + cmd + shift - 9 : yabai -m window --space 9 && yabai -m space --focus 9 +# close window +lalt - q : yabai -m window --close + +# destroy space +lalt + cmd - q : yabai -m space --destroy + +# balance size of windows +lalt - 0 : yabai -m space --balance +size < lalt - 0 : yabai -m space --balance # rotate tree lalt - r : yabai -m space --rotate 90 @@ -263,36 +205,23 @@ lalt - y : yabai -m space --mirror y-axis # mirror tree x-axis lalt - x : yabai -m space --mirror x-axis -# toggle gap offset -lalt - o : yabai -m space --toggle padding && yabai -m space --toggle gap - -# close window -lalt - q : yabai -m window --close - -# destroy space -lalt + cmd - q : yabai -m space --destroy +# transpose split type +lalt - t : yabai -m window --toggle split # toggle window parent zoom -lalt - m : yabai -m window --toggle zoom-parent; \ - sketchybar --trigger window_focus +lalt - m : yabai -m window --toggle zoom-parent; "${window-focus}" # toggle window fullscreen zoom -lalt - f : yabai -m window --toggle zoom-fullscreen; \ - sketchybar --trigger window_focus +lalt - f : yabai -m window --toggle zoom-fullscreen; "${window-focus}" # toggle window native fullscreen -lalt + shift - f : \ - yabai -m window --toggle native-fullscreen; \ - sketchybar --trigger window_focus - -# toggle window split type -lalt - e : yabai -m window --toggle split +lalt + shift - f : yabai -m window --toggle native-fullscreen; "${window-focus}" # float / unfloat window and center on screen lalt + shift - space : \ yabai -m window --toggle float && \ yabai -m window --grid 4:4:1:1:2:2; \ - sketchybar --trigger window_focus + "${window-focus}" # toggle sticky lalt + shift - s : yabai -m window --toggle sticky @@ -304,11 +233,6 @@ lalt - p : yabai -m window --toggle sticky && \ # toggle mission control (application-level) lalt - a : yabai -m window --toggle expose -# DESIGN: not sure this is a good idea -# layout -#lalt + shift - f : yabai -m space --layout float -#lcmd + shift - f : yabai -m space --layout bsp - .blacklist [ "VMware Fusion" ] diff --git a/home/modules/base/gui/darwin/xdg/configFile/yabai/yabairc.nix b/home/modules/base/gui/darwin/xdg/configFile/yabai/yabairc.nix index a83b77fa..b8603666 100755 --- a/home/modules/base/gui/darwin/xdg/configFile/yabai/yabairc.nix +++ b/home/modules/base/gui/darwin/xdg/configFile/yabai/yabairc.nix @@ -1,4 +1,4 @@ -colors: +pkgs: colors: '' #!/usr/bin/env sh @@ -7,13 +7,13 @@ colors: # DESIGN: 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" -yabai -m signal --add event=window_focused action="sketchybar --trigger window_focus" +yabai -m signal --add event=window_focused action="${pkgs.sketchybar-window-focus}/bin/sketchybar-window-focus" # global settings (in order from 'man yabai') yabai -m config external_bar all:35:0 yabai -m config mouse_follows_focus off -yabai -m config focus_follows_mouse on +yabai -m config focus_follows_mouse off yabai -m config window_origin_display default yabai -m config window_placement second_child yabai -m config window_zoom_persist on