diff --git a/apps/gophers/main.go b/apps/gophers/main.go index 3f273df6..dd325d87 100644 --- a/apps/gophers/main.go +++ b/apps/gophers/main.go @@ -200,7 +200,6 @@ func (a *App) run() error { a.pqueue.Frame(root) a.faces.Frame() } - a.w.Ack() } } return a.w.Err() diff --git a/apps/hello/hello.go b/apps/hello/hello.go index 7ba01f6d..35f35058 100644 --- a/apps/hello/hello.go +++ b/apps/hello/hello.go @@ -52,7 +52,6 @@ func init() { w.Draw(root) faces.Frame() } - w.Ack() } if w.Err() != nil { log.Fatal(err) diff --git a/ui/app/window.go b/ui/app/window.go index 535cd532..f893ca9b 100644 --- a/ui/app/window.go +++ b/ui/app/window.go @@ -32,7 +32,6 @@ type Window struct { err error events chan Event - acks chan struct{} mu sync.Mutex stage Stage @@ -55,11 +54,12 @@ var _ interface { setTextInput(s key.TextInputState) } = (*window)(nil) +var ackEvent Event + func newWindow(nw *window) *Window { w := &Window{ driver: nw, events: make(chan Event), - acks: make(chan struct{}), stage: StageInvisible, } return w @@ -69,30 +69,6 @@ func (w *Window) Events() <-chan Event { return w.events } -func (w *Window) Ack() { - w.mu.Lock() - st := w.stage - needAck := w.skipAcks == 0 - if !needAck { - w.skipAcks-- - } - sync := w.syncGPU - w.syncGPU = false - w.mu.Unlock() - if w.gpu != nil { - switch { - case st < StageVisible: - w.gpu.Release() - w.gpu = nil - case sync: - w.gpu.Refresh() - } - } - if needAck { - w.acks <- struct{}{} - } -} - func (w *Window) Timings() string { return w.timings } @@ -258,7 +234,22 @@ func (w *Window) event(e Event) { w.updateAnimation() w.events <- e if needAck { - <-w.acks + // Send a dummy event; when it gets through we + // know the application has processed the actual event. + w.events <- ackEvent + } + if w.gpu != nil { + w.mu.Lock() + sync := w.syncGPU + w.syncGPU = false + w.mu.Unlock() + switch { + case stage < StageVisible: + w.gpu.Release() + w.gpu = nil + case sync: + w.gpu.Refresh() + } } if stage == StageDead { close(w.events)