From f2d63388a8dcc18f065f74dbd067f92c5ccc291c Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 3 Apr 2025 20:08:06 +0100 Subject: [PATCH] Stop cursor attributes being temporary When telling front ends to paint the screen, the terminal code treats the cursor as an attribute applied to the character cell(s) it appears in. do_paint() detects changes to most such attributes by storing what it last sent to the front end in term->disptext and comparing that with what it thinks should be displayed in the window. However, before this commit the cursor was special. Its last-drawn position was recorded in special structure members and invalidated parts of the display based on those. The cursor attributes were treated as "temporary attributes" and were not saved in term->disptext. This commit regularizes this and turns the cursor attributes into normal attributes that are stored in term->disptext. This removes a bunch of special-case code in do_paint() because now the normal update code handles the cursor properly, and also removes some members from the Terminal structure. I hope it will also make future cursor-handling changes (for instance for input method pre-editing) simpler. This commit makes the required semantic changes but doesn't make the rather more pervasive change of actually renaming the attributes from TATTR_ to ATTR_. That will be in the next commit. --- putty.h | 2 +- terminal/terminal.c | 29 +---------------------------- terminal/terminal.h | 2 -- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/putty.h b/putty.h index 83d4932d..b6b8518f 100644 --- a/putty.h +++ b/putty.h @@ -215,7 +215,7 @@ extern const int colour_indices_oscp_to_osc4[OSCP_NCOLOURS]; #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */ -#define TDATTR_MASK 0xF0000000UL +#define TDATTR_MASK 0x80000000UL #define TATTR_MASK (TDATTR_MASK) #define DATTR_MASK (TDATTR_MASK) diff --git a/terminal/terminal.c b/terminal/terminal.c index 898b642e..23b9a970 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -2066,7 +2066,6 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win) term_copy_stuff_from_conf(term); - term->dispcursx = term->dispcursy = -1; deselect(term); term->rows = term->cols = -1; power_on(term, true); @@ -2297,7 +2296,6 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines) } sfree(term->disptext); term->disptext = newdisp; - term->dispcursx = term->dispcursy = -1; /* Make a new alternate screen. */ newalt = newtree234(NULL); @@ -6092,27 +6090,6 @@ static void do_paint(Terminal *term) unlineptr(ldata); } - /* - * If the cursor is not where it was last time we painted, and - * its previous position is visible on screen, invalidate its - * previous position. - */ - if (term->dispcursy >= 0 && - (term->curstype != cursor || - term->dispcursy != our_curs_y || - term->dispcursx != our_curs_x)) { - termchar *dispcurs = term->disptext[term->dispcursy]->chars + - term->dispcursx; - - if (term->dispcursx > 0 && dispcurs->chr == UCSWIDE) - dispcurs[-1].attr |= ATTR_INVALID; - if (term->dispcursx < term->cols-1 && dispcurs[1].chr == UCSWIDE) - dispcurs[1].attr |= ATTR_INVALID; - dispcurs->attr |= ATTR_INVALID; - - term->curstype = 0; - } - term->dispcursx = term->dispcursy = -1; /* The normal screen data */ for (i = 0; i < term->rows; i++) { @@ -6220,12 +6197,8 @@ static void do_paint(Terminal *term) } else if (term->disptext[i]->chars[j].attr & ATTR_NARROW) tattr |= ATTR_NARROW; - if (i == our_curs_y && j == our_curs_x) { + if (i == our_curs_y && j == our_curs_x) tattr |= cursor; - term->curstype = cursor; - term->dispcursx = j; - term->dispcursy = i; - } /* FULL-TERMCHAR */ newline[j].attr = tattr; diff --git a/terminal/terminal.h b/terminal/terminal.h index 02967274..df6ba4cc 100644 --- a/terminal/terminal.h +++ b/terminal/terminal.h @@ -95,8 +95,6 @@ struct terminal_tag { ("temporary scrollback") */ termline **disptext; /* buffer of text on real screen */ - int dispcursx, dispcursy; /* location of cursor on real screen */ - int curstype; /* type of cursor on real screen */ #define VBELL_TIMEOUT (TICKSPERSEC/10) /* visual bell lasts 1/10 sec */