From 4db5c2899f2b5c14d6bf72b39c4f71348ceabdd4 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 17 Aug 2013 16:06:40 +0000 Subject: [PATCH] Make calling term_nopaste() a cross-platform feature. It was one of those things that went in ages ago on Windows and never got replicated in the Unix front end. And it needn't be: ldisc.c is a perfect place to put it, since it knows which of the data it's sending is based on a keystroke and which is automatically generated, and it also has access to the terminal context. So now a keypress can interrupt a runaway paste on all platforms. [originally from svn r10025] --- Recipe | 4 ++-- ldisc.c | 12 ++++++++++++ noterm.c | 11 +++++++++++ windows/window.c | 15 --------------- 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 noterm.c diff --git a/Recipe b/Recipe index dee4da8f..ca79f1fc 100644 --- a/Recipe +++ b/Recipe @@ -343,7 +343,7 @@ U_BE_NOSSH = be_nos_s uxser nocproxy putty : [G] GUITERM NONSSH WINSSH W_BE_ALL WINMISC winx11 putty.res LIBS puttytel : [G] GUITERM NONSSH W_BE_NOSSH WINMISC puttytel.res nogss LIBS plink : [C] winplink wincons NONSSH WINSSH W_BE_ALL logging WINMISC - + winx11 plink.res winnojmp LIBS + + winx11 plink.res winnojmp noterm LIBS pscp : [C] pscp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC + pscp.res winnojmp LIBS psftp : [C] psftp winsftp wincons WINSSH BE_SSH SFTP wildcard WINMISC @@ -369,7 +369,7 @@ puttytel : [X] GTKTERM uxmisc misc ldisc settings uxsel U_BE_NOSSH + nogss plink : [U] uxplink uxcons NONSSH UXSSH U_BE_ALL logging UXMISC uxsignal - + ux_x11 + + ux_x11 noterm puttygen : [U] cmdgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version + sshrand uxnoise sshsha misc sshrsa sshdss uxcons uxstore uxmisc diff --git a/ldisc.c b/ldisc.c index efbb8714..8f653a18 100644 --- a/ldisc.c +++ b/ldisc.c @@ -146,6 +146,18 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) */ frontend_keypress(ldisc->frontend); + if (interactive && ldisc->term) { + /* + * Interrupt a paste from the clipboard, if one was in + * progress when the user pressed a key. This is easier than + * buffering the current piece of data and saving it until the + * terminal has finished pasting, and has the potential side + * benefit of permitting a user to cancel an accidental huge + * paste. + */ + term_nopaste(ldisc->term); + } + /* * Less than zero means null terminated special string. */ diff --git a/noterm.c b/noterm.c new file mode 100644 index 00000000..4ca99fa2 --- /dev/null +++ b/noterm.c @@ -0,0 +1,11 @@ +/* + * Stubs of functions in terminal.c, for use in programs that don't + * have a terminal. + */ + +#include "putty.h" +#include "terminal.h" + +void term_nopaste(Terminal *term) +{ +} diff --git a/windows/window.c b/windows/window.c index ca7260bb..bc891955 100644 --- a/windows/window.c +++ b/windows/window.c @@ -3051,14 +3051,6 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, return DefWindowProc(hwnd, message, wParam, lParam); if (len != 0) { - /* - * Interrupt an ongoing paste. I'm not sure - * this is sensible, but for the moment it's - * preferable to having to faff about buffering - * things. - */ - term_nopaste(term); - /* * We need not bother about stdin backlogs * here, because in GUI PuTTY we can't do @@ -4608,13 +4600,6 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, if (r > 0) { WCHAR keybuf; - /* - * Interrupt an ongoing paste. I'm not sure this is - * sensible, but for the moment it's preferable to - * having to faff about buffering things. - */ - term_nopaste(term); - p = output; for (i = 0; i < r; i++) { wchar_t wch = keys_unicode[i];