Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Decide default theme on Windows based on the system theme
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
n0toose committed Sep 12, 2021
1 parent 5cb9586 commit e1b7073
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 36 deletions.
106 changes: 70 additions & 36 deletions src/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ can't be.

#include "Theme.h"



#include <wx/wxprec.h>
#include <wx/dcclient.h>
#include <wx/image.h>
Expand All @@ -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 <wx/msw/registry.h>
#endif

// JKC: First get the MAC specific images.
// As we've disabled USE_AQUA_THEME, we need to name each file we use.
//
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
};

2 changes: 2 additions & 0 deletions src/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e1b7073

Please sign in to comment.