[LyX/master] Add support for dedicated dark mode color in (Inset)Layout font and background color (#12462)

Juergen Spitzmueller <[email protected]> Mon, 25 May 2026 14:50:53 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit c962f7b8708fbb6ee7294b002cc4a780c07297e7
Author: Juergen Spitzmueller <[email protected]>
Date:   Mon May 25 16:50:37 2026 +0200

    Add support for dedicated dark mode color in (Inset)Layout font and background color (#12462)
---
 lib/doc/Customization.lyx    | 57 +++++++++++++++++++++++++++++++++++++++++---
 lib/doc/de/Customization.lyx | 35 ++++++++++++++++++++++++---
 src/FontInfo.cpp             | 36 +++++++++++++++++++++++-----
 src/FontInfo.h               |  3 ++-
 src/insets/InsetLayout.cpp   | 43 ++++++++++++++++++++++++++++++---
 5 files changed, 158 insertions(+), 16 deletions(-)

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index f3633c2d45..5d1144f1a2 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -20206,7 +20206,11 @@ BgColor
 
 \end_inset
 
- [
+ 
+\change_deleted -712698321 1779719873
+[
+\change_unchanged
+
 \begin_inset Flex Code
 status collapsed
 
@@ -20216,7 +20220,34 @@ status collapsed
 
 \end_inset
 
-] The color for the inset's background.
+
+\change_deleted -712698321 1779719875
+]
+\change_inserted -712698321 1779720029
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1779720029
+<dark color name>
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+]
+\change_unchanged
+ The color for the inset's background
+\change_inserted -712698321 1779719922
+.
+ If two colors are specified,
+ the first one is used for light mode,
+ the second for dark mode
+\change_unchanged
+.
  See 
 \begin_inset CommandInset ref
 LatexCommand ref
@@ -26829,7 +26860,27 @@ string
 
 \end_inset
 
-] See appendix
+]
+\change_inserted -712698321 1779719997
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1779719983
+string
+\end_layout
+
+\end_inset
+
+] The color of this font.
+ If two colors are specified,
+ the first one is used for light mode,
+ the second for dark mode.
+
+\change_unchanged
+ See appendix
 \begin_inset space ~
 \end_inset
 
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index cc62449007..d4ea2265ef 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -18912,7 +18912,7 @@ BgColor
 
 \end_inset
 
- [
+ 
 \begin_inset Flex Code
 status collapsed
 
@@ -18922,7 +18922,21 @@ status collapsed
 
 \end_inset
 
-] ist die Hintergrundfarbe der Einfügung.
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+<Name für dunklen Modus>
+\end_layout
+
+\end_inset
+
+]:
+ die Hintergrundfarbe(n) der Einfügung.
+ Falls zwei Farben angegeben werden,
+ wird die erste für hellen,
+ die zweite für dunklen Modus verwendet.
  Siehe 
 \begin_inset CommandInset ref
 LatexCommand ref
@@ -25376,7 +25390,22 @@ string
 
 \end_inset
 
-] Siehe Anhang
+] [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+string
+\end_layout
+
+\end_inset
+
+]:
+ die Farbe(n) des Textes.
+ Falls zwei Farben angegeben werden,
+ wird die erste für hellen,
+ die zweite für dunklen Modus verwendet.
+ Siehe Anhang
 \begin_inset space ~
 \end_inset
 
diff --git a/src/FontInfo.cpp b/src/FontInfo.cpp
index 7133836949..3dd396a516 100644
--- a/src/FontInfo.cpp
+++ b/src/FontInfo.cpp
@@ -716,16 +716,36 @@ FontState setLyXMisc(string const & siz)
 
 
 /// Sets color after LyX text format
-void setLyXColor(string const & col, FontInfo & f)
+void setLyXColor(string const & col, FontInfo & f, string const & dmcol)
 {
 	ColorCode cc = lcolor.getFromLyXName(col, false);
+	string lyxname = col;
+	string lchexname;
 	if (cc == Color_none && theLaTeXColors().isLaTeXColor(col)) {
 		LaTeXColor const lc = theLaTeXColors().getLaTeXColor(col);
-		string const lyxname = lc.name();
-		lcolor.setColor(lyxname, lc.hexname());
+		lyxname = lc.name();
+		lchexname = lc.hexname();
+		lcolor.setColor(lyxname, lchexname);
 		lcolor.setLaTeXName(lyxname, lc.latex());
 		lcolor.setGUIName(lyxname, to_ascii(lc.guiname()));
 		cc = lcolor.getFromLyXName(lyxname);
+	} else if (cc != Color_none)
+		lchexname = lcolor.getX11HexName(cc);
+	if (!dmcol.empty()) {
+		// generate a new name for this color
+		string nlyxname = lyxname;
+		int i = 0;
+		while (lcolor.isKnownLyXName(nlyxname)) {
+			++i;
+			nlyxname = lyxname + convert<string>(i);
+		}
+		ColorCode dcc = lcolor.getFromLyXName(dmcol, false);
+		if (dcc == Color_none && theLaTeXColors().isLaTeXColor(dmcol)) {
+			LaTeXColor const dlc = theLaTeXColors().getLaTeXColor(dmcol);
+			lcolor.setColor(nlyxname, lchexname, dlc.hexname());
+		} else if (dcc != Color_none)
+			lcolor.setColor(nlyxname, lchexname, lcolor.getX11HexName(dcc));
+		cc = lcolor.getFromLyXName(nlyxname);
 	}
 	f.setColor(cc);
 }
@@ -802,9 +822,13 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
 				lex.printError("Illegal misc type");
 			}
 		} else if (tok == "color") {
-			lex.next();
-			string const ttok = lex.getString();
-			setLyXColor(ttok, f);
+			lex.eatLine();
+			vector<string> const colors = getVectorFromString(lex.getString(), " ");
+			string const lmcolor = colors.front();
+			string dmcolor;
+			if (colors.size() > 1)
+				dmcolor = colors.back();
+			setLyXColor(lmcolor, f, dmcolor);
 		} else {
 			lex.printError("Unknown tag");
 			error = true;
diff --git a/src/FontInfo.h b/src/FontInfo.h
index bcbe596e98..eb69fd3386 100644
--- a/src/FontInfo.h
+++ b/src/FontInfo.h
@@ -251,7 +251,8 @@ void setLyXShape(std::string const &, FontInfo &);
 void setLyXSize(std::string const &, FontInfo &);
 
 /// Sets color after LyX text format
-void setLyXColor(std::string const &, FontInfo &);
+void setLyXColor(std::string const &, FontInfo &,
+		 std::string const & dmcol = std::string());
 
 /// Returns misc flag after LyX text format
 FontState setLyXMisc(std::string const &);
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 5c12f00bcc..7acaa3d3f8 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -17,6 +17,7 @@
 #include "ColorSet.h"
 #include "TextClass.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/Lexer.h"
 #include "support/lstrings.h"
@@ -531,10 +532,46 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
 		case IL_ARGUMENT:
 			readArgument(lex);
 			break;
-		case IL_BGCOLOR:
-			lex >> tmp;
-			bgcolor_ = lcolor.getFromLyXName(tmp);
+		case IL_BGCOLOR: {
+			lex.eatLine();
+			vector<string> const colors = getVectorFromString(lex.getString(), " ");
+			string const lmcolor = colors.front();
+			string dmcolor;
+			if (colors.size() > 1)
+				dmcolor = colors.back();
+			if (dmcolor.empty()) {
+				bgcolor_ = lcolor.getFromLyXName(lmcolor);
+				break;
+			}
+			// generate a new name for this color
+			string nlyxname = to_utf8(name_);
+			int i = 0;
+			while (lcolor.isKnownLyXName(nlyxname)) {
+				++i;
+				nlyxname = to_utf8(name_) + convert<string>(i);
+			}
+			ColorCode lcc = lcolor.getFromLyXName(lmcolor, false);
+			string lyxname = lmcolor;
+			string lchexname;
+			if (lcc == Color_none && theLaTeXColors().isLaTeXColor(lmcolor)) {
+				LaTeXColor const lc = theLaTeXColors().getLaTeXColor(lmcolor);
+				lyxname = lc.name();
+				lchexname = lc.hexname();
+				lcolor.setColor(lyxname, lchexname);
+				lcolor.setLaTeXName(lyxname, lc.latex());
+				lcolor.setGUIName(lyxname, to_ascii(lc.guiname()));
+				lcc = lcolor.getFromLyXName(lyxname);
+			} else if (lcc != Color_none)
+				lchexname = lcolor.getX11HexName(lcc);
+			ColorCode dcc = lcolor.getFromLyXName(dmcolor, false);
+			if (dcc == Color_none && theLaTeXColors().isLaTeXColor(dmcolor)) {
+				LaTeXColor const dlc = theLaTeXColors().getLaTeXColor(dmcolor);
+				lcolor.setColor(nlyxname, lchexname, dlc.hexname());
+			} else if (dcc != Color_none)
+				lcolor.setColor(nlyxname, lchexname, lcolor.getX11HexName(dcc));
+			bgcolor_ = lcolor.getFromLyXName(nlyxname);
 			break;
+		}
 		case IL_PREAMBLE:
 			preamble_ = lex.getLongString(from_ascii("EndPreamble"));
 			break;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs