Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
50 changes: 50 additions & 0 deletions bin/omarchy-theme-set-templates
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,41 @@ hex_to_rgb() {
printf "%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 background="$1"

awk -v background="$background" '
function hex_value(char) {
return index("0123456789abcdef", tolower(char)) - 1
}

function hex_pair_to_int(hex, idx) {
return hex_value(substr(hex, idx, 1)) * 16 + hex_value(substr(hex, idx + 1, 1))
}

BEGIN {
r = hex_pair_to_int(background, 2)
g = hex_pair_to_int(background, 4)
b = hex_pair_to_int(background, 6)
max = r; if (g > max) max = g; if (b > max) max = b
min = r; if (g < min) min = g; if (b < min) min = b
chroma = max - min
if (((max == 255) || (max + min <= 16)) && (chroma <= 32)) {
r = g = b = int((r + g + b) / 3 + 0.5)
}
printf "%02x%02x%02x", r, g, b
}
'
}

# Mix two hex colors. Amount may be a fraction (0.30) or percentage (30%).
mix_color() {
local start="${1#\#}"
Expand Down Expand Up @@ -380,6 +415,21 @@ 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
THEME_COLORS[chrome_seed]="#$(chrome_seed_from_background "${THEME_COLORS[background]}")"
else
THEME_COLORS[chrome_seed]="${THEME_COLORS[background]}"
printf 's|{{ chrome_seed_rgb }}|%s|g\n' "${THEME_COLORS[background]}" >>"$sed_script"
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 @@ -143,6 +143,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
5 changes: 4 additions & 1 deletion install/helpers/browser-policy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ BROWSER_POLICY_FIREFOX_DIRS=(
/opt/zen-browser/distribution
)

BROWSER_POLICY_DEFAULT_COLOR="#1c2027"
# The default must be neutral: Chromium renders the seed's hue at full
# saturation at the lightness extremes, so a tinted fallback like the old
# blue-grey #1c2027 rendered as loud blue chrome.
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 @@ -174,11 +174,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