ui: Avoid glfw.GetCurrentContext for threading issues

This commit is contained in:
Hajime Hoshi 2018-10-10 01:45:39 +09:00
parent b5344bc994
commit e971f6d41c
4 changed files with 7 additions and 7 deletions

View File

@ -240,7 +240,7 @@ func ScreenSizeInFullscreen() (int, int) {
return nil return nil
}) })
} else { } else {
v = currentMonitor().GetVideoMode() v = currentUI.currentMonitor().GetVideoMode()
} }
return v.Width, v.Height return v.Width, v.Height
} }
@ -501,7 +501,7 @@ func DeviceScaleFactor() float64 {
f := 0.0 f := 0.0
u := currentUI u := currentUI
if !u.isRunning() { if !u.isRunning() {
return devicescale.GetAt(currentMonitor().GetPos()) return devicescale.GetAt(u.currentMonitor().GetPos())
} }
_ = u.runOnMainThread(func() error { _ = u.runOnMainThread(func() error {
@ -813,5 +813,5 @@ func (u *userInterface) currentMonitor() *glfw.Monitor {
return m return m
} }
// Get the monitor which the current window belongs to. This requires OS API. // Get the monitor which the current window belongs to. This requires OS API.
return currentMonitor() return u.currentMonitorImpl()
} }

View File

@ -53,7 +53,7 @@ func adjustWindowPosition(x, y int) (int, int) {
return x, y return x, y
} }
func currentMonitor() *glfw.Monitor { func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
x := C.int(0) x := C.int(0)
y := C.int(0) y := C.int(0)
C.currentMonitorPos(&x, &y) C.currentMonitorPos(&x, &y)

View File

@ -33,9 +33,9 @@ func adjustWindowPosition(x, y int) (int, int) {
return x, y return x, y
} }
func currentMonitor() *glfw.Monitor { func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
// TODO: Return more appropriate display. // TODO: Return more appropriate display.
w := glfw.GetCurrentContext() w := u.window
wx, wy := w.GetPos() wx, wy := w.GetPos()
for _, m := range glfw.GetMonitors() { for _, m := range glfw.GetMonitors() {
mx, my := m.GetPos() mx, my := m.GetPos()

View File

@ -121,7 +121,7 @@ func adjustWindowPosition(x, y int) (int, int) {
return x, y return x, y
} }
func currentMonitor() *glfw.Monitor { func (u *userInterface) currentMonitorImpl() *glfw.Monitor {
w, err := getActiveWindow() w, err := getActiveWindow()
if err != nil { if err != nil {
panic(err) panic(err)