ui: Refactoring: Remove pollEvents

This commit is contained in:
Hajime Hoshi 2019-03-31 19:51:53 +09:00
parent c21fb4d390
commit 80dcec865d
2 changed files with 6 additions and 8 deletions

View File

@ -103,6 +103,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]driver.MouseButton{
func (i *Input) Update(window *glfw.Window, scale float64) {
i.m.Lock()
defer i.m.Unlock()
if !i.callbacksInitialized {
i.runeBuffer = make([]rune, 0, 1024)
window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {

View File

@ -713,12 +713,6 @@ func (u *userInterface) actualScreenScale() float64 {
return u.getScale() * devicescale.GetAt(u.currentMonitor().GetPos())
}
// pollEvents must be called from the main thread.
func (u *userInterface) pollEvents() {
glfw.PollEvents()
input.Get().Update(u.window, u.getScale()*glfwScale())
}
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
actualScale := 0.0
sizeChanged := false
@ -766,13 +760,16 @@ func (u *userInterface) update(g GraphicsContext) error {
u.updateGraphicsContext(g)
_ = mainthread.Run(func() error {
u.pollEvents()
glfw.PollEvents()
input.Get().Update(u.window, u.getScale()*glfwScale())
defer hooks.ResumeAudio()
for !u.isRunnableInBackground() && u.window.GetAttrib(glfw.Focused) == 0 {
hooks.SuspendAudio()
// Wait for an arbitrary period to avoid busy loop.
time.Sleep(time.Second / 60)
u.pollEvents()
glfw.PollEvents()
if u.window.ShouldClose() {
return nil
}