-
Notifications
You must be signed in to change notification settings - Fork 0
/
acrylic.cc
91 lines (71 loc) · 2.28 KB
/
acrylic.cc
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <nan.h>
#include <dwmapi.h>
#include <VersionHelpers.h>
struct ACCENTPOLICY
{
int nAccentState;
int nFlags;
int nColor;
int nAnimationId;
};
struct WINCOMATTRPDATA {
int nAttribute;
PVOID pData;
ULONG ulDataSize;
};
enum WINCOMPATTR {
WCA_ACCENT_POLICY = 19
};
enum ACCENTTYPES {
ACCENT_DISABLE = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3, // aero glass
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // fluent design acrylic
ACCENT_INVALID_STATE = 5
};
void Acrylic(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 1) {
Nan::ThrowTypeError("Wrong number of arguments, expected 1");
return;
}
if (!info[0]->IsObject()) {
Nan::ThrowTypeError("Bad arguments");
return;
}
v8::Local<v8::Object> handleBuffer =
info[0].As<v8::Object>();
v8::Isolate* isolate = info.GetIsolate();
v8::HandleScope scope(isolate);
char* bufferData = node::Buffer::Data(handleBuffer);
uint32_t handle = *reinterpret_cast<uint32_t*>((unsigned char*) bufferData);
HWND hwnd = (HWND)handle;
bool result;
if (IsWindowsVersionOrGreater(10, 0, 0)) {
const HINSTANCE hModule = LoadLibrary(TEXT("user32.dll"));
if (hModule) {
typedef BOOL(WINAPI* pSetWindowCompositionAttribute)(HWND, WINCOMATTRPDATA*);
const pSetWindowCompositionAttribute SetWindowCompositionAttribute = (pSetWindowCompositionAttribute)GetProcAddress(hModule, "SetWindowCompositionAttribute");
if (SetWindowCompositionAttribute) {
ACCENTPOLICY policy;
policy.nAccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
// https://stackoverflow.com/a/41433592
policy.nFlags = 2;
// (bgOpacity /* 0 - 255 */ << 24) | (bgColor /* BGR */ & 0xFFFFFF)
policy.nColor = (0x40 << 24) | (0x000000 & 0xFFFFFF);
WINCOMATTRPDATA data;
data.nAttribute = WCA_ACCENT_POLICY;
data.ulDataSize = sizeof(policy);
data.pData = &policy;
result = SetWindowCompositionAttribute(hwnd, &data);
}
FreeLibrary(hModule);
}
}
info.GetReturnValue().Set(true);
}
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New("SetAcrylic").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(Acrylic)->GetFunction());
}
NODE_MODULE(Vibrancy, Init)