From f539ddcc3f42ef5ab0b6a7bf41151e22bbb10b02 Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Tue, 11 May 2021 16:11:23 -0400 Subject: [PATCH] Add system theme detection on Windows/SDL2 --- platforms/sdl/main.cpp.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/platforms/sdl/main.cpp.in b/platforms/sdl/main.cpp.in index 3cd59af..65bbc84 100644 --- a/platforms/sdl/main.cpp.in +++ b/platforms/sdl/main.cpp.in @@ -8,6 +8,11 @@ #include #include +#ifdef PLATFORM_WINDOWS +#include +#pragma comment(lib, "windowsapp") +#endif + @APP_CLASS@* app = nullptr; GFX* gfx_interface = nullptr; @@ -310,9 +315,25 @@ int main(int argc, char* argv[]) { return 0; } +#ifdef PLATFORM_WINDOWS +PlatformTheme platform::get_theme() { + using namespace winrt::Windows::UI::ViewManagement; + + // TODO: figure out if this works pre-anniversary update/other windows other than 10 + UISettings settings; + auto background = settings.GetColorValue(UIColorType::Background); + auto foreground = settings.GetColorValue(UIColorType::Foreground); + + if (background == winrt::Windows::UI::Colors::White()) + return PlatformTheme::Light; + else + return PlatformTheme::Dark; +} +#else PlatformTheme platform::get_theme() { return PlatformTheme::Light; } +#endif void* platform::create_native_surface(int index, void* instance) { auto window = get_window(index);