From 97ade97d38b511cfc445e8822ecb5e1b95aaa44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 5 Jan 2022 22:14:30 +0100 Subject: [PATCH] =?UTF-8?q?Use=20my=5Fwcwidth()+my=5Fwcswidth()=20instead?= =?UTF-8?q?=20of=20system=E2=80=99s=20wcwdith()+wcswidth()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit But not that these functions map to the system’s versions if foot was configured with ‘-Dsystem-wcwidth’. --- csi.c | 3 ++- ime.c | 3 ++- render.c | 13 +++++++------ vt.c | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/csi.c b/csi.c index e76e0786..9b891233 100644 --- a/csi.c +++ b/csi.c @@ -24,6 +24,7 @@ #include "vt.h" #include "xmalloc.h" #include "xsnprintf.h" +#include "my-wcwidth.h" #define UNHANDLED() LOG_DBG("unhandled: %s", csi_as_string(term, final, -1)) #define UNHANDLED_SGR(idx) LOG_DBG("unhandled: %s", csi_as_string(term, 'm', idx)) @@ -742,7 +743,7 @@ csi_dispatch(struct terminal *term, uint8_t final) int count = vt_param_get(term, 0, 1); LOG_DBG("REP: '%lc' %d times", (wint_t)term->vt.last_printed, count); - const int width = wcwidth(term->vt.last_printed); + const int width = my_wcwidth(term->vt.last_printed); if (width > 0) { for (int i = 0; i < count; i++) term_print(term, term->vt.last_printed, width); diff --git a/ime.c b/ime.c index 81e63884..6ea6dfce 100644 --- a/ime.c +++ b/ime.c @@ -15,6 +15,7 @@ #include "util.h" #include "wayland.h" #include "xmalloc.h" +#include "my-wcwidth.h" static void enter(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, @@ -178,7 +179,7 @@ done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, size_t widths[wchars + 1]; for (size_t i = 0; i < wchars; i++) { - int width = max(wcwidth(seat->ime.preedit.text[i]), 1); + int width = max(my_wcwidth(seat->ime.preedit.text[i]), 1); widths[i] = width; cell_count += width; } diff --git a/render.c b/render.c index 23cb4dab..65416e55 100644 --- a/render.c +++ b/render.c @@ -40,6 +40,7 @@ #include "url-mode.h" #include "util.h" #include "xmalloc.h" +#include "my-wcwidth.h" #define TIME_SCROLL_DAMAGE 0 @@ -627,7 +628,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, if (single != NULL) { glyph_count = 1; glyphs = &single; - cell_cols = single->cols; + cell_cols = my_wcwidth(base); } } @@ -661,7 +662,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, } else { glyph_count = 1; glyphs = &single; - cell_cols = single->cols; + cell_cols = my_wcwidth(base); } } } @@ -1414,7 +1415,7 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat, if (cell->wc >= CELL_SPACER) continue; - int width = max(1, wcwidth(cell->wc)); + int width = max(1, my_wcwidth(cell->wc)); if (col_idx + i + width > term->cols) break; @@ -2854,10 +2855,10 @@ render_search_box(struct terminal *term) /* Calculate the width of each character */ int widths[text_len + 1]; for (size_t i = 0; i < text_len; i++) - widths[i] = max(0, wcwidth(text[i])); + widths[i] = max(0, my_wcwidth(text[i])); widths[text_len] = 0; - const size_t total_cells = wcswidth(text, text_len); + const size_t total_cells = my_wcswidth(text, text_len); const size_t wanted_visible_cells = max(20, total_cells); xassert(term->scale >= 1); @@ -3288,7 +3289,7 @@ render_urls(struct terminal *term) int cols = 0; for (size_t i = 0; i <= wcslen(label); i++) { - int _cols = wcswidth(label, i); + int _cols = my_wcswidth(label, i); if (_cols == (size_t)-1) continue; diff --git a/vt.c b/vt.c index 736a2cfd..aff10af0 100644 --- a/vt.c +++ b/vt.c @@ -19,6 +19,7 @@ #include "osc.h" #include "util.h" #include "xmalloc.h" +#include "my-wcwidth.h" #define UNHANDLED() LOG_DBG("unhandled: %s", esc_as_string(term, final)) @@ -619,7 +620,7 @@ chain_key(uint32_t old_key, uint32_t new_wc) static void action_utf8_print(struct terminal *term, wchar_t wc) { - int width = wcwidth(wc); + int width = my_wcwidth(wc); const bool grapheme_clustering = term->conf->tweak.grapheme_shaping; #if !defined(FOOT_GRAPHEME_CLUSTERING) @@ -672,7 +673,7 @@ action_utf8_print(struct terminal *term, wchar_t wc) } #endif - int base_width = wcwidth(base); + int base_width = my_wcwidth(base); if (base_width > 0) { term->grid->cursor.point.col = col; term->grid->cursor.lcf = false; @@ -686,7 +687,7 @@ action_utf8_print(struct terminal *term, wchar_t wc) term->fonts[0], base, wc, &base_from_primary, &comb_from_primary, &pre_from_primary); - int precomposed_width = wcwidth(precomposed); + int precomposed_width = my_wcwidth(precomposed); /* * Only use the pre-composed character if: