From e641da83471bc3e70b31bfceac21933836a26eac Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 11 Apr 2023 10:51:47 +0200 Subject: term: ignore redraw events when not visible Another attempt at fixing the high CPU usage when terminal tabs are running interactive tui applications and the message list tab is selected. There are cases where a terminal widget can be visible but not focused (composer, message viewer, attachment selector, etc.). Define a new Visible interface with a single Show() method. Call that method when changing tabs to make sure that terminal widget content events only trigger redraws when they are visible. Fixes: 382aea4a9426 ("terminal: avoid high cpu usage when not focused") Signed-off-by: Robin Jarry Tested-by: Koni Marti --- widgets/msgviewer.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'widgets/msgviewer.go') diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index f38b186a..684c99cb 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -406,6 +406,12 @@ func (ps *PartSwitcher) Focus(focus bool) { } } +func (ps *PartSwitcher) Show(visible bool) { + if ps.parts[ps.selected].term != nil { + ps.parts[ps.selected].term.Show(visible) + } +} + func (ps *PartSwitcher) Event(event tcell.Event) bool { return ps.parts[ps.selected].Event(event) } @@ -505,6 +511,10 @@ func (mv *MessageViewer) Focus(focus bool) { mv.switcher.Focus(focus) } +func (mv *MessageViewer) Show(visible bool) { + mv.switcher.Show(visible) +} + type PartViewer struct { acctConfig *config.AccountConfig err error -- cgit