aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-12-03 17:37:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-12-07 19:44:10 +0000
commit98bd798daed897c56b6f0262e5105131a074bdad (patch)
tree64be2016cd4356eb18bbcd92275f3f0c869d7aa3
parentrender: ignore IME preedit state when deciding which cursor style to render (diff)
ime: calculate wchar widths once
-rw-r--r--ime.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ime.c b/ime.c
index ccdbb098..bde063a8 100644
--- a/ime.c
+++ b/ime.c
@@ -181,8 +181,13 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
/* Next, count number of cells needed */
size_t cell_count = 0;
- for (size_t i = 0; i < wchars; i++)
- cell_count += max(wcwidth(wcs[i]), 1);
+ size_t widths[wchars + 1];
+
+ for (size_t i = 0; i < wchars; i++) {
+ int width = max(wcwidth(wcs[i]), 1);
+ widths[i] = width;
+ cell_count += width;
+ }
/* Allocate cells */
term->ime.preedit.cells = xmalloc(
@@ -193,7 +198,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3,
for (size_t i = 0, cell_idx = 0; i < wchars; i++) {
struct cell *cell = &term->ime.preedit.cells[cell_idx];
- int width = max(wcwidth(wcs[i]), 1);
+ int width = widths[i];
cell->wc = wcs[i];
cell->attrs = (struct attributes){.clean = 0, .underline = 1};