Skip to content

Commit

Permalink
WindowsQPA: Respect ENV and cmdline darkmode overrides
Browse files Browse the repository at this point in the history
Currently the commandline and environment parameters (windows:darkmode)
for setting the darkmode handling are ignored when the application
starts. This patch adds a condition to
QWindowsTheme::effectiveColorScheme that checks whether darkmode
handling was explicitly overridden and initializes in the constructor
the m_colorScheme with the result of passing Qt::ColorScheme::Unknown
toeffectiveColorScheme.

Fixes: QTBUG-127135
Change-Id: I365d26c66fdb3a754832cb7c579aeebecab093fd
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 2ced94b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
Wladimir Leuschner authored and Qt Cherry-pick Bot committed Oct 9, 2024
1 parent b33e0ea commit 31367fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plugins/platforms/windows/qwindowstheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ QWindowsTheme *QWindowsTheme::m_instance = nullptr;
QWindowsTheme::QWindowsTheme()
{
m_instance = this;
s_colorScheme = QWindowsTheme::queryColorScheme();
s_colorScheme = Qt::ColorScheme::Unknown;
s_colorScheme = QWindowsTheme::effectiveColorScheme();
std::fill(m_fonts, m_fonts + NFonts, nullptr);
std::fill(m_palettes, m_palettes + NPalettes, nullptr);
refresh();
Expand Down Expand Up @@ -578,12 +579,15 @@ Qt::ColorScheme QWindowsTheme::colorScheme() const

Qt::ColorScheme QWindowsTheme::effectiveColorScheme()
{
auto integration = QWindowsIntegration::instance();
if (queryHighContrast())
return Qt::ColorScheme::Unknown;
if (s_colorSchemeOverride != Qt::ColorScheme::Unknown)
return s_colorSchemeOverride;
if (s_colorScheme != Qt::ColorScheme::Unknown)
return s_colorScheme;
if (!integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle))
return Qt::ColorScheme::Light;
return queryColorScheme();
}

Expand Down

0 comments on commit 31367fd

Please sign in to comment.