diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 02331dc23..78d2ad124 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -693,8 +693,8 @@ func (u *UserInterface) createWindow() error { } // unregisterWindowSetSizeCallback must be called from the main thread. -func (u *UserInterface) unregisterWindowSetSizeCallback() { - u.window.SetSizeCallback(nil) +func (u *UserInterface) unregisterWindowSetSizeCallback() bool { + return u.window.SetSizeCallback(nil) != nil } // registerWindowSetSizeCallback must be called from the main thread. @@ -1075,8 +1075,9 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) { // Do not fire the callback of SetSize. This callback can be invoked by SetMonitor or SetSize. // ForceUpdate is called from the callback. // While setWindowSize can be called from Update, calling ForceUpdate inside Update is illegal (#1505). - u.unregisterWindowSetSizeCallback() - defer u.registerWindowSetSizeCallback() + if u.unregisterWindowSetSizeCallback() { + defer u.registerWindowSetSizeCallback() + } var windowRecreated bool @@ -1295,3 +1296,15 @@ func (u *UserInterface) Input() driver.Input { func (u *UserInterface) Window() driver.Window { return &u.iwindow } + +func (u *UserInterface) maximize() { + // Maximizing invokes the SetSize callback but the callback must not be called in Update. + if u.unregisterWindowSetSizeCallback() { + defer u.registerWindowSetSizeCallback() + } + u.window.Maximize() + + // Call setWindowSize explicitly in order to update the rendering since the callback is unregistered now. + w, h := u.window.GetSize() + u.setWindowSize(w, h, u.isFullscreen()) +} diff --git a/internal/uidriver/glfw/window.go b/internal/uidriver/glfw/window.go index beaad0869..190d9c7a0 100644 --- a/internal/uidriver/glfw/window.go +++ b/internal/uidriver/glfw/window.go @@ -136,7 +136,7 @@ func (w *window) Maximize() { return } _ = w.ui.t.Call(func() error { - w.ui.window.Maximize() + w.ui.maximize() return nil }) }