Skip to content

Commit

Permalink
Add [dosbox] CFGTOOL theme setting + OS dark mode detection
Browse files Browse the repository at this point in the history
  • Loading branch information
aybe committed Jul 14, 2024
1 parent 117ee50 commit e0aa15b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/dosbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions src/gui/sdl_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3314,6 +3314,30 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
Section_prop * section=static_cast<Section_prop *>(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;
Expand Down
27 changes: 27 additions & 0 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PFNSHOULDAPPSUSEDARKMODE>(
GetProcAddress(module, MAKEINTRESOURCEA(132)));

if(pfnShouldAppsUseDarkMode)
{
const auto dark = pfnShouldAppsUseDarkMode();

return dark;
}

FreeLibrary(module);
}

return false;
}

#endif

#if defined(WIN32)
Expand Down

0 comments on commit e0aa15b

Please sign in to comment.