diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-04-18 20:37:50 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-04-18 20:37:50 +0000 |
commit | d1348946a8e1738ff233eb0c1bb8afe03b863228 (patch) | |
tree | 15927c603abed9279fc076c6ca5b58be1abdf889 /usr.bin | |
parent | 50c3abc4838481f94a0898ae39b3616d2f8ac553 (diff) |
On terminals without DECSLRM, when a pane that is less than the full
with of the terminal scrolls, tmux needs to redraw the entire pane. This
results in a large amount of output data which can cause slow terminals
to struggle, particularly when many lines are scrolled together quickly.
This can be reduced by only redrawing when tmux doesn't hold any
buffered data for the terminal. If a redraw is required and data is
buffered, the redraw is deferred until all that data is consumed (it is
checked after every event loop, a timer is used to ensure this happens
at some point). While a redraw is pending, no additional data will be
written to the terminal.
The redraw still happens, now it is just pushed back if it is possible
it would just add more data on top of a terminal that is already
behind. This both gives the terminal a chance to catch up, and allows
tmux to process more scrolling (that would require additional redraws)
in the meantime.
Helps with a problem reported by Greg Hurrell.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/server-client.c | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 27979e5778f..ef3fc1a6d28 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.217 2017/04/17 06:40:32 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.218 2017/04/18 20:37:49 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1201,6 +1201,14 @@ server_client_check_exit(struct client *c) c->flags &= ~CLIENT_EXIT; } +/* Redraw timer callback. */ +static void +server_client_redraw_timer(__unused int fd, __unused short events, + __unused void* data) +{ + log_debug("redraw timer fired"); +} + /* Check for client redraws. */ static void server_client_check_redraw(struct client *c) @@ -1208,11 +1216,53 @@ server_client_check_redraw(struct client *c) struct session *s = c->session; struct tty *tty = &c->tty; struct window_pane *wp; - int flags, masked; + int needed, flags, masked; + struct timeval tv = { .tv_usec = 1000 }; + static struct event ev; + size_t left; if (c->flags & (CLIENT_CONTROL|CLIENT_SUSPENDED)) return; + /* + * If there is outstanding data, defer the redraw until it has been + * consumed. We can just add a timer to get out of the event loop and + * end up back here. + */ + needed = 0; + if (c->flags & CLIENT_REDRAW) + needed = 1; + else { + TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry) { + if (wp->flags & PANE_REDRAW) { + needed = 1; + break; + } + } + } + if (needed) { + left = EVBUFFER_LENGTH(tty->out); + if (left != 0) { + log_debug("%s: redraw deferred (%zu left)", c->name, left); + if (evtimer_initialized(&ev) && evtimer_pending(&ev, NULL)) + return; + log_debug("redraw timer started"); + evtimer_set(&ev, server_client_redraw_timer, NULL); + evtimer_add(&ev, &tv); + + /* + * We may have got here for a single pane redraw, but + * force a full redraw next time in case other panes + * have been updated. + */ + c->flags |= CLIENT_REDRAW; + return; + } + if (evtimer_initialized(&ev)) + evtimer_del(&ev); + log_debug("%s: redraw needed", c->name); + } + if (c->flags & (CLIENT_REDRAW|CLIENT_STATUS)) { if (options_get_number(s->options, "set-titles")) server_client_set_title(c); |