summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-04-26 00:18:13 +0200
committerRobin Jarry <robin@jarry.cc>2023-04-26 09:05:15 +0200
commitb148b94cfe1f46bd14ecf8e30ab3a4a472ec2b75 (patch)
tree348562bda60adc50a340b1b1289886c189a0ddab
parent8c2a9cf6b90d5fe18fa7e5e110f6460e967ee036 (diff)
downloadaerc-b148b94cfe1f46bd14ecf8e30ab3a4a472ec2b75.tar.gz
aerc-b148b94cfe1f46bd14ecf8e30ab3a4a472ec2b75.zip
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 <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--lib/ui/ui.go9
1 files changed, 8 insertions, 1 deletions
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)
}
}