mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: forbide SetWindowSize
when the window is maximized
On Windows, changing the size of a maximized window results in unexpected states. Let's forbid this. On macOS, a maximized window is just a regular window so it is OK to allow resizing by `SetWindowSize`. On Linux or other Unix, the behavior depends on window systems and it is hard to expect what would happen, so forbid this just in case. Closes #1986
This commit is contained in:
parent
1c548c0641
commit
5b182efe7e
@ -1686,3 +1686,8 @@ func (u *userInterfaceImpl) forceToRefreshIfNeeded() {
|
||||
glfw.PollEvents()
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
|
||||
// isWindowMaximized must be called from the main thread.
|
||||
func (u *userInterfaceImpl) isWindowMaximized() bool {
|
||||
return u.window.GetAttrib(glfw.Maximized) == glfw.True && !u.isNativeFullscreen()
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package ui
|
||||
|
||||
import (
|
||||
"image"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
)
|
||||
@ -105,7 +106,7 @@ func (w *glfwWindow) IsMaximized() bool {
|
||||
}
|
||||
var v bool
|
||||
w.ui.t.Call(func() {
|
||||
v = w.ui.window.GetAttrib(glfw.Maximized) == glfw.True && !w.ui.isNativeFullscreen()
|
||||
v = w.ui.isWindowMaximized()
|
||||
})
|
||||
return v
|
||||
}
|
||||
@ -200,10 +201,16 @@ func (w *glfwWindow) Size() (int, int) {
|
||||
|
||||
func (w *glfwWindow) SetSize(width, height int) {
|
||||
if !w.ui.isRunning() {
|
||||
// If the window is initially maximized, the set size is ignored anyway.
|
||||
w.ui.setInitWindowSizeInDIP(width, height)
|
||||
return
|
||||
}
|
||||
w.ui.t.Call(func() {
|
||||
if w.ui.isWindowMaximized() && runtime.GOOS != "darwin" {
|
||||
return
|
||||
}
|
||||
// TODO: Do not call setWindowSizeInDIP directly here (#1816).
|
||||
// Instead, can we call (*Window).SetSize?
|
||||
w.ui.setWindowSizeInDIP(width, height, w.ui.isFullscreen())
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user