diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 2cea80494..624a93705 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -104,6 +104,7 @@ type userInterfaceImpl struct { framebufferSizeCallbackCh chan struct{} darwinInitOnce sync.Once + showWindowOnce sync.Once bufferOnceSwappedOnce sync.Once m sync.RWMutex @@ -1077,6 +1078,11 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error { return err } + // Window is shown after the first buffer swap. + if err := glfw.WindowHint(glfw.Visible, glfw.False); err != nil { + return err + } + // On macOS, window decoration should be initialized once after buffers are swapped (#2600). if runtime.GOOS != "darwin" { decorated := glfw.False @@ -1170,13 +1176,6 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error { _ = u.skipTaskbar() } - // On macOS, the window is shown once after buffers are swapped at update. - if runtime.GOOS != "darwin" { - if err := u.window.Show(); err != nil { - return err - } - } - switch g := u.graphicsDriver.(type) { case interface{ SetGLFWWindow(window *glfw.Window) }: g.SetGLFWWindow(u.window) @@ -1321,8 +1320,16 @@ func (u *UserInterface) update() (float64, float64, error) { if err = u.window.SetAttrib(glfw.Decorated, decorated); err != nil { return } + }) + if err != nil { + return 0, 0, err + } + } - // The window is not shown at the initialization on macOS. Show the window here. + if u.bufferOnceSwapped { + var err error + u.showWindowOnce.Do(func() { + // Show the window after first buffer swap to avoid flash of white especially on Windows. if err = u.window.Show(); err != nil { return }