diff --git a/README.md b/README.md index d55dfb98..de641b7e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Running the switch builds: - Nix user packages (ripgrep, fd, fzf, jq, lazygit, Neovim, Hack Nerd Font) - Shell (zsh, aliases, starship prompt) - Editor (Neovim config with the rose-pine moon theme) -- Terminal (WezTerm config with the rose-pine moon theme) +- Terminal (WezTerm config with the rose-pine moon theme and dimmed unfocused windows) - Agent configs (Claude, Codex, opencode all share one AGENTS.md) ## Prerequisites diff --git a/home/.config/wezterm/wezterm.lua b/home/.config/wezterm/wezterm.lua index 8bb9ce80..24041e72 100644 --- a/home/.config/wezterm/wezterm.lua +++ b/home/.config/wezterm/wezterm.lua @@ -10,4 +10,38 @@ config.macos_window_background_blur = 50 config.hide_tab_bar_if_only_one_tab = true config.window_decorations = "RESIZE" +-- Dim unfocused windows so the focused one is obvious at a glance. +local UNFOCUSED_FOREGROUND_TEXT_HSB = { hue = 1.0, saturation = 0.25, brightness = 0.45 } +local UNFOCUSED_WINDOW_BACKGROUND_OPACITY = 0.62 + +-- get_config_overrides() hands back a copy, so the current value is never the +-- same table we last stored; compare the fields instead of the identity. +local function same_text_hsb(actual, expected) + if actual == nil or expected == nil then + return actual == expected + end + return actual.hue == expected.hue + and actual.saturation == expected.saturation + and actual.brightness == expected.brightness +end + +wezterm.on("window-focus-changed", function(window) + local overrides = window:get_config_overrides() or {} + local text_hsb, opacity + if not window:is_focused() then + text_hsb = UNFOCUSED_FOREGROUND_TEXT_HSB + opacity = UNFOCUSED_WINDOW_BACKGROUND_OPACITY + end + + -- Only write when one of the two values we own actually changes; a redundant + -- set_config_overrides() call would trigger another config reload. + if same_text_hsb(overrides.foreground_text_hsb, text_hsb) and overrides.window_background_opacity == opacity then + return + end + + overrides.foreground_text_hsb = text_hsb + overrides.window_background_opacity = opacity + window:set_config_overrides(overrides) +end) + return config