summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-03-20 11:01:01 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-03-20 11:01:01 +0000
commit6cc19c0e25db197e4936c72bccee94fe437fd774 (patch)
tree3bc3b8a5f842c010724d87cf9f042c1814e37f59 /usr.bin/tmux/window.c
parentc99c9ef7592d38921c978efcf49a95e63665b991 (diff)
Add a simple form of output rate limiting by counting the number of
certain C0 sequences (linefeeds, backspaces, carriage returns) and if it exceeds a threshold (current default 50/millisecond), start to redraw the pane every 100 milliseconds instead of making each change as it comes. Two configuration options - c0-change-trigger and c0-change-interval. This makes tmux much more responsive under very fast output (for example yes(1) or accidentally cat'ing a large file) but may not be perfect on all terminals and connections - feedback very welcome, particularly where this change has a negative rather than positive effect (making it off by default is a possibility). After much experimentation based originally on a request Robin Lee Powell (which ended with a completely different solution), this idea from discussion with Ailin Nemui.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r--usr.bin/tmux/window.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index d3748847556..de809b7ae14 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.74 2012/03/17 22:35:09 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.75 2012/03/20 11:01:00 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -61,6 +61,7 @@ struct window_pane_tree all_window_panes;
u_int next_window_pane_id;
u_int next_window_id;
+void window_pane_timer_callback(int, short, void *);
void window_pane_read_callback(struct bufferevent *, void *);
void window_pane_error_callback(struct bufferevent *, short, void *);
@@ -648,6 +649,8 @@ window_pane_destroy(struct window_pane *wp)
{
window_pane_reset_mode(wp);
+ event_del(&wp->changes_timer);
+
if (wp->fd != -1) {
bufferevent_free(wp->event);
close(wp->fd);
@@ -764,6 +767,43 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
return (0);
}
+void
+window_pane_timer_start(struct window_pane *wp)
+{
+ struct timeval tv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1000;
+
+ evtimer_del(&wp->changes_timer);
+ evtimer_set(&wp->changes_timer, window_pane_timer_callback, wp);
+ evtimer_add(&wp->changes_timer, &tv);
+}
+
+void
+window_pane_timer_callback(unused int fd, unused short events, void *data)
+{
+ struct window_pane *wp = data;
+ struct window *w = wp->window;
+ u_int interval, trigger;
+
+ interval = options_get_number(&w->options, "c0-change-interval");
+ trigger = options_get_number(&w->options, "c0-change-trigger");
+
+ if (wp->changes_redraw++ == interval) {
+ wp->flags |= PANE_REDRAW;
+ wp->changes_redraw = 0;
+
+ }
+
+ if (trigger == 0 || wp->changes < trigger) {
+ wp->flags |= PANE_REDRAW;
+ wp->flags &= ~PANE_DROP;
+ } else
+ window_pane_timer_start(wp);
+ wp->changes = 0;
+}
+
/* ARGSUSED */
void
window_pane_read_callback(unused struct bufferevent *bufev, void *data)