-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme_windows.go
More file actions
42 lines (36 loc) · 1.07 KB
/
Copy paththeme_windows.go
File metadata and controls
42 lines (36 loc) · 1.07 KB
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
//go:build windows
package main
import (
"syscall"
"unsafe"
"github.com/lxn/win"
"golang.org/x/sys/windows/registry"
)
// prefersDark reports whether the user selected the dark app theme.
func prefersDark() bool {
k, err := registry.OpenKey(registry.CURRENT_USER,
`Software\Microsoft\Windows\CurrentVersion\Themes\Personalize`, registry.QUERY_VALUE)
if err != nil {
return false
}
defer k.Close()
v, _, err := k.GetIntegerValue("AppsUseLightTheme")
if err != nil {
return false
}
return v == 0
}
var procDwmSetWindowAttribute = syscall.NewLazyDLL("dwmapi.dll").NewProc("DwmSetWindowAttribute")
// applyDarkTitleBar switches the window title bar to dark (Windows 10 20H1+/11).
// Best-effort; silently ignored on older systems.
func applyDarkTitleBar(hwnd win.HWND, dark bool) {
var enabled int32
if dark {
enabled = 1
}
// DWMWA_USE_IMMERSIVE_DARK_MODE: 20 on current builds, 19 on early Win10 2004.
for _, attr := range []uintptr{20, 19} {
procDwmSetWindowAttribute.Call(uintptr(hwnd), attr,
uintptr(unsafe.Pointer(&enabled)), unsafe.Sizeof(enabled))
}
}