Am Freitag, dem 26.12.2025 um 14:34 +0100 schrieb Jürgen Spitzmüller:
> > Note: The difference between 2.5.0 RC2 and 2.4.4 is that the on
> > 2.5.0
> > RC2, the leak stops after some time (10-20 secs) after dumping
> > around
> > 1GB memory. In 2.4.4, however, memory dump never stops. I had to
> > kill
> > the process as the memory dump went upto 6GB in the tests...
> 
> There have been many changed to dark/light mode handling for 2.5, nut
> I
> don't see now which could cause that difference.
> 
> refillToolbars() was not changed.

However, refillToolbars() can be expensive as well. And if I understand
correctly that the theme change here does not (necessarily) involve a
change from dark to light, we could also use the attached patch to
refill toolbars only if the latter happened.

-- 
Jürgen
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index f64c368a59..afae7c6a50 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -1781,6 +1781,15 @@ bool GuiView::statsEnabled() const
 }
 
 
+bool GuiView::isPaletteDark(QPalette const & pal)
+{
+	QColor text_color = pal.color(QPalette::Active, QPalette::WindowText);
+	QColor bg_color = pal.color(QPalette::Active, QPalette::Window);
+
+	return (text_color.black() < bg_color.black());
+}
+
+
 bool GuiView::event(QEvent * e)
 {
 	switch (e->type())
@@ -1906,10 +1915,15 @@ bool GuiView::event(QEvent * e)
 #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
 	case QEvent::ThemeChange: {
 		if (lyxrc.color_scheme != "dark" && lyxrc.color_scheme != "light") {
-			guiApp->setPalette(guiApp->style()->standardPalette());
+			QPalette currentPalette = guiApp->palette();
+			QPalette newPalette = guiApp->style()->standardPalette();
+			guiApp->setPalette(newPalette);
 			// We need to update metrics here to avoid a crash (#12786)
 			theBufferList().changed(true);
-			refillToolbars();
+			if (isPaletteDark(currentPalette) != isPaletteDark(newPalette))
+				// we need to refill the toolbar only if we really
+				// switched from dark to light or vice versa
+				refillToolbars();
 			return QMainWindow::event(e);
 		}
 		return true;
diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h
index 73a6f46c68..bea80c8cf7 100644
--- a/src/frontends/qt/GuiView.h
+++ b/src/frontends/qt/GuiView.h
@@ -432,6 +432,8 @@ private:
 	void initToolbar(std::string const & name);
 	/// Update lock (all) toolbars position
 	void updateLockToolbars();
+	///
+	bool isPaletteDark(QPalette const & pal);
 	/// refill the toolbars (dark/light mode switch)
 	void refillToolbars();
 	///
-- 
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to