Skip to content

Commit

Permalink
Darwin: more window management
Browse files Browse the repository at this point in the history
  • Loading branch information
shajra committed Jan 18, 2024
1 parent c9238c3 commit 6c3b1a1
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 176 deletions.
48 changes: 48 additions & 0 deletions build/nixpkgs/packages/sketchybar-window-focus/default.nix
Original file line number Diff line number Diff line change
@@ -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"
}
''
5 changes: 4 additions & 1 deletion home/modules/base/gui/darwin/xdg/configFile/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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@")
Expand Down
14 changes: 10 additions & 4 deletions home/modules/base/gui/darwin/xdg/configFile/sketchybar/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ return {
loading = "􀖇",
apple = "􀣺",
preferences = "􀺽",

volume = {
_100 = "􀊩",
_66 = "􀊧",
_33 = "􀊥",
_10 = "􀊡",
_0 = "􀊣"
_0 = "􀊣",
},
wifi = {connected = "􀙇", disconnected = "􀙈"},
battery = {
Expand All @@ -17,6 +16,13 @@ return {
_50 = "􀺶",
_25 = "􀛩",
_0 = "􀛪",
charging = "􀢋"
}
charging = "􀢋",
},
yabai = {
stack = "􀏭",
fullscreen_zoom = "􀏜",
parent_zoom = "􀥃",
float = "􀢌",
grid = "􀧍",
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require("items.apple")
require("items.spaces")
require("items.yabai")
require("items.front_app")

require("items.media")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 6c3b1a1

Please sign in to comment.