Mercurial > minori
diff src/sys/win32/dark_theme.cc @ 196:f0ff06a45c42
date: use std::optional for values
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 07 Dec 2023 16:28:11 -0500 |
parents | bc8d2ccff09c |
children | 862d0d8619f6 |
line wrap: on
line diff
--- a/src/sys/win32/dark_theme.cc Thu Dec 07 11:14:01 2023 -0500 +++ b/src/sys/win32/dark_theme.cc Thu Dec 07 16:28:11 2023 -0500 @@ -25,8 +25,8 @@ if (!library.get()) return E_POINTER; - /* GCC throws a fit here because C/C++ lacks a "generic" function pointer type. - Ignore. */ + // GCC throws a fit here because C/C++ lacks a "generic" function pointer type. + // Ignore. auto set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>(GetProcAddress(library.get(), "DwmSetWindowAttribute")); if (!set_wind_attrib) return E_POINTER; @@ -42,21 +42,25 @@ namespace win32 { -/* NOTE: explicit conversion from builtin `bool` and win32 `BOOL` IS allowed. */ bool SetTitleBarToBlack(QWidget* win, bool enabled) { + /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. + * + * It's 20 on newer versions of windows (i.e. win11 and late win10), + * but it's 19 on very old versions of win10 nobody ought to be using anymore. + */ + static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19; + static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE = 20; + BOOL b = enabled; - /* MAGIC NUMBERS: 19 and 20 are both DWMWA_USE_IMMERSIVE_DARK_MODE. - For clarification: it's 20 on newer versions of windows (i.e. win11 and late win10), - but it's 19 on very old versions of win10 nobody ought to be using anymore. */ { - HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), 20, &b, sizeof(b)); + HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE, &b, sizeof(b)); if (result == S_OK) return b; } { - HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), 19, &b, sizeof(b)); + HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, &b, sizeof(b)); if (result == S_OK) return b; }