comparison src/sys/win32/dark_theme.cc @ 258:862d0d8619f6

*: HUUUGE changes animia has been renamed to animone, so instead of thinking of a health condition, you think of a beautiful flower :) I've also edited some of the code for animone, but I have no idea if it even works or not because I don't have a mac or windows machine lying around. whoops! ... anyway, all of the changes divergent from Anisthesia are now licensed under BSD. it's possible that I could even rewrite most of the code to where I don't even have to keep the MIT license, but that's thinking too far into the future I've been slacking off on implementing the anime seasons page, mostly out of laziness. I think I'd have to create another db file specifically for the seasons anyway, this code is being pushed *primarily* because the hard drive it's on is failing! yay :)
author Paper <paper@paper.us.eu.org>
date Mon, 01 Apr 2024 02:43:44 -0400
parents f0ff06a45c42
children
comparison
equal deleted inserted replaced
257:699a20c57dc8 258:862d0d8619f6
9 #include <memory> 9 #include <memory>
10 10
11 #include <dwmapi.h> 11 #include <dwmapi.h>
12 12
13 struct LibraryDeconstructor { 13 struct LibraryDeconstructor {
14 using pointer = HINSTANCE; 14 using pointer = HINSTANCE;
15 void operator()(pointer t) const { ::FreeLibrary(t); }; 15 void operator()(pointer t) const { ::FreeLibrary(t); };
16 }; 16 };
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() { library.reset( ::LoadLibraryW(L"dwmapi.dll")); } 22 Dwmapi() {
23 /* load functions */
24 library.reset(::LoadLibraryW(L"dwmapi.dll"));
25 set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>(
26 GetProcAddress(library.get(), "DwmSetWindowAttribute"));
27 }
23 28
24 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { 29 HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) {
25 if (!library.get()) 30 if (!library.get())
26 return E_POINTER; 31 return E_POINTER;
27 32
28 // GCC throws a fit here because C/C++ lacks a "generic" function pointer type. 33 /* GCC throws a fit here because C++ lacks a "generic" function pointer type.
29 // Ignore. 34 * Ignore. */
30 auto set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>(GetProcAddress(library.get(), "DwmSetWindowAttribute")); 35 if (!set_wind_attrib)
31 if (!set_wind_attrib) 36 return E_POINTER;
32 return E_POINTER;
33 37
34 return set_wind_attrib(hWnd, key, data, sz_data); 38 return set_wind_attrib(hWnd, key, data, sz_data);
35 } 39 }
36 40
37 protected: 41 protected:
38 Library library = nullptr; 42 Library library = nullptr;
43 decltype(::DwmSetWindowAttribute)* set_wind_attrib;
39 }; 44 };
40 45
41 Dwmapi dwmapi; 46 Dwmapi dwmapi;
42 47
43 namespace win32 { 48 namespace win32 {
45 bool SetTitleBarToBlack(QWidget* win, bool enabled) { 50 bool SetTitleBarToBlack(QWidget* win, bool enabled) {
46 /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE. 51 /* 19 and 20 are *both* DWMWA_USE_IMMERSIVE_DARK_MODE.
47 * 52 *
48 * It's 20 on newer versions of windows (i.e. win11 and late win10), 53 * 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. 54 * but it's 19 on very old versions of win10 nobody ought to be using anymore.
50 */ 55 */
51 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19; 56 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE_OLD = 19;
52 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE = 20; 57 static constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
53 58
54 BOOL b = enabled; 59 BOOL b = enabled;
55 60
56 { 61 {
57 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE, &b, sizeof(b)); 62 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE,
63 &b, sizeof(b));
58 if (result == S_OK) 64 if (result == S_OK)
59 return b; 65 return b;
60 } 66 }
61 67
62 { 68 {
63 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, &b, sizeof(b)); 69 HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()),
70 DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, &b, sizeof(b));
64 if (result == S_OK) 71 if (result == S_OK)
65 return b; 72 return b;
66 } 73 }
67 74
68 return b; 75 return b;