From a61d32161501bd5758232e7f4745e9b320b65b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sun, 14 Jun 2020 17:52:03 +0200 Subject: [PATCH] expose glfw.WaitEvent using Window.WaitInput --- pixelgl/input.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pixelgl/input.go b/pixelgl/input.go index 541afb1..a0aa8e9 100644 --- a/pixelgl/input.go +++ b/pixelgl/input.go @@ -1,6 +1,8 @@ package pixelgl import ( + "time" + "github.com/faiface/mainthread" "github.com/faiface/pixel" "github.com/go-gl/glfw/v3.3/glfw" @@ -408,7 +410,24 @@ func (w *Window) UpdateInput() { mainthread.Call(func() { glfw.PollEvents() }) + w.doUpdateInput() +} +// WaitInput blocks until an event is received or a timeout. If timeout is 0 +// then it will wait indefinitely +func (w *Window) WaitInput(timeout time.Duration) { + mainthread.Call(func() { + if timeout == 0 { + glfw.WaitEvents() + } else { + glfw.WaitEventsTimeout(timeout.Seconds()) + } + }) + w.doUpdateInput() +} + +// internal input bookkeeping +func (w *Window) doUpdateInput() { w.prevInp = w.currInp w.currInp = w.tempInp