summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2013-01-15 22:55:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2013-01-15 22:55:30 +0000
commit4d2f391f1c4876d63c3abe30c855b8f431a82b96 (patch)
tree2285d0cfdc5915147b5174f6159d68391c3051e5 /usr.bin
parenta3dd15112e6e0a672607f7ab4b9234131de6bac4 (diff)
If timing between keys is less than (by default) 1 millisecond, assume
the text is being pasted. assume-paste-time option changes the value (0 disables). Based on a diff from Marcin Kulik.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/options-table.c9
-rw-r--r--usr.bin/tmux/server-client.c56
-rw-r--r--usr.bin/tmux/tmux.111
-rw-r--r--usr.bin/tmux/tmux.h4
4 files changed, 60 insertions, 20 deletions
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c
index f69dda07a06..f482b207e2f 100644
--- a/usr.bin/tmux/options-table.c
+++ b/usr.bin/tmux/options-table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options-table.c,v 1.30 2012/11/27 13:52:23 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.31 2013/01/15 22:55:29 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -91,6 +91,13 @@ const struct options_table_entry server_options_table[] = {
/* Session options. */
const struct options_table_entry session_options_table[] = {
+ { .name = "assume-paste-time",
+ .type = OPTIONS_TABLE_NUMBER,
+ .minimum = 0,
+ .maximum = INT_MAX,
+ .default_num = 1,
+ },
+
{ .name = "base-index",
.type = OPTIONS_TABLE_NUMBER,
.minimum = 0,
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 701981c878b..d8eba844d74 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.81 2012/10/26 14:35:42 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.82 2013/01/15 22:55:29 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,7 @@ void server_client_check_exit(struct client *);
void server_client_check_redraw(struct client *);
void server_client_set_title(struct client *);
void server_client_reset_state(struct client *);
+int server_client_assume_paste(struct session *);
int server_client_msg_dispatch(struct client *);
void server_client_msg_command(struct client *, struct msg_command_data *);
@@ -325,6 +326,22 @@ server_client_check_mouse(struct client *c, struct window_pane *wp)
window_pane_mouse(wp, c->session, m);
}
+/* Is this fast enough to probably be a paste? */
+int
+server_client_assume_paste(struct session *s)
+{
+ struct timeval tv;
+ u_int t;
+
+ if ((t = options_get_number(&s->options, "assume-paste-time")) == 0)
+ return 0;
+
+ timersub(&s->activity_time, &s->last_activity_time, &tv);
+ if (tv.tv_sec == 0 && tv.tv_usec < t * 1000)
+ return 1;
+ return 0;
+}
+
/* Handle data key input from client. */
void
server_client_handle_key(struct client *c, int key)
@@ -334,7 +351,7 @@ server_client_handle_key(struct client *c, int key)
struct window_pane *wp;
struct timeval tv;
struct key_binding *bd;
- int xtimeout, isprefix;
+ int xtimeout, isprefix, ispaste;
/* Check the client is good to accept input. */
if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
@@ -346,6 +363,9 @@ server_client_handle_key(struct client *c, int key)
/* Update the activity timer. */
if (gettimeofday(&c->activity_time, NULL) != 0)
fatal("gettimeofday failed");
+
+ memcpy(&s->last_activity_time, &s->activity_time,
+ sizeof s->last_activity_time);
memcpy(&s->activity_time, &c->activity_time, sizeof s->activity_time);
w = c->session->curw->window;
@@ -382,25 +402,31 @@ server_client_handle_key(struct client *c, int key)
}
/* Is this a prefix key? */
- if (key == options_get_number(&c->session->options, "prefix"))
+ if (key == options_get_number(&s->options, "prefix"))
isprefix = 1;
- else if (key == options_get_number(&c->session->options, "prefix2"))
+ else if (key == options_get_number(&s->options, "prefix2"))
isprefix = 1;
else
isprefix = 0;
+ /* Treat prefix as a regular key when pasting is detected. */
+ ispaste = server_client_assume_paste(s);
+ if (ispaste)
+ isprefix = 0;
+
/* No previous prefix key. */
if (!(c->flags & CLIENT_PREFIX)) {
- if (isprefix)
+ if (isprefix) {
c->flags |= CLIENT_PREFIX;
- else {
- /* Try as a non-prefix key binding. */
- if ((bd = key_bindings_lookup(key)) == NULL) {
- if (!(c->flags & CLIENT_READONLY))
- window_pane_key(wp, c->session, key);
- } else
- key_bindings_dispatch(bd, c);
+ return;
}
+
+ /* Try as a non-prefix key binding. */
+ if (ispaste || (bd = key_bindings_lookup(key)) == NULL) {
+ if (!(c->flags & CLIENT_READONLY))
+ window_pane_key(wp, s, key);
+ } else
+ key_bindings_dispatch(bd, c);
return;
}
@@ -413,7 +439,7 @@ server_client_handle_key(struct client *c, int key)
if (isprefix)
c->flags |= CLIENT_PREFIX;
else if (!(c->flags & CLIENT_READONLY))
- window_pane_key(wp, c->session, key);
+ window_pane_key(wp, s, key);
}
return;
}
@@ -424,12 +450,12 @@ server_client_handle_key(struct client *c, int key)
if (isprefix)
c->flags |= CLIENT_PREFIX;
else if (!(c->flags & CLIENT_READONLY))
- window_pane_key(wp, c->session, key);
+ window_pane_key(wp, s, key);
return;
}
/* If this key can repeat, reset the repeat flags and timer. */
- xtimeout = options_get_number(&c->session->options, "repeat-time");
+ xtimeout = options_get_number(&s->options, "repeat-time");
if (xtimeout != 0 && bd->can_repeat) {
c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 23235ca8bbe..072e9ec4a3b 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.311 2012/12/24 12:38:57 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.312 2013/01/15 22:55:29 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 24 2012 $
+.Dd $Mdocdate: January 15 2013 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -2044,6 +2044,13 @@ interactive menu when required.
.Pp
Available session options are:
.Bl -tag -width Ds
+.It Ic assume-paste-time Ar milliseconds
+If keys are entered faster than one in
+.Ar milliseconds ,
+they are assumed to have been pasted rather than typed and
+.Nm
+key bindings are not processed.
+The default is one millisecond and zero disables.
.It Ic base-index Ar index
Set the base index from which an unused index should be searched when a new
window is created.
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 6b6d789fecd..142c90ce71e 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.369 2012/12/24 12:33:05 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.370 2013/01/15 22:55:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1095,6 +1095,7 @@ struct session {
struct timeval creation_time;
struct timeval activity_time;
+ struct timeval last_activity_time;
u_int sx;
u_int sy;
@@ -1707,7 +1708,6 @@ char *paste_print(struct paste_buffer *, size_t);
void paste_send_pane(struct paste_buffer *, struct window_pane *,
const char *, int);
-
/* clock.c */
extern const char clock_table[14][5][5];
void clock_draw(struct screen_write_ctx *, int, int);