1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 01:02:24 +00:00

Cleanup: make an enum for the values of CONF_cursor_type.

These have been magic numbers 0, 1 and 2 in the source for ages. I
think it's about time they had actual names, to make all the points of
use clearer.
This commit is contained in:
Simon Tatham 2023-05-29 15:51:17 +01:00
parent 8bd75b85ed
commit dfa91dfa8f
4 changed files with 21 additions and 14 deletions

View File

@ -2248,9 +2248,9 @@ void setup_config_box(struct controlbox *b, bool midsession,
HELPCTX(appearance_cursor), HELPCTX(appearance_cursor),
conf_radiobutton_handler, conf_radiobutton_handler,
I(CONF_cursor_type), I(CONF_cursor_type),
"Block", 'l', I(0), "Block", 'l', I(CURSOR_BLOCK),
"Underline", 'u', I(1), "Underline", 'u', I(CURSOR_UNDERLINE),
"Vertical line", 'v', I(2)); "Vertical line", 'v', I(CURSOR_VERTICAL_LINE));
ctrl_checkbox(s, "Cursor blinks", 'b', ctrl_checkbox(s, "Cursor blinks", 'b',
HELPCTX(appearance_cursor), HELPCTX(appearance_cursor),
conf_checkbox_handler, I(CONF_blink_cur)); conf_checkbox_handler, I(CONF_blink_cur));

View File

@ -508,6 +508,10 @@ enum {
FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
}; };
enum {
CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_VERTICAL_LINE
};
enum { enum {
SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
}; };

View File

@ -4075,7 +4075,7 @@ static void gtkwin_draw_cursor(
passive = true; passive = true;
} else } else
passive = false; passive = false;
if ((attr & TATTR_ACTCURS) && inst->cursor_type != 0) { if ((attr & TATTR_ACTCURS) && inst->cursor_type != CURSOR_BLOCK) {
attr &= ~TATTR_ACTCURS; attr &= ~TATTR_ACTCURS;
active = true; active = true;
} else } else
@ -4100,7 +4100,7 @@ static void gtkwin_draw_cursor(
len *= 2; len *= 2;
} }
if (inst->cursor_type == 0) { if (inst->cursor_type == CURSOR_BLOCK) {
/* /*
* An active block cursor will already have been done by * An active block cursor will already have been done by
* the above do_text call, so we only need to do anything * the above do_text call, so we only need to do anything
@ -4125,7 +4125,7 @@ static void gtkwin_draw_cursor(
else else
char_width = inst->font_width; char_width = inst->font_width;
if (inst->cursor_type == 1) { if (inst->cursor_type == CURSOR_UNDERLINE) {
uheight = inst->fonts[0]->ascent + 1; uheight = inst->fonts[0]->ascent + 1;
if (uheight >= inst->font_height) if (uheight >= inst->font_height)
uheight = inst->font_height - 1; uheight = inst->font_height - 1;
@ -4135,7 +4135,7 @@ static void gtkwin_draw_cursor(
dx = 1; dx = 1;
dy = 0; dy = 0;
length = len * widefactor * char_width; length = len * widefactor * char_width;
} else { } else /* inst->cursor_type == CURSOR_VERTICAL_LINE */ {
int xadjust = 0; int xadjust = 0;
if (attr & TATTR_RIGHTCURS) if (attr & TATTR_RIGHTCURS)
xadjust = char_width - 1; xadjust = char_width - 1;

View File

@ -3576,7 +3576,7 @@ static void do_text_internal(
y += wgs->offset_height; y += wgs->offset_height;
if ((attr & TATTR_ACTCURS) && if ((attr & TATTR_ACTCURS) &&
(wgs->cursor_type == 0 || wgs->term->big_cursor)) { (wgs->cursor_type == CURSOR_BLOCK || wgs->term->big_cursor)) {
truecolour.fg = truecolour.bg = optionalrgb_none; truecolour.fg = truecolour.bg = optionalrgb_none;
attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS|ATTR_DIM); attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS|ATTR_DIM);
/* cursor fg and bg */ /* cursor fg and bg */
@ -3971,12 +3971,13 @@ static void wintw_draw_cursor(
lattr &= LATTR_MODE; lattr &= LATTR_MODE;
if ((attr & TATTR_ACTCURS) && (ctype == 0 || wgs->term->big_cursor)) { if ((attr & TATTR_ACTCURS) &&
(ctype == CURSOR_BLOCK || wgs->term->big_cursor)) {
if (*text != UCSWIDE) { if (*text != UCSWIDE) {
win_draw_text(tw, x, y, text, len, attr, lattr, truecolour); win_draw_text(tw, x, y, text, len, attr, lattr, truecolour);
return; return;
} }
ctype = 2; ctype = CURSOR_VERTICAL_LINE;
attr |= TATTR_RIGHTCURS; attr |= TATTR_RIGHTCURS;
} }
@ -3988,7 +3989,8 @@ static void wintw_draw_cursor(
x += wgs->offset_width; x += wgs->offset_width;
y += wgs->offset_height; y += wgs->offset_height;
if ((attr & TATTR_PASCURS) && (ctype == 0 || wgs->term->big_cursor)) { if ((attr & TATTR_PASCURS) &&
(ctype == CURSOR_BLOCK || wgs->term->big_cursor)) {
POINT pts[5]; POINT pts[5];
HPEN oldpen; HPEN oldpen;
pts[0].x = pts[1].x = pts[4].x = x; pts[0].x = pts[1].x = pts[4].x = x;
@ -4000,15 +4002,16 @@ static void wintw_draw_cursor(
Polyline(wgs->wintw_hdc, pts, 5); Polyline(wgs->wintw_hdc, pts, 5);
oldpen = SelectObject(wgs->wintw_hdc, oldpen); oldpen = SelectObject(wgs->wintw_hdc, oldpen);
DeleteObject(oldpen); DeleteObject(oldpen);
} else if ((attr & (TATTR_ACTCURS | TATTR_PASCURS)) && ctype != 0) { } else if ((attr & (TATTR_ACTCURS | TATTR_PASCURS)) &&
ctype != CURSOR_BLOCK) {
int startx, starty, dx, dy, length, i; int startx, starty, dx, dy, length, i;
if (ctype == 1) { if (ctype == CURSOR_UNDERLINE) {
startx = x; startx = x;
starty = y + wgs->descent; starty = y + wgs->descent;
dx = 1; dx = 1;
dy = 0; dy = 0;
length = char_width; length = char_width;
} else { } else /* ctype == CURSOR_VERTICAL_LINE */ {
int xadjust = 0; int xadjust = 0;
if (attr & TATTR_RIGHTCURS) if (attr & TATTR_RIGHTCURS)
xadjust = char_width - 1; xadjust = char_width - 1;