Mercurial > minori
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 195:975a3f0965e2 | 196:f0ff06a45c42 | 
|---|---|
| 23 | 23 | 
| 24 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { | 24 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { | 
| 25 if (!library.get()) | 25 if (!library.get()) | 
| 26 return E_POINTER; | 26 return E_POINTER; | 
| 27 | 27 | 
| 28 /* GCC throws a fit here because C/C++ lacks a "generic" function pointer type. | 28 // GCC throws a fit here because C/C++ lacks a "generic" function pointer type. | 
| 29 Ignore. */ | 29 // Ignore. | 
| 30 auto set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>(GetProcAddress(library.get(), "DwmSetWindowAttribute")); | 30 auto set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>(GetProcAddress(library.get(), "DwmSetWindowAttribute")); | 
| 31 if (!set_wind_attrib) | 31 if (!set_wind_attrib) | 
| 32 return E_POINTER; | 32 return E_POINTER; | 
| 33 | 33 | 
| 34 return set_wind_attrib(hWnd, key, data, sz_data); | 34 return set_wind_attrib(hWnd, key, data, sz_data); | 
| 40 | 40 | 
| 41 Dwmapi dwmapi; | 41 Dwmapi dwmapi; | 
| 42 | 42 | 
| 43 namespace win32 { | 43 namespace win32 { | 
| 44 | 44 | 
| 45 /* NOTE: explicit conversion from builtin `bool` and win32 `BOOL` IS allowed. */ | |
| 46 bool SetTitleBarToBlack(QWidget* win, bool enabled) { | 45 bool SetTitleBarToBlack(QWidget* win, bool enabled) { | 
| 46 /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. | |
| 47 * | |
| 48 * It's 20 on newer versions of windows (i.e. win11 and late win10), | |
| 49 * but it's 19 on very old versions of win10 nobody ought to be using anymore. | |
| 50 */ | |
| 51 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19; | |
| 52 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE = 20; | |
| 53 | |
| 47 BOOL b = enabled; | 54 BOOL b = enabled; | 
| 48 | 55 | 
| 49 /* MAGIC NUMBERS: 19 and 20 are both DWMWA_USE_IMMERSIVE_DARK_MODE. | |
| 50 For clarification: it's 20 on newer versions of windows (i.e. win11 and late win10), | |
| 51 but it's 19 on very old versions of win10 nobody ought to be using anymore. */ | |
| 52 { | 56 { | 
| 53 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), 20, &b, sizeof(b)); | 57 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE, &b, sizeof(b)); | 
| 54 if (result == S_OK) | 58 if (result == S_OK) | 
| 55 return b; | 59 return b; | 
| 56 } | 60 } | 
| 57 | 61 | 
| 58 { | 62 { | 
| 59 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), 19, &b, sizeof(b)); | 63 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, &b, sizeof(b)); | 
| 60 if (result == S_OK) | 64 if (result == S_OK) | 
| 61 return b; | 65 return b; | 
| 62 } | 66 } | 
| 63 | 67 | 
| 64 return b; | 68 return b; | 
