aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-08-28 10:18:00 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-08-28 10:18:00 +0000
commit6319ed8b299208f756b3761392be6256282055b7 (patch)
tree6211a01a119cecf9a49c6905e021531716814080 /render.c
parentcsi: multi-cursor: use enum values in switch (diff)
render: multi-cursor: wip: colors
Diffstat (limited to 'render.c')
-rw-r--r--render.c138
1 files changed, 82 insertions, 56 deletions
diff --git a/render.c b/render.c
index 67f7cb70..cd02aa76 100644
--- a/render.c
+++ b/render.c
@@ -592,7 +592,7 @@ draw_strikeout(const struct terminal *term, pixman_image_t *pix,
}
static void
-cursor_colors_for_cell(const struct terminal *term, const struct cell *cell,
+cursor_colors_for_cell(const struct terminal *term,
const pixman_color_t *fg, const pixman_color_t *bg,
pixman_color_t *cursor_color, pixman_color_t *text_color,
bool gamma_correct)
@@ -619,6 +619,71 @@ cursor_colors_for_cell(const struct terminal *term, const struct cell *cell,
}
static void
+multi_cursor_colors_for_cell(const struct terminal *term,
+ const pixman_color_t *fg, const pixman_color_t *bg,
+ pixman_color_t *cursor_color, pixman_color_t *text_color,
+ bool gamma_correct)
+{
+ /* Primary cursor colors */
+
+ /*
+ * TODO: this is incorrect when the primary cursor doesn't use
+ * fixed colors, but reverses the cell's color - we'll use _this_
+ * cell's colors, instead of the primary cursor cell's.
+ */
+ pixman_color_t primary_cursor_color;
+ pixman_color_t primary_text_color;
+ cursor_colors_for_cell(
+ term, fg, bg, &primary_cursor_color, &primary_text_color, gamma_correct);
+
+ switch (term->multi_cursor.cursor_color_source) {
+ case MULTI_CURSOR_COLOR_PRIMARY:
+ *cursor_color = primary_cursor_color;
+ break;
+
+ case MULTI_CURSOR_COLOR_256:
+ xassert(term->multi_cursor.cursor_color < 256);
+ *cursor_color = color_hex_to_pixman(
+ term->colors.table[term->multi_cursor.cursor_color], gamma_correct);
+ break;
+
+ case MULTI_CURSOR_COLOR_RGB:
+ *cursor_color = color_hex_to_pixman(
+ term->multi_cursor.cursor_color, gamma_correct);
+ break;
+
+ case MULTI_CURSOR_COLOR_SPECIAL:
+ /* Reverse fg/bg */
+ *cursor_color = *fg;
+ *text_color = *bg;
+ return; /* Yes, return - do *not* process the text color property */
+ }
+
+ xassert(term->multi_cursor.cursor_color_source != MULTI_CURSOR_COLOR_SPECIAL);
+
+ switch (term->multi_cursor.text_color_source) {
+ case MULTI_CURSOR_COLOR_PRIMARY:
+ *text_color = primary_text_color;
+ break;
+
+ case MULTI_CURSOR_COLOR_256:
+ xassert(term->multi_cursor.text_color < 256);
+ *text_color = color_hex_to_pixman(
+ term->colors.table[term->multi_cursor.text_color], gamma_correct);
+ break;
+
+ case MULTI_CURSOR_COLOR_RGB:
+ *text_color = color_hex_to_pixman(
+ term->multi_cursor.text_color, gamma_correct);
+ break;
+
+ case MULTI_CURSOR_COLOR_SPECIAL:
+ *text_color = *bg; /* Verify if this is correct */
+ break;
+ }
+}
+
+static void
draw_cursor(const struct terminal *term, const struct cell *cell,
const struct fcft_font *font, pixman_image_t *pix, pixman_color_t *fg,
const pixman_color_t *bg, int x, int y, int cols,
@@ -626,75 +691,37 @@ draw_cursor(const struct terminal *term, const struct cell *cell,
{
const bool gamma_correct = wayl_do_linear_blending(term->wl, term->conf);
- enum cursor_style style = term->cursor_style;
-
pixman_color_t cursor_color;
pixman_color_t text_color;
- cursor_colors_for_cell(
- term, cell, fg, bg, &cursor_color, &text_color, gamma_correct);
+ if (likely(extra_cursor == MULTI_CURSOR_SHAPE_NONE)) {
+ cursor_colors_for_cell(
+ term, fg, bg, &cursor_color, &text_color, gamma_correct);
+ } else {
+ multi_cursor_colors_for_cell(
+ term, fg, bg, &cursor_color, &text_color, gamma_correct);
+ }
- if (unlikely(extra_cursor != MULTI_CURSOR_SHAPE_NONE)) {
+ enum cursor_style style = term->cursor_style;
+ if (unlikely(extra_cursor != MULTI_CURSOR_SHAPE_NONE)) {
/* Map multi-cursor shape to something the draw logic understands */
switch (extra_cursor) {
- case MULTI_CURSOR_SHAPE_NONE: xassert(false); break;
case MULTI_CURSOR_SHAPE_PRIMARY: break;
case MULTI_CURSOR_SHAPE_BLOCK: style = CURSOR_BLOCK; break;
case MULTI_CURSOR_SHAPE_BEAM: style = CURSOR_BEAM; break;
case MULTI_CURSOR_SHAPE_UNDERLINE: style = CURSOR_UNDERLINE; break;
- }
-
- switch (term->multi_cursor.cursor_color_source) {
- case MULTI_CURSOR_COLOR_PRIMARY:
- /* TODO: use the colors of the primary cursor's cell, not
- this cell's. This is only a problem when the primary
- cursor doesn't used fixed colors, but reverses the
- cell's colors */
- break;
-
- case MULTI_CURSOR_COLOR_256:
- xassert(term->multi_cursor.cursor_color < 256);
- cursor_color = color_hex_to_pixman(term->colors.table[term->multi_cursor.cursor_color], gamma_correct);
- break;
- case MULTI_CURSOR_COLOR_RGB:
- cursor_color = color_hex_to_pixman(term->multi_cursor.cursor_color, gamma_correct);
- break;
-
- case MULTI_CURSOR_COLOR_SPECIAL:
- /* Reverse fg/bg */
- cursor_color = *fg;
- text_color = *bg;
- break;
+ case MULTI_CURSOR_SHAPE_NONE:
+ case MULTI_CURSOR_SHAPE_TEXT_COLOR:
+ case MULTI_CURSOR_SHAPE_CURSOR_COLOR:
+ case MULTI_CURSOR_SHAPE_QUERY_CURSORS:
+ case MULTI_CURSOR_SHAPE_QUERY_COLORS:
+ xassert(false); break;
}
- if (term->multi_cursor.cursor_color_source != MULTI_CURSOR_COLOR_SPECIAL) {
- switch (term->multi_cursor.text_color_source) {
- case MULTI_CURSOR_COLOR_PRIMARY:
- /* TODO: use the colors of the primary cursor's cell,
- not this cell's. This is only a problem when the
- primary cursor doesn't used fixed colors, but
- reverses the cell's colors */
- break;
-
- case MULTI_CURSOR_COLOR_256:
- xassert(term->multi_cursor.text_color < 256);
- text_color = color_hex_to_pixman(term->colors.table[term->multi_cursor.text_color], gamma_correct);
- break;
-
- case MULTI_CURSOR_COLOR_RGB:
- text_color = color_hex_to_pixman(term->multi_cursor.text_color, gamma_correct);
- break;
-
- case MULTI_CURSOR_COLOR_SPECIAL:
- text_color = *bg; /* Verify if this is correct */
- break;
- }
- }
}
-
if (unlikely(!term->kbd_focus)) {
switch (term->conf->cursor.unfocused_style) {
case CURSOR_UNFOCUSED_UNCHANGED:
@@ -709,7 +736,6 @@ draw_cursor(const struct terminal *term, const struct cell *cell,
}
}
-
switch (style) {
case CURSOR_BLOCK:
if (likely(term->cursor_blink.state == CURSOR_BLINK_ON) ||
@@ -1927,7 +1953,7 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat,
pixman_color_t cursor_color, text_color;
cursor_colors_for_cell(
- term, start_cell, &fg, &bg, &cursor_color, &text_color, gamma_correct);
+ term, &fg, &bg, &cursor_color, &text_color, gamma_correct);
int x = term->margins.left + (col_idx + start) * term->cell_width;
int y = term->margins.top + row_idx * term->cell_height;