csi: multi-cursor: use enum values in switch

This commit is contained in:
Daniel Eklöf 2025-08-28 12:17:35 +02:00
parent 7996267d7b
commit 89d87f2c1b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 42 additions and 25 deletions

61
csi.c
View file

@ -2240,16 +2240,16 @@ csi_dispatch(struct terminal *term, uint8_t final)
const unsigned shape = vt_param_get(term, 0, 0); const unsigned shape = vt_param_get(term, 0, 0);
switch (shape) { switch (shape) {
case 0: case MULTI_CURSOR_SHAPE_NONE:
case 1: case MULTI_CURSOR_SHAPE_BLOCK:
case 2: case MULTI_CURSOR_SHAPE_BEAM:
case 3: case MULTI_CURSOR_SHAPE_UNDERLINE:
case 29: case MULTI_CURSOR_SHAPE_PRIMARY:
LOG_WARN("multi-cursor: %s", LOG_WARN("multi-cursor: %s",
shape == 0 ? "no cursor" : shape == MULTI_CURSOR_SHAPE_NONE ? "no cursor" :
shape == 1 ? "block cursor" : shape == MULTI_CURSOR_SHAPE_BLOCK ? "block cursor" :
shape == 2 ? "beam cursor" : shape == MULTI_CURSOR_SHAPE_BEAM ? "beam cursor" :
shape == 3 ? "underline cursor" : "main cursor"); shape == MULTI_CURSOR_SHAPE_UNDERLINE ? "underline cursor" : "main cursor");
pixman_region32_t modified; pixman_region32_t modified;
pixman_region32_init(&modified); pixman_region32_init(&modified);
@ -2305,12 +2305,18 @@ csi_dispatch(struct terminal *term, uint8_t final)
} }
} }
if (shape == 0) { if (shape == MULTI_CURSOR_SHAPE_NONE) {
/* Cursors disabled, remove from active set */ /* Cursors disabled, remove from active set */
pixman_region32_subtract(&term->multi_cursor.active, &term->multi_cursor.active, &modified); pixman_region32_subtract(
&term->multi_cursor.active,
&term->multi_cursor.active,
&modified);
} else { } else {
/* Add new/updated cursors to active set */ /* Add new/updated cursors to active set */
pixman_region32_union(&term->multi_cursor.active, &term->multi_cursor.active, &modified); pixman_region32_union(
&term->multi_cursor.active,
&term->multi_cursor.active,
&modified);
} }
if (pixman_region32_empty(&term->multi_cursor.active)) { if (pixman_region32_empty(&term->multi_cursor.active)) {
@ -2327,6 +2333,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
int rect_count = 0; int rect_count = 0;
const pixman_box32_t *boxes = pixman_region32_rectangles(&modified, &rect_count); const pixman_box32_t *boxes = pixman_region32_rectangles(&modified, &rect_count);
/* Set shape, and dirty affected cells */
for (int j = 0; j < rect_count; j++) { for (int j = 0; j < rect_count; j++) {
const pixman_box32_t *box = &boxes[j]; const pixman_box32_t *box = &boxes[j];
for (int r = box->y1; r < box->y2; r++) { for (int r = box->y1; r < box->y2; r++) {
@ -2346,23 +2353,25 @@ csi_dispatch(struct terminal *term, uint8_t final)
pixman_region32_fini(&modified); pixman_region32_fini(&modified);
break; break;
case 30: case MULTI_CURSOR_SHAPE_TEXT_COLOR:
case 40: { case MULTI_CURSOR_SHAPE_CURSOR_COLOR: {
const unsigned color_space = vt_param_get(term, 1, 0); const unsigned color_space = vt_param_get(term, 1, 0);
enum multi_cursor_color_source color_source = MULTI_CURSOR_COLOR_PRIMARY; enum multi_cursor_color_source color_source = MULTI_CURSOR_COLOR_PRIMARY;
uint32_t color = shape == 30 ? term->multi_cursor.text_color uint32_t color = shape == MULTI_CURSOR_SHAPE_TEXT_COLOR
: term->multi_cursor.cursor_color; ? term->multi_cursor.text_color
: term->multi_cursor.cursor_color;
switch (color_space) { switch (color_space) {
case 0: case MULTI_CURSOR_COLOR_PRIMARY:
color_source = MULTI_CURSOR_COLOR_PRIMARY; color_source = MULTI_CURSOR_COLOR_PRIMARY;
break; break;
case 1: case MULTI_CURSOR_COLOR_SPECIAL:
color_source = MULTI_CURSOR_COLOR_SPECIAL; color_source = MULTI_CURSOR_COLOR_SPECIAL;
break; break;
case 2: { case MULTI_CURSOR_COLOR_RGB: {
const struct vt_param *param = &term->vt.params.v[1]; const struct vt_param *param = &term->vt.params.v[1];
if (param->sub.idx == 3) { if (param->sub.idx == 3) {
const uint8_t red = param->sub.value[0]; const uint8_t red = param->sub.value[0];
@ -2374,11 +2383,13 @@ csi_dispatch(struct terminal *term, uint8_t final)
break; break;
} }
case 5: { case MULTI_CURSOR_COLOR_256: {
const struct vt_param *param = &term->vt.params.v[1]; const struct vt_param *param = &term->vt.params.v[1];
if (param->sub.idx == 1) { if (param->sub.idx == 1) {
const unsigned color_index = param->sub.value[0]; const unsigned color_index = min(
color_source = MULTI_CURSOR_COLOR_RGB; param->sub.value[0], ALEN(term->colors.table) - 1);
color_source = MULTI_CURSOR_COLOR_256;
color = color_index; color = color_index;
} }
break; break;
@ -2389,7 +2400,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
return; return;
} }
if (shape == 30) { if (shape == MULTI_CURSOR_SHAPE_TEXT_COLOR) {
term->multi_cursor.text_color_source = color_source; term->multi_cursor.text_color_source = color_source;
term->multi_cursor.text_color = color; term->multi_cursor.text_color = color;
} else { } else {
@ -2399,11 +2410,11 @@ csi_dispatch(struct terminal *term, uint8_t final)
break; break;
} }
case 100: case MULTI_CURSOR_SHAPE_QUERY_CURSORS:
LOG_WARN("multi-cursor: unimplemented: query extra cursors"); LOG_WARN("multi-cursor: unimplemented: query extra cursors");
break; break;
case 101: case MULTI_CURSOR_SHAPE_QUERY_COLORS:
LOG_WARN("multi-cursor: unimplemented: query extra cursors' color"); LOG_WARN("multi-cursor: unimplemented: query extra cursors' color");
break; break;

View file

@ -414,6 +414,12 @@ enum multi_cursor_shape {
MULTI_CURSOR_SHAPE_BEAM = 2, MULTI_CURSOR_SHAPE_BEAM = 2,
MULTI_CURSOR_SHAPE_UNDERLINE = 3, MULTI_CURSOR_SHAPE_UNDERLINE = 3,
MULTI_CURSOR_SHAPE_PRIMARY = 29, MULTI_CURSOR_SHAPE_PRIMARY = 29,
MULTI_CURSOR_SHAPE_TEXT_COLOR = 30,
MULTI_CURSOR_SHAPE_CURSOR_COLOR = 40,
MULTI_CURSOR_SHAPE_QUERY_CURSORS = 100,
MULTI_CURSOR_SHAPE_QUERY_COLORS = 101,
}; };
/* Synchronized with the multi-cursor protocol specification */ /* Synchronized with the multi-cursor protocol specification */