[LyX/master] Improve readability of dark text colors in dark mode (#13218)

Juergen Spitzmueller <[email protected]> Sat, 16 May 2026 07:16:24 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 67a87d81f4d58f33306a25532010cecb05d22270
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat May 16 09:15:43 2026 +0200

    Improve readability of dark text colors in dark mode (#13218)
---
 src/RowPainter.cpp              | 12 +++++++++---
 src/frontends/qt/GuiPainter.cpp |  8 +++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index fd45245ea7..c8f5b8b3bf 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -257,9 +257,15 @@ void RowPainter::paintStringAndSel(Row::Element const & e) const
 		|| pi_.selected;
 
 	bool invert = false;
-	if (theApp() && theApp()->isInDarkMode()
-	    && theApp()->isLightColor(rgbFromHexName(lcolor.getX11HexName(pi_.background_color, true))))
-		invert = true;
+	if (theApp() && theApp()->isInDarkMode()) {
+		if (e.font.fontInfo().color() == Color_none
+		    && theApp()->isLightColor(rgbFromHexName(lcolor.getX11HexName(pi_.background_color, true))))
+			invert = true;
+		else if (pi_.background_color == Color_background
+			 && e.font.fontInfo().color() != Color_none
+			 && !theApp()->isLightColor(rgbFromHexName(lcolor.getX11HexName(e.font.fontInfo().color()))))
+			invert = true;
+	}
 
 	if (e.type == Row::PREEDIT) {
 		// the case of the preedit element
diff --git a/src/frontends/qt/GuiPainter.cpp b/src/frontends/qt/GuiPainter.cpp
index 0383cf5b45..04e9fb9c9e 100644
--- a/src/frontends/qt/GuiPainter.cpp
+++ b/src/frontends/qt/GuiPainter.cpp
@@ -330,7 +330,13 @@ void GuiPainter::text(int x, int y, docstring const & s,
 
 	textDecoration(f, x, y, textwidth);
 
-	setQPainterPen(computeColor(f.realColor(invert)));
+	Color const rc = f.realColor(invert);
+	QColor penColor = computeColor(rc);
+	if (invert && rc == f.color())
+		// We are in dark mode and have a dark text color.
+		// Brighten that for workarea display (#13218)
+		penColor = penColor.lighter(170);
+	setQPainterPen(penColor);
 	if (dir != Auto) {
 		auto ptl = fm.getTextLayout(s, dir == RtL, wordspacing);
 		QTextLine const & tline = ptl->lineForTextPosition(0);
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs