blob: 381f0020d4f1f85b85683e18061be97879db4368 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package moe.yuuta.aero
import aero.ACCENT_POLICY
import aero.WINDOWCOMPOSITIONATTRIBDATA
import aero.pfnSetWindowCompositionAttribute
import kotlinx.cinterop.*
import platform.windows.*
object WinApi {
fun getenv(name: String): String = memScoped {
val buffer = nativeHeap.allocArray<CHARVar>(MAX_PATH)
GetEnvironmentVariableA(name,
buffer,
MAX_PATH
)
val env = buffer.toKString()
nativeHeap.free(buffer)
return@memScoped env
}
fun msgLoop() {
memScoped {
val msg = nativeHeap.alloc<MSG>()
while (GetMessageA(msg.ptr,
null,
0.convert(),
0.convert()) != 0) {
TranslateMessage(msg.ptr)
DispatchMessageA(msg.ptr)
}
// The queue quits
nativeHeap.free(msg)
}
}
fun setAero(hwnd: HWND?) {
val hUser = GetModuleHandleW("user32.dll") ?: return
val setWindowCompositionAttribute = GetProcAddress(hUser,
"SetWindowCompositionAttribute")
as pfnSetWindowCompositionAttribute? ?: return
val accent = cValue<ACCENT_POLICY> {
AccentState = aero.ACCENT_ENABLE_BLURBEHIND
AccentFlags = 0.convert()
GradientColor = 0.convert()
AnimationId = 0.convert()
}
memScoped {
val data = cValue<WINDOWCOMPOSITIONATTRIBDATA> {
Attrib = aero.WCA_ACCENT_POLICY
pvData = accent.ptr
cbData = accent.size.convert()
}
setWindowCompositionAttribute(hwnd, data.ptr)
}
}
}
|