internal/ui: show window after first draw on glfw (#2875)

Fixes #2725 by avoiding the flash in the first place. Showing the
window this way was already default on macOS; This makes it default
for all glfw platforms.

Closes #2725
This commit is contained in:
theinternetftw 2023-12-29 00:16:54 -05:00 committed by GitHub
parent 338b8957e8
commit 5774cf808f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}