mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-25 17:30:09 +01:00
internal/ui: bug fix: replace initWindowMonitor usages with initMonitor
There were two similar member variables internalWindowMonitor and initMonitor, and when SetMonitor is called, probably there were some inconsitency between them. This change fixes the issue by not using initWindowMonitor. Closes #2779
This commit is contained in:
parent
67b3bc14da
commit
e0cd031aea
@ -87,7 +87,6 @@ type userInterfaceImpl struct {
|
|||||||
initFullscreen bool
|
initFullscreen bool
|
||||||
initCursorMode CursorMode
|
initCursorMode CursorMode
|
||||||
initWindowDecorated bool
|
initWindowDecorated bool
|
||||||
initWindowMonitor int
|
|
||||||
initWindowPositionXInDIP int
|
initWindowPositionXInDIP int
|
||||||
initWindowPositionYInDIP int
|
initWindowPositionYInDIP int
|
||||||
initWindowWidthInDIP int
|
initWindowWidthInDIP int
|
||||||
@ -141,7 +140,6 @@ func init() {
|
|||||||
maxWindowHeightInDIP: glfw.DontCare,
|
maxWindowHeightInDIP: glfw.DontCare,
|
||||||
initCursorMode: CursorModeVisible,
|
initCursorMode: CursorModeVisible,
|
||||||
initWindowDecorated: true,
|
initWindowDecorated: true,
|
||||||
initWindowMonitor: glfw.DontCare,
|
|
||||||
initWindowPositionXInDIP: invalidPos,
|
initWindowPositionXInDIP: invalidPos,
|
||||||
initWindowPositionYInDIP: invalidPos,
|
initWindowPositionYInDIP: invalidPos,
|
||||||
initWindowWidthInDIP: 640,
|
initWindowWidthInDIP: 640,
|
||||||
@ -207,6 +205,9 @@ func initialize() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitMonitor(m *glfw.Monitor) {
|
func (u *userInterfaceImpl) setInitMonitor(m *glfw.Monitor) {
|
||||||
|
u.m.Lock()
|
||||||
|
defer u.m.Unlock()
|
||||||
|
|
||||||
u.initMonitor = m
|
u.initMonitor = m
|
||||||
u.initDeviceScaleFactor = u.deviceScaleFactor(m)
|
u.initDeviceScaleFactor = u.deviceScaleFactor(m)
|
||||||
// GetVideoMode must be called from the main thread, then call this here and record
|
// GetVideoMode must be called from the main thread, then call this here and record
|
||||||
@ -426,24 +427,6 @@ func (u *userInterfaceImpl) setIconImages(iconImages []image.Image) {
|
|||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitWindowMonitor() int {
|
|
||||||
u.m.RLock()
|
|
||||||
v := u.initWindowMonitor
|
|
||||||
u.m.RUnlock()
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowMonitor(monitor int) {
|
|
||||||
if microsoftgdk.IsXbox() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
u.m.Lock()
|
|
||||||
defer u.m.Unlock()
|
|
||||||
|
|
||||||
u.initWindowMonitor = monitor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
|
func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
@ -797,7 +780,7 @@ func init() {
|
|||||||
// createWindow must be called from the main thread.
|
// createWindow must be called from the main thread.
|
||||||
//
|
//
|
||||||
// createWindow does not set the position or size so far.
|
// createWindow does not set the position or size so far.
|
||||||
func (u *userInterfaceImpl) createWindow(width, height int, monitor int) error {
|
func (u *userInterfaceImpl) createWindow(width, height int, monitor *glfw.Monitor) error {
|
||||||
if u.window != nil {
|
if u.window != nil {
|
||||||
panic("ui: u.window must not exist at createWindow")
|
panic("ui: u.window must not exist at createWindow")
|
||||||
}
|
}
|
||||||
@ -809,12 +792,10 @@ func (u *userInterfaceImpl) createWindow(width, height int, monitor int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set our target monitor if provided. This is required to prevent an initial window flash on the default monitor.
|
// Set our target monitor if provided. This is required to prevent an initial window flash on the default monitor.
|
||||||
if monitor != glfw.DontCare {
|
x, y := monitor.GetPos()
|
||||||
m := theMonitors.monitorFromID(monitor)
|
px, py := InitialWindowPosition(monitor.GetVideoMode().Width, monitor.GetVideoMode().Height, width, height)
|
||||||
x, y := m.m.GetPos()
|
|
||||||
px, py := InitialWindowPosition(m.m.GetVideoMode().Width, m.m.GetVideoMode().Height, width, height)
|
|
||||||
window.SetPos(x+px, y+py)
|
window.SetPos(x+px, y+py)
|
||||||
}
|
|
||||||
initializeWindowAfterCreation(window)
|
initializeWindowAfterCreation(window)
|
||||||
|
|
||||||
u.window = window
|
u.window = window
|
||||||
@ -1008,23 +989,16 @@ func (u *userInterfaceImpl) initOnMainThread(options *RunOptions) error {
|
|||||||
glfw.WindowHint(glfw.Visible, glfw.True)
|
glfw.WindowHint(glfw.Visible, glfw.True)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get our target monitor.
|
|
||||||
monitor := u.getInitWindowMonitor()
|
|
||||||
|
|
||||||
if monitor != glfw.DontCare {
|
|
||||||
u.setInitMonitor(theMonitors.monitorFromID(monitor).m)
|
|
||||||
}
|
|
||||||
|
|
||||||
ww, wh := u.getInitWindowSizeInDIP()
|
ww, wh := u.getInitWindowSizeInDIP()
|
||||||
initW := int(u.dipToGLFWPixel(float64(ww), u.initMonitor))
|
initW := int(u.dipToGLFWPixel(float64(ww), u.initMonitor))
|
||||||
initH := int(u.dipToGLFWPixel(float64(wh), u.initMonitor))
|
initH := int(u.dipToGLFWPixel(float64(wh), u.initMonitor))
|
||||||
if err := u.createWindow(initW, initH, monitor); err != nil {
|
if err := u.createWindow(initW, initH, u.initMonitor); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The position must be set before the size is set (#1982).
|
// The position must be set before the size is set (#1982).
|
||||||
// setWindowSize refers the current monitor's device scale.
|
// setWindowSize refers the current monitor's device scale.
|
||||||
// TODO: currentMonitor is very hard to use correctly. Refactor this.
|
// TODO: The window position is already set at createWindow. Unify the logic.
|
||||||
wx, wy := u.getInitWindowPositionInDIP()
|
wx, wy := u.getInitWindowPositionInDIP()
|
||||||
// Force to put the window in the initial monitor (#1575).
|
// Force to put the window in the initial monitor (#1575).
|
||||||
if wx < 0 {
|
if wx < 0 {
|
||||||
|
@ -234,7 +234,7 @@ func (w *glfwWindow) SetMonitor(monitor *Monitor) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !w.ui.isRunning() {
|
if !w.ui.isRunning() {
|
||||||
w.ui.setInitWindowMonitor(monitor.id)
|
w.ui.setInitMonitor(monitor.m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.ui.mainThread.Call(func() {
|
w.ui.mainThread.Call(func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user