aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-04-11 10:51:47 +0200
committerRobin Jarry <robin@jarry.cc>2023-04-15 17:26:57 +0200
commite641da83471bc3e70b31bfceac21933836a26eac (patch)
treeaca78815ff6ce8b03a4334afcc77823c471e0aab /lib/ui
parent66995d17eea2a45a4e8d88a7739db18c13b91bf7 (diff)
downloadaerc-e641da83471bc3e70b31bfceac21933836a26eac.tar.gz
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 <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/interfaces.go5
-rw-r--r--lib/ui/tab.go8
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/ui/interfaces.go b/lib/ui/interfaces.go
index a28c6c29..8ede22c7 100644
--- a/lib/ui/interfaces.go
+++ b/lib/ui/interfaces.go
@@ -20,6 +20,11 @@ type Closeable interface {
Close()
}
+type Visible interface {
+ // Indicate that this component is visible or not
+ Show(bool)
+}
+
type RootDrawable interface {
Initialize(ui *UI)
}
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index b992a8a2..b62764fb 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -153,9 +153,17 @@ func (tabs *Tabs) selectPriv(index int) bool {
if tabs.curIndex != index {
// only push valid tabs onto the history
if tabs.curIndex < len(tabs.tabs) {
+ prev := tabs.tabs[tabs.curIndex]
+ if vis, ok := prev.Content.(Visible); ok {
+ vis.Show(false)
+ }
tabs.pushHistory(tabs.curIndex)
}
tabs.curIndex = index
+ next := tabs.tabs[tabs.curIndex]
+ if vis, ok := next.Content.(Visible); ok {
+ vis.Show(true)
+ }
Invalidate()
}
return true