diff --git a/examples/mascot/main.go b/examples/mascot/main.go index a653aa858..e1b96c661 100644 --- a/examples/mascot/main.go +++ b/examples/mascot/main.go @@ -87,7 +87,6 @@ func (m *mascot) update(screen *ebiten.Image) error { m.count++ sw, sh := ebiten.ScreenSizeInFullscreen() - // TODO: Consider multiple monitors. This requires new APIs (#1114). ebiten.SetWindowPosition(m.x16/16, m.y16/16+sh-height) if m.vx16 == 0 { diff --git a/internal/driver/ui.go b/internal/driver/ui.go index 4c398a5fc..0cfaf5122 100644 --- a/internal/driver/ui.go +++ b/internal/driver/ui.go @@ -42,7 +42,6 @@ type UI interface { IsVsyncEnabled() bool ScreenSizeInFullscreen() (int, int) IsScreenTransparent() bool - MonitorPosition() (int, int) SetCursorMode(mode CursorMode) SetFullscreen(fullscreen bool) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index 68a9e1ea0..3d192b408 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -1043,23 +1043,6 @@ func (u *UserInterface) IsScreenTransparent() bool { return val } -func (u *UserInterface) MonitorPosition() (int, int) { - if !u.isRunning() { - return u.monitorPosition() - } - var mx, my int - _ = u.t.Call(func() error { - mx, my = u.monitorPosition() - return nil - }) - return mx, my -} - -func (u *UserInterface) monitorPosition() (int, int) { - // TODO: toDeviceIndependentPixel might be required. - return u.currentMonitor().GetPos() -} - func (u *UserInterface) Input() driver.Input { return &u.input } diff --git a/internal/uidriver/glfw/window.go b/internal/uidriver/glfw/window.go index d2a0d72f9..20b751240 100644 --- a/internal/uidriver/glfw/window.go +++ b/internal/uidriver/glfw/window.go @@ -185,6 +185,9 @@ func (w *window) Position() (int, int) { } else { wx, wy = w.ui.window.GetPos() } + mx, my := w.ui.currentMonitor().GetPos() + wx -= mx + wy -= my xf := w.ui.toDeviceIndependentPixel(float64(wx)) yf := w.ui.toDeviceIndependentPixel(float64(wy)) x, y = int(xf), int(yf) @@ -199,9 +202,10 @@ func (w *window) SetPosition(x, y int) { return } _ = w.ui.t.Call(func() error { + mx, my := w.ui.currentMonitor().GetPos() xf := w.ui.toDeviceDependentPixel(float64(x)) yf := w.ui.toDeviceDependentPixel(float64(y)) - x, y := adjustWindowPosition(int(xf), int(yf)) + x, y := adjustWindowPosition(mx+int(xf), my+int(yf)) if w.ui.isFullscreen() { w.ui.origPosX, w.ui.origPosY = x, y } else { diff --git a/internal/uidriver/js/ui.go b/internal/uidriver/js/ui.go index 8e4fd551b..27ebba766 100644 --- a/internal/uidriver/js/ui.go +++ b/internal/uidriver/js/ui.go @@ -456,10 +456,6 @@ func (u *UserInterface) IsScreenTransparent() bool { return bodyStyle.Get("backgroundColor").String() == "transparent" } -func (u *UserInterface) MonitorPosition() (int, int) { - return 0, 0 -} - func (u *UserInterface) Input() driver.Input { return &u.input } diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index 4bf996cbe..cc26b9417 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -433,10 +433,6 @@ func (u *UserInterface) IsScreenTransparent() bool { return false } -func (u *UserInterface) MonitorPosition() (int, int) { - return 0, 0 -} - func (u *UserInterface) Input() driver.Input { return &u.input } diff --git a/window.go b/window.go index 1c41b6c66..53ab1df33 100644 --- a/window.go +++ b/window.go @@ -112,6 +112,8 @@ func SetWindowIcon(iconImages []image.Image) { } // WindowPosition returns the window position. +// The origin position is the left-upper corner of the current monitor. +// The unit is device-independent pixels. // // WindowPosition panics if the main loop does not start yet. // @@ -131,6 +133,8 @@ func WindowPosition() (x, y int) { } // SetWindowPosition sets the window position. +// The origin position is the left-upper corner of the current monitor. +// The unit is device-independent pixels. // // SetWindowPosition does nothing on fullscreen mode. // @@ -194,10 +198,9 @@ func fixWindowPosition(width, height int) { } if initWindowPosition.x == invalidPos || initWindowPosition.y == invalidPos { - mx, my := uiDriver().MonitorPosition() sw, sh := uiDriver().ScreenSizeInFullscreen() - x := mx + (sw-width)/2 - y := my + (sh-height)/3 + x := (sw - width) / 2 + y := (sh - height) / 3 w.SetPosition(x, y) } else { w.SetPosition(initWindowPosition.x, initWindowPosition.y)