summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-08-28 07:34:33 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-08-28 07:34:33 +0000
commit3d2f1a954a683951c2ff674d0d800f9791f646cf (patch)
treebbaa2d8b3aa832318303170590747272a256a407 /usr.bin/tmux
parent9e8391c6e299b23987dcc997a87880bb90761568 (diff)
The resize event was never deciding to actually resize the pane if there
was output in the pane faster than the timer would fire, so change how it works to only defer the timer again if the pane was actually resized within the last timer period. Reported by James Tai in GitHub issue 1880.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/server-client.c77
-rw-r--r--usr.bin/tmux/tmux.h3
-rw-r--r--usr.bin/tmux/window.c4
3 files changed, 49 insertions, 35 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 39591ddb470..253fc028801 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.293 2019/07/17 17:46:51 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.294 2019/08/28 07:34:32 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -44,6 +44,7 @@ static void server_client_set_title(struct client *);
static void server_client_reset_state(struct client *);
static int server_client_assume_paste(struct session *);
static void server_client_clear_overlay(struct client *);
+static void server_client_resize_event(int, short, void *);
static void server_client_dispatch(struct imsg *, void *);
static void server_client_dispatch_command(struct client *, struct imsg *);
@@ -1319,19 +1320,11 @@ server_client_resize_force(struct window_pane *wp)
return (1);
}
-/* Resize timer event. */
+/* Resize a pane. */
static void
-server_client_resize_event(__unused int fd, __unused short events, void *data)
+server_client_resize_pane(struct window_pane *wp)
{
- struct window_pane *wp = data;
- struct winsize ws;
-
- evtimer_del(&wp->resize_timer);
-
- if (!(wp->flags & PANE_RESIZE))
- return;
- if (server_client_resize_force(wp))
- return;
+ struct winsize ws;
memset(&ws, 0, sizeof ws);
ws.ws_col = wp->sx;
@@ -1346,35 +1339,55 @@ server_client_resize_event(__unused int fd, __unused short events, void *data)
wp->osy = wp->sy;
}
+/* Start the resize timer. */
+static void
+server_client_start_resize_timer(struct window_pane *wp)
+{
+ struct timeval tv = { .tv_usec = 250000 };
+
+ if (!evtimer_pending(&wp->resize_timer, NULL))
+ evtimer_add(&wp->resize_timer, &tv);
+}
+
+/* Resize timer event. */
+static void
+server_client_resize_event(__unused int fd, __unused short events, void *data)
+{
+ struct window_pane *wp = data;
+
+ evtimer_del(&wp->resize_timer);
+
+ if (~wp->flags & PANE_RESIZE)
+ return;
+ log_debug("%s: %%%u timer fired (was%s resized)", __func__, wp->id,
+ (wp->flags & PANE_RESIZED) ? "" : " not");
+
+ if (wp->saved_grid == NULL && (wp->flags & PANE_RESIZED)) {
+ log_debug("%s: %%%u deferring timer", __func__, wp->id);
+ server_client_start_resize_timer(wp);
+ } else if (!server_client_resize_force(wp)) {
+ log_debug("%s: %%%u resizing pane", __func__, wp->id);
+ server_client_resize_pane(wp);
+ }
+ wp->flags &= ~PANE_RESIZED;
+}
+
/* Check if pane should be resized. */
static void
server_client_check_resize(struct window_pane *wp)
{
- struct timeval tv = { .tv_usec = 250000 };
-
- if (!(wp->flags & PANE_RESIZE))
+ if (~wp->flags & PANE_RESIZE)
return;
- log_debug("%s: %%%u resize to %u,%u", __func__, wp->id, wp->sx, wp->sy);
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);
+ if (!evtimer_pending(&wp->resize_timer, NULL)) {
+ log_debug("%s: %%%u starting timer", __func__, wp->id);
+ server_client_resize_pane(wp);
+ server_client_start_resize_timer(wp);
+ } else
+ log_debug("%s: %%%u timer running", __func__, wp->id);
}
/* Check whether pane should be focused. */
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 0d7efb3392d..5f479ff5862 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.925 2019/08/16 11:49:12 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.926 2019/08/28 07:34:32 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -843,6 +843,7 @@ struct window_pane {
#define PANE_STATUSDRAWN 0x400
#define PANE_EMPTY 0x800
#define PANE_STYLECHANGED 0x1000
+#define PANE_RESIZED 0x2000
int argc;
char **argv;
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index d32f96489cd..3449d0378ae 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.241 2019/08/14 09:58:31 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.242 2019/08/28 07:34:32 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -953,7 +953,7 @@ window_pane_resize(struct window_pane *wp, u_int sx, u_int sy)
if (wme != NULL && wme->mode->resize != NULL)
wme->mode->resize(wme, sx, sy);
- wp->flags |= PANE_RESIZE;
+ wp->flags |= (PANE_RESIZE|PANE_RESIZED);
}
/*