statusline: update status only when necessary

Update statusline only when changed to reduce cpu usage.

commit 2512c0403f ("statusline: implement per-account status") updates
the status irrespective of whether the statusline changed or not. This
can lead to high cpu usage that can be avoided.

Reported-by: Jens Grassel <jens@wegtam.com>
Reported-by: inwit <inwit@sindominio.net>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-03-19 13:30:07 +01:00 committed by Robin Jarry
parent 2512c0403f
commit e49f08e35f
1 changed files with 6 additions and 1 deletions

View File

@ -32,6 +32,7 @@ type AccountView struct {
msglist *MessageList msglist *MessageList
worker *types.Worker worker *types.Worker
state *statusline.State state *statusline.State
update bool
} }
func (acct *AccountView) UiConfig() config.UIConfig { func (acct *AccountView) UiConfig() config.UIConfig {
@ -113,6 +114,7 @@ func (acct *AccountView) SetStatus(setters ...statusline.SetStateFunc) {
for _, fn := range setters { for _, fn := range setters {
fn(acct.state) fn(acct.state)
} }
acct.update = true
} }
func (acct *AccountView) UpdateStatus() { func (acct *AccountView) UpdateStatus() {
@ -158,7 +160,10 @@ func (acct *AccountView) Invalidate() {
} }
func (acct *AccountView) Draw(ctx *ui.Context) { func (acct *AccountView) Draw(ctx *ui.Context) {
if acct.update {
acct.UpdateStatus() acct.UpdateStatus()
acct.update = false
}
acct.grid.Draw(ctx) acct.grid.Draw(ctx)
} }