From 194fbff883e605a3a9afac4ecc66c6cf3cc6b7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 6 Dec 2020 12:17:52 +0100 Subject: [PATCH] ime: store wchar version of pre-edit string in terminal struct --- ime.c | 9 +++++---- terminal.c | 2 ++ terminal.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ime.c b/ime.c index 9c6676ab..d7dbc873 100644 --- a/ime.c +++ b/ime.c @@ -150,15 +150,16 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, if (wchars > 0) { /* First, convert to unicode */ - wchar_t wcs[wchars + 1]; - mbstowcs(wcs, seat->ime.preedit.pending.text, wchars); + term->ime.preedit.text = xmalloc((wchars + 1) * sizeof(wchar_t)); + mbstowcs(term->ime.preedit.text, seat->ime.preedit.pending.text, wchars); + term->ime.preedit.text[wchars] = L'\0'; /* Next, count number of cells needed */ size_t cell_count = 0; size_t widths[wchars + 1]; for (size_t i = 0; i < wchars; i++) { - int width = max(wcwidth(wcs[i]), 1); + int width = max(wcwidth(term->ime.preedit.text[i]), 1); widths[i] = width; cell_count += width; } @@ -174,7 +175,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, int width = widths[i]; - cell->wc = wcs[i]; + cell->wc = term->ime.preedit.text[i]; cell->attrs = (struct attributes){.clean = 0, .underline = 1}; for (int j = 1; j < width; j++) { diff --git a/terminal.c b/terminal.c index 215304ec..a626b88d 100644 --- a/terminal.c +++ b/terminal.c @@ -2819,7 +2819,9 @@ term_ime_reset(struct terminal *term) { #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED if (term->ime.preedit.cells != NULL) { + free(term->ime.preedit.text); free(term->ime.preedit.cells); + term->ime.preedit.text = NULL; term->ime.preedit.cells = NULL; term->ime.preedit.count = 0; } diff --git a/terminal.h b/terminal.h index f99c77c0..07723e1e 100644 --- a/terminal.h +++ b/terminal.h @@ -475,6 +475,7 @@ struct terminal { struct { bool enabled; struct { + wchar_t *text; struct cell *cells; int count;