From e1b7073e293e2904a9674f22926f80f37c890845 Mon Sep 17 00:00:00 2001 From: Panagiotis Vasilopoulos Date: Sun, 12 Sep 2021 10:34:58 +0200 Subject: [PATCH] Decide default theme on Windows based on the system theme wxWidgets provides an easy way to read registry values, apparently. Instead of forcing the user to switch their theme so that it corresponds to the system theme, it'd be a better idea to just do that for them. What this change does not do: If the user changes the system theme after Tenacity is initially configured, the theme won't change. Some additional style-related changes were also made. Signed-off-by: Panagiotis Vasilopoulos --- src/Theme.cpp | 106 +++++++++++++++++++++++++++++++++----------------- src/Theme.h | 2 + 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/src/Theme.cpp b/src/Theme.cpp index 56da2af35e..dd4f0f2e24 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -62,8 +62,6 @@ can't be. #include "Theme.h" - - #include #include #include @@ -80,6 +78,16 @@ can't be. #include "MemoryX.h" #include "widgets/AudacityMessageBox.h" +#ifdef EXPERIMENTAL_DA +bool useDATheme = true; +#else +bool useDATheme = false; +#endif + +#ifdef __WXMSW__ +#include +#endif + // JKC: First get the MAC specific images. // As we've disabled USE_AQUA_THEME, we need to name each file we use. // @@ -210,6 +218,41 @@ Theme::~Theme(void) { } +#ifdef __WXMSW__ +int Theme::CheckWindowsAppTheme() { + int defaultTheme; + long value; + + wxRegKey key( + wxRegKey::HKCU, + "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize" + ); + + bool valueAccessed = key.QueryValue("AppsUseLightTheme", &value); + + defaultTheme = 1; // "light" until proven "dark" + + if (valueAccessed == true && value == 0) { + // System uses dark theme + defaultTheme = 2; // "dark" + } + + return defaultTheme; +} +#endif + +int Theme::ChooseDefaultTheme() +{ + if (useDATheme = true) { + return 2; + } + +#ifdef __WXMSW__ + return CheckWindowsAppTheme(); +#else + return 1; +#endif +} void Theme::EnsureInitialised() { @@ -1292,39 +1335,30 @@ void auStaticText::OnPaint(wxPaintEvent & WXUNUSED(evt)) dc.DrawText( GetLabel(), 0,0); } -constexpr int defaultTheme = -#ifdef EXPERIMENTAL_DA - 2 // "dark" -#else - 1 // "light" -#endif -; - ChoiceSetting GUITheme{ - wxT("/GUI/Theme"), - { - ByColumns, - { - /* i18n-hint: describing the "classic" or traditional - appearance of older versions of Audacity */ - XO("Classic") , - /* i18n-hint: Light meaning opposite of dark */ - XO("Light") , - XO("Dark") , - /* i18n-hint: greater difference between foreground and - background colors */ - XO("High Contrast") , - /* i18n-hint: user defined */ - XO("Custom") , - }, - { - wxT("classic") , - wxT("light") , - wxT("dark") , - wxT("high-contrast") , - wxT("custom") , - } - }, - defaultTheme + wxT("/GUI/Theme"), + { + ByColumns, + { + /* i18n-hint: describing the "classic" or traditional + appearance of older versions of Audacity */ + XO("Classic"), + /* i18n-hint: Light meaning opposite of dark */ + XO("Light"), + XO("Dark"), + /* i18n-hint: greater difference between foreground and + background colors */ + XO("High Contrast"), + /* i18n-hint: user defined */ + XO("Custom"), + }, + { + wxT("classic"), + wxT("light"), + wxT("dark"), + wxT("high-contrast"), + wxT("custom"), + } + }, + theTheme.ChooseDefaultTheme() }; - diff --git a/src/Theme.h b/src/Theme.h index ea49902cae..a341615232 100644 --- a/src/Theme.h +++ b/src/Theme.h @@ -167,6 +167,8 @@ class TENACITY_DLL_API Theme final : public ThemeBase public: ~Theme(void); public: + int ChooseDefaultTheme(); + int CheckWindowsAppTheme(); void EnsureInitialised() override; void RegisterImages(); void RegisterColours();