From 7bdfdabb5e1c7418074ff43d9b436033c96aa00c Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Wed, 14 Jun 2017 08:11:05 -0500 Subject: [PATCH] Update clipping interface for true-colour --- fuzzterm.c | 2 +- putty.h | 2 +- terminal.c | 19 ++++++++++++++----- unix/gtkwin.c | 8 ++++---- windows/window.c | 3 ++- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/fuzzterm.c b/fuzzterm.c index c57412c4..255fc6fb 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -82,7 +82,7 @@ void free_ctx(Context ctx) { } void palette_set(void *frontend, int a, int b, int c, int d) { } void palette_reset(void *frontend) { } int palette_get(void *frontend, int n, int *r, int *g, int *b) {return FALSE;} -void write_clip(void *frontend, wchar_t *a, int *b, int c, int d) { } +void write_clip(void *frontend, wchar_t *a, int *b, truecolour *c, int d, int e) { } void get_clip(void *frontend, wchar_t **w, int *i) { } void set_raw_mouse_mode(void *frontend, int m) { } void request_paste(void *frontend) { } diff --git a/putty.h b/putty.h index a9433fa7..ac35eb73 100644 --- a/putty.h +++ b/putty.h @@ -636,7 +636,7 @@ void palette_set(void *frontend, int, int, int, int); void palette_reset(void *frontend); int palette_get(void *frontend, int n, int *r, int *g, int *b); void write_aclip(void *frontend, char *, int, int); -void write_clip(void *frontend, wchar_t *, int *, int, int); +void write_clip(void *frontend, wchar_t *, int *, truecolour *, int, int); void get_clip(void *frontend, wchar_t **, int *); void optimised_move(void *frontend, int, int, int); void set_raw_mouse_mode(void *frontend, int); diff --git a/terminal.c b/terminal.c index 2106d10a..d32d4f42 100644 --- a/terminal.c +++ b/terminal.c @@ -5616,9 +5616,11 @@ typedef struct { wchar_t *textptr; /* = textbuf + bufpos (current insertion point) */ int *attrbuf; /* buffer for copied attributes */ int *attrptr; /* = attrbuf + bufpos */ + truecolour *tcbuf; /* buffer for copied colours */ + truecolour *tcptr; /* = tcbuf + bufpos */ } clip_workbuf; -static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr) +static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr, truecolour tc) { if (b->bufpos >= b->buflen) { b->buflen *= 2; @@ -5626,9 +5628,12 @@ static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr) b->textptr = b->textbuf + b->bufpos; b->attrbuf = sresize(b->attrbuf, b->buflen, int); b->attrptr = b->attrbuf + b->bufpos; + b->tcbuf = sresize(b->tcbuf, b->buflen, truecolour); + b->tcptr = b->tcbuf + b->bufpos; } *b->textptr++ = chr; *b->attrptr++ = attr; + *b->tcptr++ = tc; b->bufpos++; } @@ -5637,11 +5642,13 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel) clip_workbuf buf; int old_top_x; int attr; + truecolour tc; buf.buflen = 5120; buf.bufpos = 0; buf.textptr = buf.textbuf = snewn(buf.buflen, wchar_t); buf.attrptr = buf.attrbuf = snewn(buf.buflen, int); + buf.tcptr = buf.tcbuf = snewn(buf.buflen, truecolour); old_top_x = top.x; /* needed for rect==1 */ @@ -5707,6 +5714,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel) while (1) { int uc = ldata->chars[x].chr; attr = ldata->chars[x].attr; + tc = ldata->chars[x].truecolour; switch (uc & CSET_MASK) { case CSET_LINEDRW: @@ -5767,7 +5775,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel) #endif for (p = cbuf; *p; p++) - clip_addchar(&buf, *p, attr); + clip_addchar(&buf, *p, attr, tc); if (ldata->chars[x].cc_next) x += ldata->chars[x].cc_next; @@ -5779,7 +5787,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel) if (nl) { int i; for (i = 0; i < sel_nl_sz; i++) - clip_addchar(&buf, sel_nl[i], 0); + clip_addchar(&buf, sel_nl[i], 0, term->basic_erase_char.truecolour); } top.y++; top.x = rect ? old_top_x : 0; @@ -5787,12 +5795,13 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel) unlineptr(ldata); } #if SELECTION_NUL_TERMINATED - clip_addchar(&buf, 0, 0); + clip_addchar(&buf, 0, 0, term->basic_erase_char.truecolour); #endif /* Finally, transfer all that to the clipboard. */ - write_clip(term->frontend, buf.textbuf, buf.attrbuf, buf.bufpos, desel); + write_clip(term->frontend, buf.textbuf, buf.attrbuf, buf.tcbuf, buf.bufpos, desel); sfree(buf.textbuf); sfree(buf.attrbuf); + sfree(buf.tcbuf); } void term_copyall(Terminal *term) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 3e12a4ba..3a3c2a54 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -2360,8 +2360,8 @@ static void clipboard_clear(GtkClipboard *clipboard, gpointer data) sfree(cdi); } -void write_clip(void *frontend, wchar_t *data, int *attr, int len, - int must_deselect) +void write_clip(void *frontend, wchar_t *data, int *attr, truecolour *truecolour, + int len, int must_deselect) { struct gui_data *inst = (struct gui_data *)frontend; struct clipboard_data_instance *cdi; @@ -2488,8 +2488,8 @@ static char *retrieve_cutbuffer(int *nbytes) #endif } -void write_clip(void *frontend, wchar_t *data, int *attr, int len, - int must_deselect) +void write_clip(void *frontend, wchar_t *data, int *attr, truecolour *truecolour, + int len, int must_deselect) { struct gui_data *inst = (struct gui_data *)frontend; if (inst->pasteout_data) diff --git a/windows/window.c b/windows/window.c index 73f0751c..8faa57e9 100644 --- a/windows/window.c +++ b/windows/window.c @@ -4989,7 +4989,8 @@ void write_aclip(void *frontend, char *data, int len, int must_deselect) /* * Note: unlike write_aclip() this will not append a nul. */ -void write_clip(void *frontend, wchar_t * data, int *attr, int len, int must_deselect) +void write_clip(void *frontend, wchar_t *data, int *attr, truecolour *truecolour, + int len, int must_deselect) { HGLOBAL clipdata, clipdata2, clipdata3; int len2;