Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry picking Windows 10 theme workaround for dark mode
Fixes #2184
- Loading branch information
1 parent
b1b5a18
commit 8d9c106
Showing
4 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// +build !windows | ||
|
||
package glfw | ||
|
||
func (w *window) setDarkMode() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package glfw | ||
|
||
import ( | ||
"runtime" | ||
"syscall" | ||
"unsafe" | ||
|
||
"fyne.io/fyne/v2" | ||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
func (w *window) setDarkMode() { | ||
if runtime.GOOS == "windows" { | ||
hwnd := w.view().GetWin32Window() | ||
dark := isDark() | ||
|
||
dwm := syscall.NewLazyDLL("dwmapi.dll") | ||
setAtt := dwm.NewProc("DwmSetWindowAttribute") | ||
ret, _, err := setAtt.Call(uintptr(unsafe.Pointer(hwnd)), // window handle | ||
20, // DWMWA_USE_IMMERSIVE_DARK_MODE | ||
uintptr(unsafe.Pointer(&dark)), // on or off | ||
8) // sizeof(darkMode) | ||
|
||
if ret != 0 { // err is always non-nil, we check return value | ||
fyne.LogError("Failed to set dark mode", err) | ||
} | ||
} | ||
} | ||
|
||
func isDark() bool { | ||
k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize`, registry.QUERY_VALUE) | ||
if err != nil { // older version of Windows will not have this key | ||
return false | ||
} | ||
defer k.Close() | ||
|
||
useLight, _, err := k.GetIntegerValue("AppsUseLightTheme") | ||
if err != nil { // older version of Windows will not have this value | ||
return false | ||
} | ||
|
||
return useLight == 0 | ||
} |