Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions bin/omarchy-theme-set-templates
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ hex_to_rgb() {
printf -v REPLY "%d,%d,%d" "0x${hex:0:2}" "0x${hex:2:2}" "0x${hex:4:2}"
}

# Chromium derives the browser chrome color from the seed by adjusting
# lightness while preserving HSL saturation. At the luminance extremes HSL
# saturation is degenerate — a near-black's max+min is tiny and a near-white's
# max channel is 255 — so a small hue tint yields full saturation and renders
# as a loud, saturated tone of that hue: near-black blue-tinted backgrounds
# render bright blue chrome, near-white warm ones bright yellow. Neutralize
# degenerate seeds so near-black and near-white backgrounds keep
# near-neutral chrome.
chrome_seed_from_background() {
local hex="${1#\#}"
local r=$((16#${hex:0:2})) g=$((16#${hex:2:2})) b=$((16#${hex:4:2}))
local max=$r min=$r

(( g > max )) && max=$g
(( b > max )) && max=$b
(( g < min )) && min=$g
(( b < min )) && min=$b

if (( (max == 255 || max + min <= 16) && max - min <= 32 )); then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Saturated seeds escape the clamp A near-black background such as #000011 misses the cutoff because its maximum and minimum channels sum to 17. It remains fully saturated as a Chromium seed, so the browser can still show the conspicuous blue chrome this change aims to prevent. Near-white colors such as #fefdf0 also miss the max == 255 check.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

(( r = g = b = (2 * (r + g + b) + 3) / 6 ))
fi

printf -v REPLY "#%02x%02x%02x" "$r" "$g" "$b"
}

trim() {
local value="$1"

Expand Down Expand Up @@ -440,6 +465,22 @@ if [[ -f $COLORS_FILE ]]; then
THEME_COLORS[$key]="$value"
done < <(omarchy-theme-color --file "$COLORS_FILE" --all)

# BrowserThemeColor is a seed, not a paint color (see
# chrome_seed_from_background). Derive a clamped chrome seed from the
# background so generated chromium.theme files survive Chromium's seed
# derivation. A theme that defines its own chrome_seed keeps it; a
# background that is not plain hex passes through untouched so
# {{ chrome_seed_rgb }} still resolves instead of leaking a placeholder.
if [[ -z ${THEME_COLORS[chrome_seed]+_} && -n ${THEME_COLORS[background]+_} ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Explicit RGB seeds become placeholders If a theme sets chrome_seed = "18,52,86", the palette parser accepts it and browser policy could use it as an RGB triple. But an explicit seed skips this branch, and the template renderer creates chrome_seed_rgb only from six-digit hex values. The generated chromium.theme therefore contains the literal {{ chrome_seed_rgb }} placeholder, causing browser sync to use the fallback color instead of the requested seed.

Knowledge Base Used: Theme switching and application sync

if [[ ${THEME_COLORS[background]} =~ ^#[0-9a-fA-F]{6}$ ]]; then
chrome_seed_from_background "${THEME_COLORS[background]}"
THEME_COLORS[chrome_seed]="$REPLY"
else
THEME_COLORS[chrome_seed]="${THEME_COLORS[background]}"
printf '{{ chrome_seed_rgb }}\037%s\n' "${THEME_COLORS[background]}" >>"$value_table"
fi
fi

for key in "${!THEME_COLORS[@]}"; do
add_template_value "$key" "${THEME_COLORS[$key]}"
done
Expand Down
2 changes: 1 addition & 1 deletion default/themed/chromium.theme.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ background_rgb }}
{{ chrome_seed_rgb }}
2 changes: 2 additions & 0 deletions docs/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ For a color key such as `accent = "#7aa2f7"`:
| `{{ accent_strip }}` | `7aa2f7` |
| `{{ accent_rgb }}` | `122,162,247` |

`chromium.theme` is generated from the background as a clamped chrome seed rather than the raw color: Chromium derives the browser chrome color from that seed by adjusting lightness, and near-black and near-white degenerate seeds are neutralized so a tinted background keeps near-neutral chrome.

### Color mixing

`mix`, `mix_strip`, and `mix_rgb` blend two hex colors by a fraction or
Expand Down
4 changes: 3 additions & 1 deletion install/helpers/browser-policy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ BROWSER_POLICY_FIREFOX_DIRS=(
/opt/zen-browser/distribution
)

BROWSER_POLICY_DEFAULT_COLOR="#1c2027"
# Neutral, so the fallback chrome carries no tint of its own: Chromium draws
# the old #1c2027 seed's toolbar as blue-grey #39424f.
BROWSER_POLICY_DEFAULT_COLOR="#1f1f1f"

browser_policy_purge_dir() {
local dir=$1
Expand Down
2 changes: 1 addition & 1 deletion manual/43-making-your-own-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

You can add your own themes to `~/.config/omarchy/themes`. Just copy one of the existing ones as a base (look in `/usr/share/omarchy/themes`), then tweak to your delight. As long as your theme is inside that folder, it'll be included in the theme selection menu.

The main file you have to tweak is `colors.toml`. That defines the color set that's then used to generate configurations for the terminal (Foot/Alacritty/Ghostty/Kitty), btop, Chromium, Hyprland, Neovim, Helix, VSCode, Obsidian, and the entire Omarchy shell (top bar, menu, notifications, OSD, and lock screen).
The main file you have to tweak is `colors.toml`. That defines the color set that's then used to generate configurations for the terminal (Foot/Alacritty/Ghostty/Kitty), btop, Chromium, Hyprland, Neovim, Helix, VSCode, Obsidian, and the entire Omarchy shell (top bar, menu, notifications, OSD, and lock screen). Chromium's chrome color is generated from the background as a clamped chrome seed — Chromium derives the chrome color from that seed, and degenerate near-black or near-white seeds are neutralized so a tinted background doesn't render as loud, saturated chrome.

You can also use the included Aether application to create a new theme using a lovely GUI interface to play with colors and search for backgrounds. Just start it via the apps menu on `Super + Alt + Space`.

Expand Down
4 changes: 2 additions & 2 deletions test/shell.d/browser-policy-dir-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pass "Firefox setup does not follow a planted distribution symlink"
fail "theme colour treats leading zeros as decimal"
for malformed in "" "not,a,color" "1,2" "1,2,3,4" "256,0,0" "999,999,999" "-1,0,0" \
"1,2,3;id" '1,2,$(id)' "0x10,0,0" "1,2,3 4,5,6"; do
[[ $(browser_policy_theme_hex "$malformed") == "#1c2027" ]] ||
[[ $(browser_policy_theme_hex "$malformed") == "#1f1f1f" ]] ||
fail "theme colour falls back to the stock grey for '$malformed'"
done
pass "theme colour is six hex digits or the stock grey"
Expand All @@ -225,7 +225,7 @@ for theme in "$ROOT"/themes/*/chromium.theme; do
hex=$(browser_policy_theme_hex "$rgb")
[[ $hex =~ ^#[0-9a-f]{6}$ ]] ||
fail "shipped $(basename "$(dirname "$theme")") chromium.theme parses as hex" "got: $hex from $(printf %q "$rgb")"
if [[ $hex == "#1c2027" && ! $rgb =~ ^[[:space:]]*28[[:space:]]*,[[:space:]]*32[[:space:]]*,[[:space:]]*39[[:space:]]*$ ]]; then
if [[ $hex == "#1f1f1f" && ! $rgb =~ ^[[:space:]]*31[[:space:]]*,[[:space:]]*31[[:space:]]*,[[:space:]]*31[[:space:]]*$ ]]; then
fail "shipped $(basename "$(dirname "$theme")") chromium.theme is a valid RGB triple" "got: $(printf %q "$rgb")"
fi
done
Expand Down
4 changes: 2 additions & 2 deletions test/shell.d/browser-policy-sudoers-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ color_for_theme() {
for malformed in "" "not,a,color" "1,2" "1,2,3,4" "256,0,0" "999,999,999" "-1,0,0" \
"1,2,3;id" '1,2,$(id)' "0x10,0,0" "1,2,3 4,5,6"; do
color=$(color_for_theme "$malformed")
[[ $color == "1c2027" ]] ||
[[ $color == "1f1f1f" ]] ||
fail "omarchy-theme-set-browser falls back to the stock colour for '$malformed'" "got: $color"
done

[[ $(color_for_theme) == "1c2027" ]] ||
[[ $(color_for_theme) == "1f1f1f" ]] ||
fail "omarchy-theme-set-browser falls back to the stock colour with no theme file"

pass "browser theme color is derived as six hex digits or falls back to the stock grey"
93 changes: 93 additions & 0 deletions test/shell.d/chrome-seed-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

set -euo pipefail

# Chromium's BrowserThemeColor policy is a seed, not a paint color: Chromium
# derives the chrome color from it by adjusting lightness while preserving HSL
# saturation. Near-black and near-white seeds are degenerate there, so a tinted
# background would render as loud, saturated chrome of its hue. The generated
# chromium.theme must be the clamped seed, not the raw background — unless the
# theme defines its own chrome_seed, or the background is not plain hex at all.

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

home="$test_tmp/home"
next_theme="$home/.local/state/omarchy/current/next-theme"
mkdir -p "$next_theme"

generated_chromium_theme() {
local background="$1"
local chrome_seed="${2:-}"

# Templates never overwrite an output that already exists, so each case
# starts from a clean staging directory.
rm -rf "$next_theme"
mkdir -p "$next_theme"

cat >"$next_theme/colors.toml" <<TOML
mode = "dark"

accent = "#7aa2f7"
selection = "#292e42"
muted = "#414868"

background = "$background"
foreground = "#a9b1d6"

color0 = "#1a1b26"
color1 = "#f7768e"
color2 = "#9ece6a"
color3 = "#e0af68"
color4 = "#7aa2f7"
color5 = "#bb9af7"
color6 = "#7dcfff"
color7 = "#a9b1d6"
TOML

if [[ -n $chrome_seed ]]; then
printf '\nchrome_seed = "%s"\n' "$chrome_seed" >>"$next_theme/colors.toml"
fi

HOME="$home" OMARCHY_PATH="$ROOT" PATH="$ROOT/bin:$PATH" \
bash "$ROOT/bin/omarchy-theme-set-templates"

cat "$next_theme/chromium.theme"
}

assert_chromium_theme() {
local description="$1"
local expected="$2"
local actual

actual=$(generated_chromium_theme "$3" "$4")
[[ $actual == "$expected" ]] ||
fail "$description" "background $3 chrome_seed ${4:-<none>}: expected $expected, got $actual"
pass "$description"
}

assert_chromium_theme \
"a near-black blue-tinted background generates a neutral chrome seed" \
"3,3,3" "#000107" ""

assert_chromium_theme \
"a near-white warm background generates a neutral chrome seed" \
"249,249,249" "#fffcf0" ""

assert_chromium_theme \
"a dark tinted background above the degenerate range keeps its seed" \
"26,27,38" "#1a1b26" ""

assert_chromium_theme \
"a saturated background keeps its seed" \
"255,0,0" "#ff0000" ""

assert_chromium_theme \
"a theme-defined chrome_seed wins over the derived one" \
"18,52,86" "#000107" "#123456"

assert_chromium_theme \
"a non-hex background passes through as the chrome seed" \
"rgba(010203ee) rgba(040506ee) 45deg" "rgba(010203ee) rgba(040506ee) 45deg" ""
Comment on lines +91 to +93

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test accepts unusable browser color This test expects a gradient string in chromium.theme, but browser sync accepts only an RGB triple and falls back for that output. The test therefore passes even though the generated file cannot supply the browser color, leaving this handoff untested.

Knowledge Base Used: Theme catalog and assets

4 changes: 2 additions & 2 deletions test/shell.d/theme-set-browser-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ chmod +x "$TMP_BIN/omarchy-theme-set-browser-policy"
# skip everything.
policy_tmp="$TMPDIR/policies"
mkdir -p "$policy_tmp"
printf '{"BrowserThemeColor": "#1c2027", "BrowserColorScheme": "device"}\n' > "$policy_tmp/color.json"
printf '{"BrowserThemeColor": "#1f1f1f", "BrowserColorScheme": "device"}\n' > "$policy_tmp/color.json"

# A test cannot make a root-owned file, so stat reports the owner the writer
# leaves behind, or a user-owned one.
Expand All @@ -43,7 +43,7 @@ printf '%s\n' "${STAT_OWNER:?}"
FAKE
chmod +x "$stat_bin/stat"

# No theme file -> fallback color #1c2027, which matches the fixture.
# No theme file -> fallback color #1f1f1f, which matches the fixture.
HOME="$TMPDIR" PATH="$stat_bin:$TMP_BIN:$ROOT/bin:$PATH" OMARCHY_PATH="$ROOT" STAT_OWNER="root:root 644" \
OMARCHY_BROWSER_POLICY_DIRS="$policy_tmp" CALL_LOG="$CALL_LOG" \
bash "$ROOT/bin/omarchy-theme-set-browser" >/dev/null
Expand Down