Mercurial > hg > svcore
changeset 1818:c5ee0746bdef background-mode
Determine whether a dark background is indicated
author | Chris Cannam |
---|---|
date | Fri, 17 Jan 2020 21:36:07 +0000 |
parents | 23d5cb3f9f38 |
children | 4eda6ba5b5d8 |
files | system/System.cpp system/System.h |
diffstat | 2 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/system/System.cpp Tue Jan 14 15:48:22 2020 +0000 +++ b/system/System.cpp Fri Jan 17 21:36:07 2020 +0000 @@ -27,6 +27,10 @@ #include <unistd.h> #endif +#ifdef _MSC_VER +#include <winrt/Windows.UI.ViewManagement.h> +#endif + #ifdef __APPLE__ #include <sys/param.h> #include <sys/sysctl.h> @@ -334,6 +338,21 @@ } } +bool +OSThemeIsDark() +{ + SVCERR << "OSThemeIsDark() called" << endl; +#ifdef _MSC_VER + using namespace winrt::Windows::UI::ViewManagement; + UISettings settings; + auto background = settings.GetColorValue(UIColorType::Background); + if (int(background.R) + int(background.G) + int(background.B) < 384) { + return true; + } +#endif + return false; +} + double mod(double x, double y) { return x - (y * floor(x / y)); } float modf(float x, float y) { return x - (y * floorf(x / y)); }
--- a/system/System.h Tue Jan 14 15:48:22 2020 +0000 +++ b/system/System.h Fri Jan 17 21:36:07 2020 +0000 @@ -163,6 +163,11 @@ // if unknown. (Hence signed return type) extern ssize_t GetDiscSpaceMBAvailable(const char *path); +// Return true if the OS desktop is set to use a dark mode +// theme. Return false if it is set to a light theme or if the theme +// is unknown. +extern bool OSThemeIsDark(); + extern void StoreStartupLocale(); extern void RestoreStartupLocale();