From e0aa15b624cf639234d5d375e593aad9a3d3554e Mon Sep 17 00:00:00 2001 From: aybe Date: Mon, 15 Jul 2024 00:11:59 +0200 Subject: [PATCH] Add [dosbox] CFGTOOL theme setting + OS dark mode detection --- CHANGELOG | 2 +- src/dosbox.cpp | 12 ++++++++++++ src/gui/sdl_gui.cpp | 24 ++++++++++++++++++++++++ src/gui/sdlmain.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a4a0a2e5c4..22401e1dc8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,7 +22,7 @@ NEXT - Fixed TTF mode didn't change to graphic mode when machine = Hercules (maron2000) - Configuration tool: (aybe) - - more Windows 3.1 styling: buttons, colors, focus, layout + - more Windows 3.1 look'n'feel (themes w/ host dark mode detection) - enhance main window layout, it is now visible in its entirety - fix layout issues, off by one in rectangle drawing functions - fix 'list iterators incompatible' when pressing the Tab key diff --git a/src/dosbox.cpp b/src/dosbox.cpp index d167c8c10c..6456353a08 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -1422,6 +1422,11 @@ void DOSBOX_SetupConfigSections(void) { const char* quit_settings[] = { "true", "false", "1", "0", "auto", "autofile", nullptr }; const char* autofix_settings[] = { "true", "false", "1", "0", "both", "a20fix", "loadfix", "none", nullptr }; const char* color_themes[] = { "default", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", nullptr }; + const char* color_themes_config[] = { + "Windows Default", "Arizona", "Black Leather Jacket", "Bordeaux", "Cinnamon", "Designer", "Emerald City", + "Fluorescent","HotDog Stand", "LCD Default Screen Settings", "LCD Reversed - Dark", "LCD Reversed - Light", + "Mahogany", "Monochrome", "Ocean", "Pastel", "Patchwork", "Plasma Power Saver", "Rugby", "The Blues", + "Tweed", "Valentine", "Wingtips", nullptr }; const char* irqsgus[] = { "5", "3", "7", "9", "10", "11", "12", nullptr }; const char* irqssb[] = { "7", "5", "3", "9", "10", "11", "12", "0", "-1", nullptr }; const char* dmasgus[] = { "3", "0", "1", "5", "6", "7", nullptr }; @@ -1575,6 +1580,13 @@ void DOSBOX_SetupConfigSections(void) { Pstring->Set_help("You can specify a different background color theme for the welcome banner from the default one."); Pstring->SetBasic(true); + Pstring = secprop->Add_path("configuration tool theme", Property::Changeable::WhenIdle, ""); + Pstring->Set_values(color_themes_config); + Pstring->Set_help( + "Theme for the configuration tool.\n" + "If not set, host dark mode setting will be followed.\n"); + Pstring->SetBasic(true); + Pstring = secprop->Add_string("dpi aware",Property::Changeable::OnlyAtStart,"auto"); Pstring->Set_values(truefalseautoopt); Pstring->Set_help("Set this option (auto by default) to indicate to your OS that DOSBox-X is DPI aware.\n" diff --git a/src/gui/sdl_gui.cpp b/src/gui/sdl_gui.cpp index 3b92cf921d..6e3d021c16 100644 --- a/src/gui/sdl_gui.cpp +++ b/src/gui/sdl_gui.cpp @@ -3314,6 +3314,30 @@ class ConfigurationWindow : public GUI::ToplevelWindow { Section_prop * section=static_cast(control->GetSection("dosbox")); advopt->setChecked(section->Get_bool("show advanced options") || advOptUser); + // apply theme + { + auto theme = std::string(section->Get_string("configuration tool theme")); + + if(theme.empty()) + { + bool dark = false; + +#if defined(WIN32) && !defined(HX_DOS) + // ReSharper disable once CppDeclaratorDisambiguatedAsFunction + bool HostDarkMode(); // NOLINT(clang-diagnostic-vexing-parse) + dark = HostDarkMode(); +#endif + TryApplyTheme( + dark + ? GUI::ThemeWindows31LCDReversedDark::GetName() + : GUI::ThemeWindows31LCDReversedLight::GetName()); + } + else + { + TryApplyTheme(theme); + } + } + strcpy(tmp1, (MSG_Get("SAVE")+std::string("...")).c_str()); const auto xSave = gridbtnx + (gridbtnwidth + margin) * 2; diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 0d6916e7e7..7f93f4c97d 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -363,6 +363,33 @@ bool UpdateWindows11RoundCorners(HWND hWnd, CornerPreference cornerPreference) { } return false; } + +bool HostDarkMode() +{ + // https://gist.github.com/rounk-ctrl/b04e5622e30e0d62956870d5c22b7017 + + using PFNSHOULDAPPSUSEDARKMODE = bool (WINAPI *)(); + + const auto module = ::LoadLibrary("uxtheme.dll"); + + if(module) + { + auto* pfnShouldAppsUseDarkMode = reinterpret_cast( + GetProcAddress(module, MAKEINTRESOURCEA(132))); + + if(pfnShouldAppsUseDarkMode) + { + const auto dark = pfnShouldAppsUseDarkMode(); + + return dark; + } + + FreeLibrary(module); + } + + return false; +} + #endif #if defined(WIN32)