aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/terminal.go
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 /widgets/terminal.go
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 'widgets/terminal.go')
-rw-r--r--widgets/terminal.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index ca5a5ef2..c3c16db6 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -18,6 +18,7 @@ type Terminal struct {
ctx *ui.Context
destroyed bool
focus bool
+ visible bool
vterm *tcellterm.Terminal
running bool
@@ -29,8 +30,9 @@ type Terminal struct {
func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
term := &Terminal{
- cmd: cmd,
- vterm: tcellterm.New(),
+ cmd: cmd,
+ vterm: tcellterm.New(),
+ visible: true,
}
return term, nil
}
@@ -97,6 +99,10 @@ func (term *Terminal) Draw(ctx *ui.Context) {
term.draw()
}
+func (term *Terminal) Show(visible bool) {
+ term.visible = visible
+}
+
func (term *Terminal) draw() {
term.vterm.Draw()
if term.focus && !term.closed && term.ctx != nil {
@@ -149,7 +155,7 @@ func (term *Terminal) HandleEvent(ev tcell.Event) bool {
}
switch ev := ev.(type) {
case *views.EventWidgetContent:
- if term.focus {
+ if term.visible {
ui.QueueRedraw()
}
return true