aboutsummaryrefslogtreecommitdiff
path: root/server-client.c
diff options
context:
space:
mode:
authornicm <nicm>2016-09-28 08:30:44 +0000
committernicm <nicm>2016-09-28 08:30:44 +0000
commitacacb718e5452bfdba4810007d5a10eace1a9fec (patch)
treeafd9330825aebdc0705562f8e781ef98b991c98b /server-client.c
parent69e980602b31732348aaceee045a1901dc982d78 (diff)
downloadrtmux-acacb718e5452bfdba4810007d5a10eace1a9fec.tar.gz
rtmux-acacb718e5452bfdba4810007d5a10eace1a9fec.tar.bz2
rtmux-acacb718e5452bfdba4810007d5a10eace1a9fec.zip
Rate limit TIOCSWINSZ on a timer to avoid programs getting hammered with
SIGWINCH when the size changes rapidly. To help a problem reported by Rui Pinheiro.
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/server-client.c b/server-client.c
index 0c0b2cff..a6ea7bc6 100644
--- a/server-client.c
+++ b/server-client.c
@@ -765,11 +765,13 @@ server_client_loop(void)
}
}
-/* Check if pane should be resized. */
-void
-server_client_check_resize(struct window_pane *wp)
+static void
+server_client_resize_event(__unused int fd, __unused short events, void *data)
{
- struct winsize ws;
+ struct window_pane *wp = data;
+ struct winsize ws;
+
+ evtimer_del(&wp->resize_timer);
if (!(wp->flags & PANE_RESIZE))
return;
@@ -784,6 +786,36 @@ server_client_check_resize(struct window_pane *wp)
wp->flags &= ~PANE_RESIZE;
}
+/* Check if pane should be resized. */
+void
+server_client_check_resize(struct window_pane *wp)
+{
+ struct timeval tv = { .tv_usec = 250000 };
+
+ if (!(wp->flags & PANE_RESIZE))
+ return;
+
+ if (!event_initialized(&wp->resize_timer))
+ evtimer_set(&wp->resize_timer, server_client_resize_event, wp);
+
+ /*
+ * The first resize should happen immediately, so if the timer is not
+ * running, do it now.
+ */
+ if (!evtimer_pending(&wp->resize_timer, NULL))
+ server_client_resize_event(-1, 0, wp);
+
+ /*
+ * If the pane is in the alternate screen, let the timer expire and
+ * resize to give the application a chance to redraw. If not, keep
+ * pushing the timer back.
+ */
+ if (wp->saved_grid != NULL && evtimer_pending(&wp->resize_timer, NULL))
+ return;
+ evtimer_del(&wp->resize_timer);
+ evtimer_add(&wp->resize_timer, &tv);
+}
+
/* Check whether pane should be focused. */
void
server_client_check_focus(struct window_pane *wp)