From b148b94cfe1f46bd14ecf8e30ab3a4a472ec2b75 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 26 Apr 2023 00:18:13 +0200 Subject: ui: avoid duplicate queued redraws No need to queue multiple nil messages to force multiple redraws. Only one is required. When the screen is redrawn, clear the queued redraw flag. Signed-off-by: Robin Jarry Acked-by: Tim Culverhouse --- lib/ui/ui.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/ui') diff --git a/lib/ui/ui.go b/lib/ui/ui.go index 05a44e4a..4e3b9987 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -10,6 +10,8 @@ import ( const ( DIRTY int32 = iota NOT_DIRTY + REDRAW_PENDING + REDRAW_DONE ) var MsgChannel = make(chan AercMsg, 50) @@ -18,11 +20,15 @@ type AercFuncMsg struct { Func func() } +var redraw int32 = REDRAW_DONE + // QueueRedraw marks the UI as invalid and sends a nil message into the // MsgChannel. Nothing will handle this message, but a redraw will occur func QueueRedraw() { Invalidate() - MsgChannel <- nil + if atomic.SwapInt32(&redraw, REDRAW_PENDING) == REDRAW_DONE { + MsgChannel <- nil + } } // QueueFunc queues a function to be called in the main goroutine. This can be @@ -114,6 +120,7 @@ func (state *UI) Render() { state.popover.Draw(state.ctx) } state.screen.Show() + atomic.StoreInt32(&redraw, REDRAW_DONE) } } -- cgit