Use my_wcwidth()+my_wcswidth() instead of system’s wcwdith()+wcswidth()

But not that these functions map to the system’s versions if foot was
configured with ‘-Dsystem-wcwidth’.
This commit is contained in:
Daniel Eklöf 2022-01-05 22:14:30 +01:00
parent c758949145
commit 97ade97d38
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 15 additions and 11 deletions

3
csi.c
View file

@ -24,6 +24,7 @@
#include "vt.h" #include "vt.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "xsnprintf.h" #include "xsnprintf.h"
#include "my-wcwidth.h"
#define UNHANDLED() LOG_DBG("unhandled: %s", csi_as_string(term, final, -1)) #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)) #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); int count = vt_param_get(term, 0, 1);
LOG_DBG("REP: '%lc' %d times", (wint_t)term->vt.last_printed, count); 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) { if (width > 0) {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
term_print(term, term->vt.last_printed, width); term_print(term, term->vt.last_printed, width);

3
ime.c
View file

@ -15,6 +15,7 @@
#include "util.h" #include "util.h"
#include "wayland.h" #include "wayland.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "my-wcwidth.h"
static void static void
enter(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, 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]; size_t widths[wchars + 1];
for (size_t i = 0; i < wchars; i++) { 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; widths[i] = width;
cell_count += width; cell_count += width;
} }

View file

@ -40,6 +40,7 @@
#include "url-mode.h" #include "url-mode.h"
#include "util.h" #include "util.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "my-wcwidth.h"
#define TIME_SCROLL_DAMAGE 0 #define TIME_SCROLL_DAMAGE 0
@ -627,7 +628,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
if (single != NULL) { if (single != NULL) {
glyph_count = 1; glyph_count = 1;
glyphs = &single; 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 { } else {
glyph_count = 1; glyph_count = 1;
glyphs = &single; 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) if (cell->wc >= CELL_SPACER)
continue; continue;
int width = max(1, wcwidth(cell->wc)); int width = max(1, my_wcwidth(cell->wc));
if (col_idx + i + width > term->cols) if (col_idx + i + width > term->cols)
break; break;
@ -2854,10 +2855,10 @@ render_search_box(struct terminal *term)
/* Calculate the width of each character */ /* Calculate the width of each character */
int widths[text_len + 1]; int widths[text_len + 1];
for (size_t i = 0; i < text_len; i++) 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; 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); const size_t wanted_visible_cells = max(20, total_cells);
xassert(term->scale >= 1); xassert(term->scale >= 1);
@ -3288,7 +3289,7 @@ render_urls(struct terminal *term)
int cols = 0; int cols = 0;
for (size_t i = 0; i <= wcslen(label); i++) { 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) if (_cols == (size_t)-1)
continue; continue;

7
vt.c
View file

@ -19,6 +19,7 @@
#include "osc.h" #include "osc.h"
#include "util.h" #include "util.h"
#include "xmalloc.h" #include "xmalloc.h"
#include "my-wcwidth.h"
#define UNHANDLED() LOG_DBG("unhandled: %s", esc_as_string(term, final)) #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 static void
action_utf8_print(struct terminal *term, wchar_t wc) 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; const bool grapheme_clustering = term->conf->tweak.grapheme_shaping;
#if !defined(FOOT_GRAPHEME_CLUSTERING) #if !defined(FOOT_GRAPHEME_CLUSTERING)
@ -672,7 +673,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
} }
#endif #endif
int base_width = wcwidth(base); int base_width = my_wcwidth(base);
if (base_width > 0) { if (base_width > 0) {
term->grid->cursor.point.col = col; term->grid->cursor.point.col = col;
term->grid->cursor.lcf = false; 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, term->fonts[0], base, wc, &base_from_primary,
&comb_from_primary, &pre_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: * Only use the pre-composed character if: