From 56dbaf326a927adb9c770e6a6debd90e656f6a56 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 16 May 2020 10:39:44 +0200 Subject: [PATCH] app: move frame waiting code out of Window.run to a separate method Signed-off-by: Elias Naur --- app/window.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/window.go b/app/window.go index 4af06280..4e1a98e2 100644 --- a/app/window.go +++ b/app/window.go @@ -214,6 +214,21 @@ func (w *Window) destroyGPU() { } } +// waitFrame waits for the client to either call FrameEvent.Frame +// or to continue event handling. It returns whether the client +// called Frame or not. +func (w *Window) waitFrame() (*op.Ops, bool) { + select { + case frame := <-w.frames: + // The client called FrameEvent.Frame. + return frame, true + case w.out <- ackEvent: + // The client ignored FrameEvent and continued processing + // events. + return nil, false + } +} + func (w *Window) run(opts *window.Options) { defer close(w.in) defer close(w.out) @@ -271,16 +286,7 @@ func (w *Window) run(opts *window.Options) { w.loop.Refresh() } } - var frame *op.Ops - // Wait for either a frame or an ack event to go - // through, which means that the client didn't give us - // a frame. - gotFrame := false - select { - case frame = <-w.frames: - gotFrame = true - case w.out <- ackEvent: - } + frame, gotFrame := w.waitFrame() var err error for { if w.loop != nil {