From 916a2574d5fb40ee9ce899ac93e8d31738f5bed4 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 8 Oct 2017 13:49:54 +0100 Subject: [PATCH] Make reverse video interact correctly with true colour. ATTR_REVERSE was being handled in the front ends, and was causing the foreground and background colours to be switched. (I'm not completely sure why I made that design decision; it might be purely historical, but then again, it might also be because reverse video is one effect on the fg and bg colours that must still be performed even in unusual frontend-specific situations like display-driven monochrome mode.) This affected both explicit reverse video enabled using SGR 7, and also the transient reverse video arising from mouse selection. Thanks to Markus Gans for reporting the bug in the latter, which when I investigated it turned out to affect the former as well. --- terminal.h | 2 +- unix/gtkwin.c | 6 ++++++ windows/window.c | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/terminal.h b/terminal.h index fcb321c4..03659744 100644 --- a/terminal.h +++ b/terminal.h @@ -103,7 +103,7 @@ struct terminal_tag { #endif /* OPTIMISE_SCROLL */ int default_attr, curr_attr, save_attr; - truecolour curr_truecolour; + truecolour curr_truecolour, save_truecolour; termchar basic_erase_char, erase_char; bufchain inbuf; /* terminal input buffer */ diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 5c629519..3e12a4ba 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -3298,9 +3298,15 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len, nfg = ((monochrome ? ATTR_DEFFG : (attr & ATTR_FGMASK)) >> ATTR_FGSHIFT); nbg = ((monochrome ? ATTR_DEFBG : (attr & ATTR_BGMASK)) >> ATTR_BGSHIFT); if (!!(attr & ATTR_REVERSE) ^ (monochrome && (attr & TATTR_ACTCURS))) { + struct optionalrgb trgb; + t = nfg; nfg = nbg; nbg = t; + + trgb = truecolour.fg; + truecolour.fg = truecolour.bg; + truecolour.bg = trgb; } if ((inst->bold_style & 2) && (attr & ATTR_BOLD)) { if (nfg < 16) nfg |= 8; diff --git a/windows/window.c b/windows/window.c index be7b4379..73f0751c 100644 --- a/windows/window.c +++ b/windows/window.c @@ -3521,9 +3521,15 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len, if (!fonts[nfont]) nfont = FONT_NORMAL; if (attr & ATTR_REVERSE) { + struct optionalrgb trgb; + t = nfg; nfg = nbg; nbg = t; + + trgb = truecolour.fg; + truecolour.fg = truecolour.bg; + truecolour.bg = trgb; } if (bold_colours && (attr & ATTR_BOLD) && !is_cursor) { if (nfg < 16) nfg |= 8;