From 06dd22254d5c1c5539443b69dbe0773b78033be0 Mon Sep 17 00:00:00 2001 From: lkn Date: Thu, 25 Jun 2026 07:52:58 +0200 Subject: [PATCH] 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. --- src/backend/wayland/wl_window.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/wayland/wl_window.c b/src/backend/wayland/wl_window.c index cf2b353..69bf25e 100644 --- a/src/backend/wayland/wl_window.c +++ b/src/backend/wayland/wl_window.c @@ -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;