diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 3288c7440..addf12e72 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -231,7 +231,10 @@ func (g *game) Update(screen *ebiten.Image) error { } maximize := inpututil.IsKeyJustPressed(ebiten.KeyM) minimize := inpututil.IsKeyJustPressed(ebiten.KeyN) - restore := inpututil.IsKeyJustPressed(ebiten.KeyE) + restore := false + if ebiten.IsWindowMaximized() || ebiten.IsWindowMinimized() { + restore = inpututil.IsKeyJustPressed(ebiten.KeyE) + } if toUpdateWindowSize { if *flagLegacy { diff --git a/window.go b/window.go index e00c5cd60..cdf119143 100644 --- a/window.go +++ b/window.go @@ -278,10 +278,15 @@ func MaximizeWindow() { // IsWindowMaximized reports whether the window is maximized or not. // +// IsWindowMaximized returns false when the window is not resizable. +// // IsWindowMaximized always returns false on browsers and mobiles. // // IsWindowMaximized is concurrent-safe. func IsWindowMaximized() bool { + if !IsWindowResizable() { + return false + } if w := uiDriver().Window(); w != nil { return w.IsMaximized() } @@ -315,8 +320,13 @@ func IsWindowMinimized() bool { // RestoreWindow restores the window from its maximized or minimized state. // +// RestoreWindow panics when the window is not maximized nor minimized. +// // RestoreWindow is concurrent-safe. func RestoreWindow() { + if !IsWindowMaximized() && !IsWindowMinimized() { + panic("ebiten: RestoreWindow must be called on a maximized or a minimized window") + } if w := uiDriver().Window(); w != nil { w.Restore() }