diff options
author | 2016-06-15 09:13:46 +0000 | |
---|---|---|
committer | 2016-06-15 09:13:46 +0000 | |
commit | d0600f3846bc42e2cee86be6e1f89d0684075801 (patch) | |
tree | f095d76e8d6c60aaeb13872467de914f19b9b9b8 | |
parent | Add -F to list-commands. (diff) | |
download | wireguard-openbsd-d0600f3846bc42e2cee86be6e1f89d0684075801.tar.xz wireguard-openbsd-d0600f3846bc42e2cee86be6e1f89d0684075801.zip |
Copy mode needs to keep the original grid intact so it can copy from it
if needed, so it disables reading from the pane. This can be problem
with some programs. So make tmux automatically exit all modes after 180
seconds of inactivity and if there is pending output.
-rw-r--r-- | usr.bin/tmux/tmux.h | 5 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 29 |
2 files changed, 32 insertions, 2 deletions
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 7b1fda71041..569657c6fd3 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.634 2016/06/06 07:28:52 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.635 2016/06/15 09:13:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -823,6 +823,7 @@ struct window_mode { void (*key)(struct window_pane *, struct client *, struct session *, key_code, struct mouse_event *); }; +#define WINDOW_MODE_TIMEOUT 180 /* Structures for choose mode. */ struct window_choose_data { @@ -905,6 +906,8 @@ struct window_pane { const struct window_mode *mode; void *modedata; + struct event modetimer; + time_t modelast; TAILQ_ENTRY(window_pane) entry; RB_ENTRY(window_pane) tree_entry; diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 13bc97bb49d..3ca19e2f27f 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.161 2016/06/06 07:24:31 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.162 2016/06/15 09:13:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -17,6 +17,7 @@ */ #include <sys/types.h> +#include <sys/ioctl.h> #include <errno.h> #include <fcntl.h> @@ -1046,15 +1047,38 @@ window_pane_alternate_off(struct window_pane *wp, struct grid_cell *gc, wp->flags |= PANE_REDRAW; } +static void +window_pane_mode_timer(__unused int fd, __unused short events, void *arg) +{ + struct window_pane *wp = arg; + struct timeval tv = { .tv_sec = 10 }; + int n = 0; + + evtimer_del(&wp->modetimer); + evtimer_add(&wp->modetimer, &tv); + + log_debug("%%%u in mode: last=%ld", wp->id, (long)wp->modelast); + + if (wp->modelast < time(NULL) - WINDOW_MODE_TIMEOUT) { + if (ioctl(wp->fd, FIONREAD, &n) == -1 || n > 0) + window_pane_reset_mode(wp); + } +} + int window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode) { struct screen *s; + struct timeval tv = { .tv_sec = 10 }; if (wp->mode != NULL) return (1); wp->mode = mode; + wp->modelast = time(NULL); + evtimer_set(&wp->modetimer, window_pane_mode_timer, wp); + evtimer_add(&wp->modetimer, &tv); + if ((s = wp->mode->init(wp)) != NULL) wp->screen = s; wp->flags |= (PANE_REDRAW|PANE_CHANGED); @@ -1069,6 +1093,8 @@ window_pane_reset_mode(struct window_pane *wp) if (wp->mode == NULL) return; + evtimer_del(&wp->modetimer); + wp->mode->free(wp); wp->mode = NULL; @@ -1088,6 +1114,7 @@ window_pane_key(struct window_pane *wp, struct client *c, struct session *s, return; if (wp->mode != NULL) { + wp->modelast = time(NULL); if (wp->mode->key != NULL) wp->mode->key(wp, c, s, key, m); return; |