Repository navigation
Clamp degenerate-saturation chrome seeds for Chromium #10697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from all commits
e6f2c37
a0e913a
350a61e
1caa829
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| (( r = g = b = (2 * (r + g + b) + 3) / 6 )) | ||
| fi | ||
|
|
||
| printf -v REPLY "#%02x%02x%02x" "$r" "$g" "$b" | ||
| } | ||
|
|
||
| trim() { | ||
| local value="$1" | ||
|
|
||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {{ background_rgb }} | ||
| {{ chrome_seed_rgb }} |
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Knowledge Base Used: Theme catalog and assets |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#000011misses 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#fefdf0also miss themax == 255check.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!