Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/sys/win32/dark_theme.cc Sun Feb 18 16:02:14 2024 -0500 +++ b/src/sys/win32/dark_theme.cc Mon Apr 01 02:43:44 2024 -0400 @@ -11,31 +11,36 @@ #include <dwmapi.h> struct LibraryDeconstructor { - using pointer = HINSTANCE; - void operator()(pointer t) const { ::FreeLibrary(t); }; + using pointer = HINSTANCE; + void operator()(pointer t) const { ::FreeLibrary(t); }; }; using Library = std::unique_ptr<HINSTANCE, LibraryDeconstructor>; class Dwmapi { - public: - Dwmapi() { library.reset( ::LoadLibraryW(L"dwmapi.dll")); } +public: + Dwmapi() { + /* load functions */ + library.reset(::LoadLibraryW(L"dwmapi.dll")); + set_wind_attrib = reinterpret_cast<decltype(::DwmSetWindowAttribute)*>( + GetProcAddress(library.get(), "DwmSetWindowAttribute")); + } - HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { - if (!library.get()) - return E_POINTER; + HRESULT SetWindowAttribute(HWND hWnd, DWORD key, LPCVOID data, DWORD sz_data) { + if (!library.get()) + return E_POINTER; - // 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; + /* GCC throws a fit here because C++ lacks a "generic" function pointer type. + * Ignore. */ + if (!set_wind_attrib) + return E_POINTER; - return set_wind_attrib(hWnd, key, data, sz_data); - } + return set_wind_attrib(hWnd, key, data, sz_data); + } - protected: - Library library = nullptr; +protected: + Library library = nullptr; + decltype(::DwmSetWindowAttribute)* set_wind_attrib; }; Dwmapi dwmapi; @@ -47,20 +52,22 @@ * * 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; { - HRESULT result = dwmapi.SetWindowAttribute(reinterpret_cast<HWND>(win->winId()), DWMWA_USE_IMMERSIVE_DARK_MODE, &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()), DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, &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; }