wayland: auto-contrast menu text color for dark themes
When MenuTextColor is not explicitly set (defaults to black), dark widget themes render invisible black-on-dark menu text. Compute luminance contrast between text color and background; if insufficient (< 64 difference), substitute white text on dark backgrounds or black text on light backgrounds.
This commit is contained in:
parent
72d6e31f24
commit
06dd22254d
|
|
@ -468,6 +468,20 @@ void wl_menu_paint_entry(WMenu *menu, int index, int selected)
|
|||
/* Draw text using WINGs font backend (renders via PangoFT2 → pixman) */
|
||||
WMColor *color = selected ? scr->select_text_color :
|
||||
(entry->flags.enabled ? scr->mtext_color : scr->dtext_color);
|
||||
/* Ensure text is readable against background: if text color is too
|
||||
* close to bg (dark theme with black text), use white instead. */
|
||||
if (color && !selected) {
|
||||
unsigned tr = WMRedComponentOfColor(color) >> 8;
|
||||
unsigned tg = WMGreenComponentOfColor(color) >> 8;
|
||||
unsigned tb = WMBlueComponentOfColor(color) >> 8;
|
||||
unsigned br = (bg >> 16) & 0xFF;
|
||||
unsigned bg_ = (bg >> 8) & 0xFF;
|
||||
unsigned bb = bg & 0xFF;
|
||||
int text_lum = (int)(tr * 299 + tg * 587 + tb * 114) / 1000;
|
||||
int bg_lum = (int)(br * 299 + bg_ * 587 + bb * 114) / 1000;
|
||||
if (abs(text_lum - bg_lum) < 64)
|
||||
color = (bg_lum < 128) ? scr->white : scr->black;
|
||||
}
|
||||
WMFont *font = scr->menu_entry_font;
|
||||
WMDrawable d = (WMDrawable)(uintptr_t)fb->image;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue