=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/server-client.c,v retrieving revision 1.81 retrieving revision 1.82 diff -c -r1.81 -r1.82 *** src/usr.bin/tmux/server-client.c 2012/10/26 14:35:42 1.81 --- src/usr.bin/tmux/server-client.c 2013/01/15 22:55:29 1.82 *************** *** 1,4 **** ! /* $OpenBSD: server-client.c,v 1.81 2012/10/26 14:35:42 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: server-client.c,v 1.82 2013/01/15 22:55:29 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott *************** *** 34,39 **** --- 34,40 ---- 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,330 **** --- 326,347 ---- 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,340 **** struct window_pane *wp; struct timeval tv; struct key_binding *bd; ! int xtimeout, isprefix; /* Check the client is good to accept input. */ if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0) --- 351,357 ---- struct window_pane *wp; struct timeval tv; struct key_binding *bd; ! int xtimeout, isprefix, ispaste; /* Check the client is good to accept input. */ if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0) *************** *** 346,351 **** --- 363,371 ---- /* 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,406 **** } /* Is this a prefix key? */ ! if (key == options_get_number(&c->session->options, "prefix")) isprefix = 1; ! else if (key == options_get_number(&c->session->options, "prefix2")) isprefix = 1; else isprefix = 0; /* No previous prefix key. */ if (!(c->flags & CLIENT_PREFIX)) { ! 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; } --- 402,432 ---- } /* Is this a prefix key? */ ! if (key == options_get_number(&s->options, "prefix")) isprefix = 1; ! 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) { c->flags |= CLIENT_PREFIX; ! 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,419 **** if (isprefix) c->flags |= CLIENT_PREFIX; else if (!(c->flags & CLIENT_READONLY)) ! window_pane_key(wp, c->session, key); } return; } --- 439,445 ---- if (isprefix) c->flags |= CLIENT_PREFIX; else if (!(c->flags & CLIENT_READONLY)) ! window_pane_key(wp, s, key); } return; } *************** *** 424,435 **** if (isprefix) c->flags |= CLIENT_PREFIX; else if (!(c->flags & CLIENT_READONLY)) ! window_pane_key(wp, c->session, key); return; } /* If this key can repeat, reset the repeat flags and timer. */ ! xtimeout = options_get_number(&c->session->options, "repeat-time"); if (xtimeout != 0 && bd->can_repeat) { c->flags |= CLIENT_PREFIX|CLIENT_REPEAT; --- 450,461 ---- if (isprefix) c->flags |= CLIENT_PREFIX; else if (!(c->flags & CLIENT_READONLY)) ! window_pane_key(wp, s, key); return; } /* If this key can repeat, reset the repeat flags and timer. */ ! xtimeout = options_get_number(&s->options, "repeat-time"); if (xtimeout != 0 && bd->can_repeat) { c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;