From 6c47cf7892d0f212b04e7b798e53c120f51022d7 Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 20 Dec 2022 23:53:20 +0000 Subject: Add text cursor support. This turned out to be much more complex than anticipated, and the potential for bugs is therefore quite high. --- src/entry.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/entry.c') diff --git a/src/entry.c b/src/entry.c index 2ea14ac..5ccdb72 100644 --- a/src/entry.c +++ b/src/entry.c @@ -59,7 +59,7 @@ static void fixup_padding_sizes(struct directional *padding, uint32_t clip_width } } -void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, uint32_t height) +void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, uint32_t height, uint32_t scale) { entry->image.width = width; entry->image.height = height; @@ -211,6 +211,25 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u fixup_padding_sizes(&entry->alternate_result_theme.padding, width, height); fixup_padding_sizes(&entry->selection_theme.padding, width, height); + /* The cursor is a special case, as it just needs the input colours. */ + if (!entry->cursor_theme.color_specified) { + entry->cursor_theme.color = entry->input_theme.foreground_color; + } + if (!entry->cursor_theme.text_color_specified) { + entry->cursor_theme.text_color = entry->background_color; + } + + /* + * TODO: + * This is a dirty hack. The proper thing to do is probably just to + * stop scaling everything manually, set cairo_scale and have done + * with. The reason that isn't how things are currently done is due to + * historic scaling behaviour of tofi. + */ + if (!entry->cursor_theme.thickness_specified) { + entry->cursor_theme.thickness *= scale; + } + /* * Perform an initial render of the text. * This is done here rather than by calling entry_update to avoid the -- cgit v1.2.3