-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes fyne fails to setup dark mode #4758
Comments
Sometimes this also happens here. Even though the theme is correctly set in the 'fyne elements', the Windows' own window top bar remains in light theme, as in the print below (exactly when it occurred). It throws the same error 0x800703e6. The right behavior for the window would be: I read the error HRESULT =0x800703e6 represents - ERROR_NOACCESS. A description of the code reveals the message invalid access to memory location. Perhaps a possibility is that the window fyne tries to set to dark mode isn't fully initialized yet? I take this opportunity to ask you: Were you using the SystemTray or SystemTrayMenu API when this occurred? |
I were using none of them. At least on my machine the theme is still applied successfully, and I get the following error description: |
Any error message logged? |
|
OMG windows. I wonder if there is something in the thread handling where we set that up... possibly we knocked it into a goroutine? |
Seems not: runOnMain(func() {
w.setDarkMode() Perhaps there is something in our windows call that is not correct for all systems or at all times? 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) |
I have a vague recollection of this being a thing on old versions of Windows 10 (or at least something similar). Is the system updated to the latest version? |
I debugged the issue and found the return code was: 0x800703e6 More info, that error code is this:
So, looking at the original code I noticed it is passing Bool unsafe with a size of 8. I think there are a few issues with this as I explain here in comments:
So, based on my reasoning above this is the code I came up with. func (w *window) setDarkMode() {
if runtime.GOOS == "windows" {
hwnd := w.view().GetWin32Window()
dark := isDark()
// cannot use a go bool.
var winBool int32
if dark {
winBool = 1
}
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(&winBool)), // on or off
4) // sizeof(bool for windows)
if ret != 0 && ret != 0x80070057 { // err is always non-nil, we check return value (except erroneous code)
fyne.LogError("Failed to set dark mode", err)
}
}
} The above code works for my machine, windows 10. I think there is some out of date document implying DWMWA_USE_IMMERSIVE_DARK_MODE only works starting windows 11, but I think they added this in a newer windows 10 patch, I am just unsure when. However, the check for 0x80070057 catches the case for versions where windows 10 isn't supported. Anyway, I think these are the correct changes that should work on windows 10 and window 11 and shouldn't randomly give these errors or make the title bar the wrong color (it could be white or black with the opposite theme with this bug). |
…SetWindowAttribute and DWMWA_USE_IMMERSIVE_DARK_MODE on windows.
…SetWindowAttribute and DWMWA_USE_IMMERSIVE_DARK_MODE on windows.
…SetWindowAttribute and DWMWA_USE_IMMERSIVE_DARK_MODE on windows.
…-4758 Fixes #4758, set the correct parameter memory and size for DwmSetWindowAttribute and DWMWA_USE_IMMERSIVE_DARK_MODE on windows.
Thanks to @steampoweredtaco this is fixed on develop, and I will pick it onto release branch |
…SetWindowAttribute and DWMWA_USE_IMMERSIVE_DARK_MODE on windows.
Checklist
Describe the bug
Happens randomly, with error code 0x800703e6.
Dark mode, however, is still set successfully.
How to reproduce
Use
go run .
until it appears. Depends on your luck I guess.Screenshots
No response
Example code
Fyne version
2.4.4
Go compiler version
1.22.0
Operating system and version
Windows 10
Additional Information
Modified
internal/driver/glfw/window_windows.go
to show the error code.The text was updated successfully, but these errors were encountered: