blob: eac68e4f6344b09fbcd1ef25b970368dcbb64265 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <QWidget>
#include "WinDarkmode.h"
namespace WinDarkmode {
/* See https://github.com/statiolake/neovim-qt/commit/da8eaba7f0e38b6b51f3bacd02a8cc2d1f7a34d8 */
void setDarkWinTitlebar(WId winid, bool darkmode)
{
HWND hwnd = reinterpret_cast<HWND>(winid);
BOOL dark = (BOOL) darkmode;
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
fnAllowDarkModeForWindow AllowDarkModeForWindow
= reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
fnSetPreferredAppMode SetPreferredAppMode
= reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
fnSetWindowCompositionAttribute SetWindowCompositionAttribute
= reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
SetPreferredAppMode(AllowDark);
AllowDarkModeForWindow(hwnd, dark);
WINDOWCOMPOSITIONATTRIBDATA data = {
WCA_USEDARKMODECOLORS,
&dark,
sizeof(dark)
};
SetWindowCompositionAttribute(hwnd, &data);
}
}
|