Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bin/omarchy-theme-color
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ parse_colors_file() {
return 0
}

resolve_terminal_opacity() {
local declared="${THEME_COLORS[terminal_opacity]+set}"
local opacity="${THEME_COLORS[terminal_opacity]-1.0}" terminal

# This setting is scalar; an unquoted value can carry a TOML comment.
opacity="${opacity%%#*}"
opacity="${opacity%% *}"
if [[ ! $opacity =~ ^(0([.][0-9]+)?|1([.]0+)?)$ ]]; then
Comment thread
OldJobobo marked this conversation as resolved.
Resolved
printf 'omarchy-theme-color: invalid terminal_opacity %q; ignoring override\n' "$opacity" >&2
opacity="1.0"
declared=""
fi
THEME_COLORS[terminal_opacity]="$opacity"

# Keep the scalar fallback for custom templates, but never make a stock
# template look explicitly opaque when the theme declared no valid setting.
# Recompute every helper so palette data cannot supply a config directive.
for terminal in alacritty foot ghostty kitty; do
THEME_COLORS[terminal_opacity_$terminal]="# opacity is not set by this theme"
done
if [[ $declared ]]; then
THEME_COLORS[terminal_opacity_alacritty]="opacity = $opacity"
THEME_COLORS[terminal_opacity_foot]="alpha=$opacity"
THEME_COLORS[terminal_opacity_ghostty]="background-opacity = $opacity"
THEME_COLORS[terminal_opacity_kitty]="background_opacity $opacity"
fi
}

resolve_theme_colors() {
local key

Expand Down Expand Up @@ -277,6 +305,7 @@ resolve_theme_colors() {
done

resolve_theme_mode
resolve_terminal_opacity
THEME_COLORS[theme_type]="${THEME_COLORS[mode]}"
}

Expand Down
3 changes: 3 additions & 0 deletions default/themed/alacritty.toml.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[window]
{{ terminal_opacity_alacritty }}

[colors.primary]
background = "{{ background }}"
foreground = "{{ foreground }}"
Expand Down
1 change: 1 addition & 0 deletions default/themed/foot.ini.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[colors-dark]
{{ terminal_opacity_foot }}
foreground={{ foreground_strip }}
background={{ background_strip }}
# Blur only applies while the background is see-through, as with Glassy windows,
Expand Down
1 change: 1 addition & 0 deletions default/themed/ghostty.conf.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
background = {{ background }}
{{ terminal_opacity_ghostty }}
foreground = {{ foreground }}
cursor-color = {{ bright_foreground }}
selection-background = {{ selection_background }}
Expand Down
1 change: 1 addition & 0 deletions default/themed/kitty.conf.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
foreground {{ foreground }}
background {{ background }}
{{ terminal_opacity_kitty }}
selection_foreground {{ selection_foreground }}
selection_background {{ selection_background }}

Expand Down
11 changes: 7 additions & 4 deletions docs/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ What this does not cover: a theme distributed as an archive rather than a git re

## `colors.toml`

`colors.toml` provides the palette keys used by templates. Keys are grouped
semantic-first: accent/selection/muted, then the backgrounds, then the
foregrounds, then the named colors:
`colors.toml` provides the palette and visual settings used by templates. Color keys are grouped semantic-first: accent/selection/muted, then the backgrounds, then the foregrounds, then the named colors:

```toml
mode = "dark"
terminal_opacity = "0.95"

accent = "#7aa2f7"
selection = "#292e42"
Expand All @@ -89,6 +88,10 @@ red = "#f7768e"
blue = "#7aa2f7"
```

`terminal_opacity` optionally sets the terminal emulator's background translucency, from `0.0` (transparent) through `1.0` (opaque). Stock templates emit an opacity setting only for a valid explicit declaration; an omitted or invalid value leaves the terminal's own settings and the selected window mode intact. Glassy windows can therefore apply their usual `0.65` background opacity when the theme says nothing. A valid theme declaration, including an explicit `1.0`, takes precedence over Glassy's fallback, just as an authored terminal config does. This is separate from Hyprland window opacity, which affects the whole window including its text. Custom templates can still use the scalar `{{ terminal_opacity }}`, whose fallback is `1.0`.

Running Foot windows receive the last `alpha` in the generated theme's `foot.ini` over OSC when the theme or window-opacity choice changes; reopening them is not required. Other terminals follow their normal configuration-reload behavior.

Any key can be referenced from a template with `{{ key }}`. The foundational
shell palette is loaded from:

Expand Down Expand Up @@ -376,7 +379,7 @@ The input method's candidate window is drawn by Fcitx's classicui, from `default
## Adding or overriding theme files

- Add palette values to `themes/<name>/colors.toml`.
- Hand-written overrides work everywhere except a `.lua`, a terminal config or a `vscode.json` in a theme cloned from a git repo; see [What an installed theme may not ship](#what-an-installed-theme-may-not-ship).
- Hand-written overrides work everywhere except a `.lua`, a terminal config or a `vscode.json` in a theme cloned from a git repo; see [What an installed theme may not ship](#what-an-installed-theme-may-not-ship). A hand-written terminal config takes precedence over the generated `terminal_opacity` setting.
- Prefer generated files when the theme can be expressed with templates.
- Add a hand-written file in `themes/<name>/` only when that theme needs to
override the generated output entirely.
Expand Down
33 changes: 33 additions & 0 deletions test/cli
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ mkdir -p "$NEXT_THEME" "$CURRENT_THEME" "$USER_THEMED"

cat >"$NEXT_THEME/colors.toml" <<'EOF'
mode = "light"
terminal_opacity = "0.78"
accent = "#336699"
hyprland_active_border = "rgba(010203ee) rgba(040506ee) 45deg"
background = "#000000"
Expand Down Expand Up @@ -346,6 +347,12 @@ border = "#ffffff"
EOF

OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-templates"
grep -qx 'opacity = 0.78' "$NEXT_THEME/alacritty.toml" || fail "Alacritty template uses terminal opacity"
grep -qx 'alpha=0.78' "$NEXT_THEME/foot.ini" || fail "Foot template uses terminal opacity"
grep -qx 'background-opacity = 0.78' "$NEXT_THEME/ghostty.conf" || fail "Ghostty template uses terminal opacity"
grep -qx 'background_opacity 0.78' "$NEXT_THEME/kitty.conf" || fail "Kitty template uses terminal opacity"
pass "terminal templates use the shared opacity token"

grep -qx 'mix=#808080' "$NEXT_THEME/mix-test.txt" || fail "theme template mix helper works"
grep -qx 'strip=808080' "$NEXT_THEME/mix-test.txt" || fail "theme template mix_strip helper works"
grep -qx 'rgb=128,128,128' "$NEXT_THEME/mix-test.txt" || fail "theme template mix_rgb helper works"
Expand Down Expand Up @@ -374,6 +381,28 @@ grep -qx 'selection-foreground=#eeeeee' "$NEXT_THEME/alias-test.txt" || fail "th
grep -qx 'cursor-alias=#eeeeee' "$NEXT_THEME/alias-test.txt" || fail "theme template derives cursor alias from bright_foreground"
pass "theme template semantic aliases expose legacy palette helpers"

while read -r opacity expected; do
opacity_file="$PI_TMPDIR/opacity-$opacity.toml"
printf 'terminal_opacity = "%s"\n' "$opacity" >"$opacity_file"
actual=$("$ROOT/bin/omarchy-theme-color" --file "$opacity_file" terminal_opacity)
[[ $actual == "$expected" ]] || fail "terminal opacity resolves $opacity"
done <<'EOF'
0 0
0.78 0.78
1 1
1.0 1.0
EOF
pass "terminal opacity accepts values from zero through one"

for opacity in -0.1 1.1 transparent; do
opacity_file="$PI_TMPDIR/invalid-opacity-${opacity//[^a-zA-Z0-9]/-}.toml"
printf 'terminal_opacity = "%s"\n' "$opacity" >"$opacity_file"
actual=$("$ROOT/bin/omarchy-theme-color" --file "$opacity_file" terminal_opacity 2>"$PI_TMPDIR/opacity-stderr")
[[ $actual == "1.0" ]] || fail "invalid terminal opacity falls back to opaque"
grep -q 'invalid terminal_opacity' "$PI_TMPDIR/opacity-stderr" || fail "invalid terminal opacity reports its fallback"
done
pass "invalid terminal opacity warns and falls back to opaque"

LEGACY_COLORS_FILE="$PI_TMPDIR/legacy-colors.toml"
cat >"$LEGACY_COLORS_FILE" <<'EOF'
mode = "dark"
Expand Down Expand Up @@ -424,6 +453,10 @@ cp "$LEGACY_COLORS_FILE" "$LEGACY_NEXT_THEME/colors.toml"
OMARCHY_PATH="$ROOT" HOME="$LEGACY_THEME_HOME" "$ROOT/bin/omarchy-theme-set-templates"
grep -qx 'background = #101010' "$LEGACY_NEXT_THEME/ghostty.conf" || fail "legacy theme generates terminal background"
grep -qx 'foreground = #f0f0f0' "$LEGACY_NEXT_THEME/ghostty.conf" || fail "legacy theme generates terminal foreground"
! grep -q '^opacity =' "$LEGACY_NEXT_THEME/alacritty.toml" || fail "legacy Alacritty theme leaves opacity unset"
! grep -q '^alpha=' "$LEGACY_NEXT_THEME/foot.ini" || fail "legacy Foot theme leaves opacity unset"
! grep -q '^background-opacity =' "$LEGACY_NEXT_THEME/ghostty.conf" || fail "legacy Ghostty theme leaves opacity unset"
! grep -q '^background_opacity ' "$LEGACY_NEXT_THEME/kitty.conf" || fail "legacy Kitty theme leaves opacity unset"
grep -Fq 'dark_bg = "#111111"' "$LEGACY_NEXT_THEME/neovim.lua" || fail "legacy theme preserves dark_bg in generated editor theme"
grep -Fq 'lighter_bg = "#131313"' "$LEGACY_NEXT_THEME/neovim.lua" || fail "legacy theme preserves lighter_bg in generated editor theme"
grep -Fq 'dark_fg = "#d0d0d0"' "$LEGACY_NEXT_THEME/neovim.lua" || fail "legacy theme preserves dark_fg in generated editor theme"
Expand Down
8 changes: 8 additions & 0 deletions test/shell.d/theme-staging-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ assert_no_marker() {
write_colors() {
cat >"$1" <<TOML
mode = "light"
terminal_opacity = "0.78"

accent = "#7aa2f7"
selection = "#292e42"
Expand Down Expand Up @@ -109,6 +110,10 @@ for generated in hyprland.lua neovim.lua gum_env.lua kitty.conf alacritty.toml f
assert_staged "$generated" "$generated is generated from Omarchy's template"
assert_no_marker "$generated" "an installed theme cannot supply $generated"
done
grep -qx 'opacity = 0.78' "$(staged alacritty.toml)" || fail "installed theme opacity reaches Alacritty's generated config"
grep -qx 'alpha=0.78' "$(staged foot.ini)" || fail "installed theme opacity reaches Foot's generated config"
grep -qx 'background-opacity = 0.78' "$(staged ghostty.conf)" || fail "installed theme opacity reaches Ghostty's generated config"
grep -qx 'background_opacity 0.78' "$(staged kitty.conf)" || fail "installed theme opacity reaches Kitty's generated config"

# Colour is kept, including a file Omarchy would otherwise have generated.
assert_staged shell.toml "shell.toml is staged"
Expand Down Expand Up @@ -158,6 +163,7 @@ set_theme legacy || fail "omarchy-theme-set applies a theme that only ships alac
assert_staged colors.toml "a legacy theme's palette is recovered from its alacritty.toml"
grep -q '#102030' "$(staged colors.toml)" || fail "the recovered palette is the theme's"
assert_no_marker alacritty.toml "a legacy theme's alacritty.toml is not staged"
! grep -q '^opacity =' "$(staged alacritty.toml)" || fail "a legacy installed theme leaves opacity unset"

pass "a theme older than colors.toml keeps its palette and loses its terminal config"

Expand All @@ -179,10 +185,12 @@ mkdir -p "$mine"
write_colors "$mine/colors.toml"
printf 'os.execute("%s")\n' "$marker" >"$mine/hyprland.lua"
printf '{"name":"Mine","extension":"pub.ext"}\n' >"$mine/vscode.json"
printf '[colors-dark]\nalpha=0.42\n' >"$mine/foot.ini"

set_theme mine || fail "omarchy-theme-set applies a theme the user wrote"
grep -q "$marker" "$(staged hyprland.lua)" || fail "a theme the user wrote keeps its own hyprland.lua"
assert_staged vscode.json "a theme the user wrote keeps every file it ships"
grep -qx 'alpha=0.42' "$(staged foot.ini)" || fail "a theme the user wrote keeps its terminal config"
[[ ! -s $test_tmp/stderr ]] || fail "a theme the user wrote reports nothing ignored" "$(cat "$test_tmp/stderr")"

pass "a theme the user wrote is not held to the installed-theme list"
Expand Down
26 changes: 26 additions & 0 deletions test/shell.d/theme-templates-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,29 @@ for tpl in "$ROOT"/default/themed/*.tpl; do
[[ -f $next/$name ]] || fail "every built-in template renders ($name)"
done
pass "theme templates render every built-in template"

# Render the real stock templates with Glassy selected, rather than hand-writing
# terminal configs: an implicit opacity line would suppress Glassy's defaults.
while IFS='|' read -r name declaration expected; do
opacity_home="$test_tmp/opacity-$name"
opacity_next="$opacity_home/.local/state/omarchy/current/next-theme"
mkdir -p "$opacity_next" "$opacity_home/.local/state/omarchy/toggles/hypr"
cp "$next/colors.toml" "$opacity_next/colors.toml"
if [[ -n $declaration ]]; then
printf 'terminal_opacity = %s\n' "$declaration" >>"$opacity_next/colors.toml"
fi
touch "$opacity_home/.local/state/omarchy/toggles/hypr/window-glassy.lua"
HOME="$opacity_home" XDG_CONFIG_HOME="$opacity_home/.config" XDG_STATE_HOME="$opacity_home/.local/state" \
OMARCHY_PATH="$ROOT" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-theme-set-templates" 2>"$test_tmp/opacity-$name.log"
grep -qx "opacity = $expected" "$opacity_next/alacritty.toml" || fail "Glassy Alacritty opacity for $name"
grep -qx "alpha=$expected" "$opacity_next/foot.ini" || fail "Glassy Foot opacity for $name"
grep -qx "background-opacity = $expected" "$opacity_next/ghostty.conf" || fail "Glassy Ghostty opacity for $name"
grep -qx "background_opacity $expected" "$opacity_next/kitty.conf" || fail "Glassy Kitty opacity for $name"
pass "Glassy stock templates respect $name opacity"
done <<'CASES'
missing||0.65
invalid|"invalid"|0.65
declared|0.8|0.8
opaque|1.0|1.0
commented|0.8 # translucent|0.8
CASES
Loading