1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 04:22:47 -05:00

Stop front ends remembering the data of their last paste.

Previously, both the Unix and Windows front ends would respond to a
paste action by retrieving data from the system clipboard, converting
it appropriately, _storing_ it in a persistent dynamic data block
inside the front end, and then calling term_do_paste(term), which in
turn would call back to the front end via get_clip() to retrieve the
current contents of that stored data block.

But, as far as I can tell, this was a completely pointless mechanism,
because after a data block was written into this storage area, it
would be immediately used for exactly one paste, and then never
accessed again until the next paste action caused it to be freed and
replaced with a new chunk of pasted data.

So why on earth was it stored persistently at all, and why that
callback mechanism from frontend to terminal back to frontend to
retrieve it for the actual paste action? I have no idea. This change
removes the entire system and replaces it with the completely obvious
alternative: the character-set-converted version of paste data is
allocated in a _local_ variable in the frontend paste functions,
passed directly to term_do_paste which now takes (buffer,length)
parameters, and freed immediately afterwards. get_clip() is gone.
This commit is contained in:
Simon Tatham
2017-12-09 08:41:03 +00:00
parent c05fdb7d61
commit f26654f618
5 changed files with 73 additions and 102 deletions

View File

@ -101,8 +101,6 @@ struct gui_data {
GdkColormap *colmap;
#endif
int direct_to_font;
wchar_t *pastein_data;
int pastein_data_len;
#ifdef JUST_USE_GTK_CLIPBOARD_UTF8
GtkClipboard *clipboard;
struct clipboard_data_instance *current_cdi;
@ -2594,6 +2592,8 @@ static void clipboard_text_received(GtkClipboard *clipboard,
const gchar *text, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
wchar_t *paste;
int paste_len;
int length;
if (!text)
@ -2601,14 +2601,12 @@ static void clipboard_text_received(GtkClipboard *clipboard,
length = strlen(text);
if (inst->pastein_data)
sfree(inst->pastein_data);
paste = snewn(length, wchar_t);
paste_len = mb_to_wc(CS_UTF8, 0, text, length, paste, length);
inst->pastein_data = snewn(length, wchar_t);
inst->pastein_data_len = mb_to_wc(CS_UTF8, 0, text, length,
inst->pastein_data, length);
term_do_paste(inst->term, paste, paste_len);
term_do_paste(inst->term);
sfree(paste);
}
void request_paste(void *frontend)
@ -2855,6 +2853,8 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
GdkAtom seldata_type = gtk_selection_data_get_data_type(seldata);
const guchar *seldata_data = gtk_selection_data_get_data(seldata);
gint seldata_length = gtk_selection_data_get_length(seldata);
wchar_t *paste;
int paste_len;
if (seldata_target == utf8_string_atom && seldata_length <= 0) {
/*
@ -2942,16 +2942,12 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
}
}
if (inst->pastein_data)
sfree(inst->pastein_data);
paste = snewn(length, wchar_t);
paste_len = mb_to_wc(charset, 0, text, length, paste, length);
inst->pastein_data = snewn(length, wchar_t);
inst->pastein_data_len = length;
inst->pastein_data_len =
mb_to_wc(charset, 0, text, length,
inst->pastein_data, inst->pastein_data_len);
term_do_paste(inst->term, paste, paste_len);
term_do_paste(inst->term);
sfree(paste);
#ifndef NOT_X_WINDOWS
if (free_list_required)
@ -3011,16 +3007,6 @@ void init_clipboard(struct gui_data *inst)
#endif /* JUST_USE_GTK_CLIPBOARD_UTF8 */
void get_clip(void *frontend, wchar_t ** p, int *len)
{
struct gui_data *inst = (struct gui_data *)frontend;
if (p) {
*p = inst->pastein_data;
*len = inst->pastein_data_len;
}
}
static void set_window_titles(struct gui_data *inst)
{
/*