Mercurial > minori
comparison src/sys/win32/dark_theme.cc @ 379:5eaafed6c10b default tip
*: clang-format
| author | Paper <paper@tflc.us> |
|---|---|
| date | Wed, 05 Nov 2025 12:59:46 -0500 |
| parents | 862d0d8619f6 |
| children |
comparison
equal
deleted
inserted
replaced
| 378:5912dafc6e28 | 379:5eaafed6c10b |
|---|---|
| 17 | 17 |
| 18 using Library = std::unique_ptr<HINSTANCE, LibraryDeconstructor>; | 18 using Library = std::unique_ptr<HINSTANCE, LibraryDeconstructor>; |
| 19 | 19 |
| 20 class Dwmapi { | 20 class Dwmapi { |
| 21 public: | 21 public: |
| 22 Dwmapi() { | 22 Dwmapi() |
| 23 { | |
| 23 /* load functions */ | 24 /* load functions */ |
| 24 library.reset(::LoadLibraryW(L"dwmapi.dll")); | 25 library.reset(::LoadLibraryW(L"dwmapi.dll")); |
| 25 set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>( | 26 set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute) *>( |
| 26 GetProcAddress(library.get(), "DwmSetWindowAttribute")); | 27 GetProcAddress(library.get(), "DwmSetWindowAttribute")); |
| 27 } | 28 } |
| 28 | 29 |
| 29 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { | 30 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) |
| 31 { | |
| 30 if (!library.get()) | 32 if (!library.get()) |
| 31 return E_POINTER; | 33 return E_POINTER; |
| 32 | 34 |
| 33 /* GCC throws a fit here because C++ lacks a "generic" function pointer type. | 35 /* GCC throws a fit here because C++ lacks a "generic" function pointer type. |
| 34 * Ignore. */ | 36 * Ignore. */ |
| 38 return set_wind_attrib(hWnd, key, data, sz_data); | 40 return set_wind_attrib(hWnd, key, data, sz_data); |
| 39 } | 41 } |
| 40 | 42 |
| 41 protected: | 43 protected: |
| 42 Library library = nullptr; | 44 Library library = nullptr; |
| 43 decltype(::DwmSetWindowAttribute)* set_wind_attrib; | 45 decltype(::DwmSetWindowAttribute) *set_wind_attrib; |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 Dwmapi dwmapi; | 48 Dwmapi dwmapi; |
| 47 | 49 |
| 48 namespace win32 { | 50 namespace win32 { |
| 49 | 51 |
| 50 bool SetTitleBarToBlack(QWidget* win, bool enabled) { | 52 bool SetTitleBarToBlack(QWidget *win, bool enabled) |
| 53 { | |
| 51 /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. | 54 /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. |
| 52 * | 55 * |
| 53 * It's 20 on newer versions of windows (i.e. win11 and late win10), | 56 * It's 20 on newer versions of windows (i.e. win11 and late win10), |
| 54 * but it's 19 on very old versions of win10 nobody ought to be using anymore. | 57 * but it's 19 on very old versions of win10 nobody ought to be using anymore. |
| 55 */ | 58 */ |
| 73 } | 76 } |
| 74 | 77 |
| 75 return b; | 78 return b; |
| 76 } | 79 } |
| 77 | 80 |
| 78 void SetTitleBarsToBlack(bool enabled) { | 81 void SetTitleBarsToBlack(bool enabled) |
| 79 for (QWidget* widget : qApp->topLevelWidgets()) { | 82 { |
| 83 for (QWidget *widget : qApp->topLevelWidgets()) { | |
| 80 SetTitleBarToBlack(widget, enabled); | 84 SetTitleBarToBlack(widget, enabled); |
| 81 } | 85 } |
| 82 } | 86 } |
| 83 | 87 |
| 84 bool DarkThemeAvailable() { | 88 bool DarkThemeAvailable() |
| 85 const auto& ver = QOperatingSystemVersion::current(); | 89 { |
| 90 const auto &ver = QOperatingSystemVersion::current(); | |
| 86 return (ver.majorVersion() > 10) ? true : (ver.majorVersion() == 10 && ver.microVersion() >= 17763); | 91 return (ver.majorVersion() > 10) ? true : (ver.majorVersion() == 10 && ver.microVersion() >= 17763); |
| 87 } | 92 } |
| 88 | 93 |
| 89 bool IsInDarkTheme() { | 94 bool IsInDarkTheme() |
| 95 { | |
| 90 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", | 96 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", |
| 91 QSettings::NativeFormat); | 97 QSettings::NativeFormat); |
| 92 return settings.value("AppsUseLightTheme", 1).toInt() == 0; | 98 return settings.value("AppsUseLightTheme", 1).toInt() == 0; |
| 93 } | 99 } |
| 94 | 100 |
