Skip to content

Choose black or white text on accents by WCAG contrast - #16

Open
piotrkowski wants to merge 1 commit into
ianswope:masterfrom
piotrkowski:fix/on-color-contrast
Open

piotrkowski wants to merge 1 commit into
ianswope:masterfrom
piotrkowski:fix/on-color-contrast

Conversation

@piotrkowski

@piotrkowski piotrkowski commented Oct 11, 2026 •

Copy link
Copy Markdown

on_color picks black or white with luminance(c) > 0.6, on gamma-encoded sRGB values (weighted, but not linearized). For mid tones that often picks the worse ink. #8f8f8f, for example, gets white at 3.2:1 instead of black at 6.5:1. The red from the Everforest test palette (#e67e80) gets white at 2.7:1, which is what destructive buttons use.

This picks whichever of black or white has the higher WCAG contrast ratio, using linearized relative luminance. luminance itself is unchanged, since mode detection still uses it.

fill before after
#8f8f8f white 3.2:1 black 6.5:1
#e67e80 (Everforest red) white 2.7:1 black 7.7:1
#e06c75 (One Dark red) white 3.2:1 black 6.6:1
#3584e4 (GNOME blue) white 3.8:1 black 5.6:1

Light accents like Everforest, Catppuccin, Tokyo Night and Nord are unaffected; they were already black. Note that GNOME blue flips to black too, because white falls short of 4.5:1 there. This only affects Omarchy palettes; without one, libadwaita's own colors are untouched.

Before / after with a #8f8f8f accent (checked toggle, today badge):

before / after

Best landed after #14: with more reds getting black ink, destructive buttons need their fill back. The two merge cleanly in either order.

Test first (on_color_picks_the_ink_with_more_contrast_on_a_mid_tone), then the four CI gates.

@piotrkowski piotrkowski changed the title Pick the accent ink by WCAG contrast instead of a luminance cutoff Choose black or white text on accents by WCAG contrast Oct 11, 2026
`on_color` chose black or white ink with a cutoff on `luminance`, which
weights the channels but leaves them gamma-encoded. That reads mid tones as
darker than they are, so they got white where black has twice the contrast:
2.7:1 against 7.7:1 on Everforest's red, which fills the destructive
buttons, and 3.2:1 against 6.5:1 on a plain #8f8f8f.

It now takes the WCAG relative luminance, with the channels linearised, and
picks whichever ink has the higher contrast ratio. `luminance` stays as it
is for telling a light palette from a dark one, the only other thing it
does.

Light accents such as Everforest's, Catppuccin's, Tokyo Night's and Nord's
already got black and are unchanged. A saturated mid blue like GNOME's
#3584e4 flips to black as well, 5.6:1 against 3.8:1. None of this touches a
desktop without an Omarchy palette, where libadwaita's own colours stand.
@piotrkowski
piotrkowski force-pushed the fix/on-color-contrast branch from 6417a95 to 13126d6 Compare October 11, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant