From 2ef823ccd2d4a693f02c55e8322b6dd835e75947 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 28 Sep 2024 02:45:56 +0900 Subject: [PATCH] internal/ui: remove panic in adjustWindowSize --- internal/ui/ui_darwin.go | 4 ++-- internal/ui/ui_glfw.go | 7 ++++++- internal/ui/ui_linbsd.go | 4 ++-- internal/ui/ui_windows.go | 8 ++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/ui/ui_darwin.go b/internal/ui/ui_darwin.go index c2736e0a1..cce7d41de 100644 --- a/internal/ui/ui_darwin.go +++ b/internal/ui/ui_darwin.go @@ -219,8 +219,8 @@ func dipToGLFWPixel(x float64, scale float64) float64 { return x } -func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) { - return x, y +func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) { + return x, y, nil } var ( diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index bbf035145..131d887de 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -2113,7 +2113,12 @@ func (u *UserInterface) setWindowPositionInDIP(x, y int, monitor *Monitor) error s := monitor.DeviceScaleFactor() xf := dipToGLFWPixel(float64(x), s) yf := dipToGLFWPixel(float64(y), s) - if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor); f { + + x, y, err = u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor) + if err != nil { + return err + } + if f { u.setOrigWindowPos(x, y) } else { if err := u.window.SetPos(x, y); err != nil { diff --git a/internal/ui/ui_linbsd.go b/internal/ui/ui_linbsd.go index c0d77b2b0..c7b54fee3 100644 --- a/internal/ui/ui_linbsd.go +++ b/internal/ui/ui_linbsd.go @@ -131,8 +131,8 @@ func dipToGLFWPixel(x float64, deviceScaleFactor float64) float64 { return x * deviceScaleFactor } -func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) { - return x, y +func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) { + return x, y, nil } func initialMonitorByOS() (*Monitor, error) { diff --git a/internal/ui/ui_windows.go b/internal/ui/ui_windows.go index adadac79e..6eda1b921 100644 --- a/internal/ui/ui_windows.go +++ b/internal/ui/ui_windows.go @@ -110,9 +110,9 @@ func dipToGLFWPixel(x float64, deviceScaleFactor float64) float64 { return x * deviceScaleFactor } -func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) { +func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) { if microsoftgdk.IsXbox() { - return x, y + return x, y, nil } mx := monitor.boundsInGLFWPixels.Min.X @@ -124,12 +124,12 @@ func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, i } t, err := _GetSystemMetrics(_SM_CYCAPTION) if err != nil { - panic(err) + return 0, 0, err } if y < my+int(t) { y = my + int(t) } - return x, y + return x, y, nil } func initialMonitorByOS() (*Monitor, error) {