diff --git a/internal/input/input_glfw.go b/internal/input/input_glfw.go index ee878916b..347c93c32 100644 --- a/internal/input/input_glfw.go +++ b/internal/input/input_glfw.go @@ -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) { diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 39ba60d35..8eaf0bd34 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -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 }