diff --git a/interface/wx/app.h b/interface/wx/app.h index 95f1d5ab6f..4651a1d4dc 100644 --- a/interface/wx/app.h +++ b/interface/wx/app.h @@ -1193,6 +1193,10 @@ public: functions to enable dark mode support for the desktop applications under Windows 10 20H1 or later (including all Windows 11 versions). + Note that dark mode can also be enabled by setting the "msw.dark-mode" + @ref wxSystemOptions "system option" via an environment variable from + outside the application. + @param flags Can include @c wxApp::DarkMode_Always to force enabling dark mode for the application, even if the system doesn't use the dark mode by default. Otherwise dark mode is only used if it is the diff --git a/interface/wx/sysopt.h b/interface/wx/sysopt.h index 19cc635270..c19865d0b8 100644 --- a/interface/wx/sysopt.h +++ b/interface/wx/sysopt.h @@ -76,6 +76,11 @@ If set to 1, disables the use of composited, i.e. double-buffered, windows by default in wxMSW. This is not recommended, but can be useful for debugging or working around redraw problems in the existing code. + @flag{msw.dark-mode} + If set to 1, enable experimental support of dark mode if the system is + using it, i.e. this has the same effect as calling + wxApp::MSWEnableDarkMode(). If set to 2, use dark mode unconditionally, + as if this function were called with wxApp::DarkMode_Always argument. @endFlagTable diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 0d798b8895..13a5f4fa5b 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -48,6 +48,7 @@ #include "wx/thread.h" #include "wx/platinfo.h" #include "wx/scopeguard.h" +#include "wx/sysopt.h" #include "wx/vector.h" #include "wx/weakref.h" @@ -631,6 +632,14 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) wxSetKeyboardHook(true); + // this is useful to allow users to enable dark mode for the applications + // not enabling it themselves by setting the corresponding environment + // variable + if ( const int darkMode = wxSystemOptions::GetOptionInt("msw.dark-mode") ) + { + MSWEnableDarkMode(darkMode > 1 ? DarkMode_Always : DarkMode_Auto); + } + callBaseCleanup.Dismiss(); return true;