internal/uidriver/glfw: Bug fix: Unregister SetSize callback when undecorate the window

Closes #1586
This commit is contained in:
Hajime Hoshi 2021-04-18 21:23:59 +09:00
parent f5a4216434
commit c88ee0d0ad
2 changed files with 19 additions and 6 deletions

View File

@ -1362,3 +1362,20 @@ func (u *UserInterface) restore() {
w, h := u.window.GetSize()
u.setWindowSize(w, h, u.isFullscreen())
}
func (u *UserInterface) setDecorated(decorated bool) {
// SetAttrib with glfw.Decorated invokes the SetSize callback but the callback must not be called in the game's Update (#1586).
// SetSize callback is invoked in the limited situations like just after restoring from the fullscreen mode.
if u.unregisterWindowSetSizeCallback() {
defer u.registerWindowSetSizeCallback()
}
v := glfw.False
if decorated {
v = glfw.True
}
u.window.SetAttrib(glfw.Decorated, v)
// Just after restoring from the fullscreen mode, the window's size might be a wrong value on Windows.
// This was the cause to invoke SetSize callback unexpectedly. This sounds like a GLFW's issue, but this is not confirmed.
// As the window size should not be changed, setWindowSize doesn't have to be called anyway.
}

View File

@ -51,14 +51,10 @@ func (w *window) SetDecorated(decorated bool) {
return nil
}
v := glfw.False
if decorated {
v = glfw.True
}
w.ui.window.SetAttrib(glfw.Decorated, v)
w.ui.setDecorated(decorated)
// The title can be lost when the decoration is gone. Recover this.
if v == glfw.True {
if decorated {
w.ui.window.SetTitle(w.ui.title)
}
return nil