examples/windowsize: Bug fix: Suppress calling SetWindowPosition if the position is not updated

This is a temoprary fix for the issue that the window size unexpectedly
shrunk on Linux.

Updates #1607
Closes #1605
This commit is contained in:
Hajime Hoshi 2021-04-20 20:47:56 +09:00
parent 9c765a5d15
commit 0cf38ce80a

View File

@ -126,6 +126,7 @@ func (g *game) Update() error {
const d = 16 const d = 16
toUpdateWindowSize := false toUpdateWindowSize := false
toUpdateWindowPosition := false
if ebiten.IsKeyPressed(ebiten.KeyShift) { if ebiten.IsKeyPressed(ebiten.KeyShift) {
if inpututil.IsKeyJustPressed(ebiten.KeyUp) { if inpututil.IsKeyJustPressed(ebiten.KeyUp) {
screenHeight += d screenHeight += d
@ -150,15 +151,19 @@ func (g *game) Update() error {
} else { } else {
if inpututil.IsKeyJustPressed(ebiten.KeyUp) { if inpututil.IsKeyJustPressed(ebiten.KeyUp) {
positionY -= d positionY -= d
toUpdateWindowPosition = true
} }
if inpututil.IsKeyJustPressed(ebiten.KeyDown) { if inpututil.IsKeyJustPressed(ebiten.KeyDown) {
positionY += d positionY += d
toUpdateWindowPosition = true
} }
if inpututil.IsKeyJustPressed(ebiten.KeyLeft) { if inpututil.IsKeyJustPressed(ebiten.KeyLeft) {
positionX -= d positionX -= d
toUpdateWindowPosition = true
} }
if inpututil.IsKeyJustPressed(ebiten.KeyRight) { if inpututil.IsKeyJustPressed(ebiten.KeyRight) {
positionX += d positionX += d
toUpdateWindowPosition = true
} }
} }
if inpututil.IsKeyJustPressed(ebiten.KeyS) && !*flagAutoAdjusting { if inpututil.IsKeyJustPressed(ebiten.KeyS) && !*flagAutoAdjusting {
@ -239,7 +244,9 @@ func (g *game) Update() error {
} }
ebiten.SetMaxTPS(tps) ebiten.SetMaxTPS(tps)
ebiten.SetWindowDecorated(decorated) ebiten.SetWindowDecorated(decorated)
ebiten.SetWindowPosition(positionX, positionY) if toUpdateWindowPosition {
ebiten.SetWindowPosition(positionX, positionY)
}
ebiten.SetWindowFloating(floating) ebiten.SetWindowFloating(floating)
ebiten.SetScreenClearedEveryFrame(screenCleared) ebiten.SetScreenClearedEveryFrame(screenCleared)
if maximize && ebiten.IsWindowResizable() { if maximize && ebiten.IsWindowResizable() {