From de536da0bb3bfdab84c75b76d36e57ca9f6c5be7 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Wed, 12 Aug 2026 17:33:14 +0900 Subject: [PATCH] refactor: trim popup and XIM helpers --- dat.h | 1 - fn.h | 2 +- font.c | 7 +------ tests/xim_test.c | 22 ++++++++-------------- win.c | 5 +---- xim/ximtext.c | 2 +- 6 files changed, 12 insertions(+), 27 deletions(-) diff --git a/dat.h b/dat.h index 3bbcff0..d904969 100644 --- a/dat.h +++ b/dat.h @@ -17,7 +17,6 @@ enum LangVI = 0x16, Fontsz = 32, - Fontbase = 4, Nglyphs = 0x20000, Maxrunes = 64, Maxutf = Maxrunes * UTFmax + 1, diff --git a/fn.h b/fn.h index 5d56113..6919dae 100644 --- a/fn.h +++ b/fn.h @@ -55,5 +55,5 @@ int wlstaterepeat(Wlstate*, uvlong, u32int*); void* emalloc(ulong); void* erealloc(void*, ulong); -void fontinit(char*); +int fontinit(char*); void putfont(u32int*, int, int, int, int, Rune); diff --git a/font.c b/font.c index 99c1dd6..67176c8 100644 --- a/font.c +++ b/font.c @@ -83,7 +83,7 @@ loadfont(char *path) return 1; } -void +int fontinit(char *dir) { static char *names[] = { @@ -108,11 +108,6 @@ fontinit(char *dir) blendtab[0][a] = blend(Colbg, Colfg, a); blendtab[1][a] = blend(Colsel, Colfg, a); } -} - -int -fontready(void) -{ return nfonts != 0; } diff --git a/tests/xim_test.c b/tests/xim_test.c index 2fa8ce8..e51b796 100644 --- a/tests/xim_test.c +++ b/tests/xim_test.c @@ -8,7 +8,6 @@ uint32_t keymaplookup(const uint32_t*, int, uint16_t); char *ximcompound(const char*, size_t, size_t*); -char *ximutf8compound(const char*, size_t, size_t*); enum { @@ -35,22 +34,17 @@ checktext(const char *s) } static void -checkfallback(void) +checkutf8run(void) { static const char s[] = "😀"; - static const char want[] = "\033%G😀\033%@"; - char *ct, *utf8; - size_t clen, ulen; + char *ct; + size_t n; - ct = ximutf8compound(s, sizeof s - 1, &clen); + ct = ximcompound(s, sizeof s - 1, &n); assert(ct != NULL); - assert(clen == sizeof want - 1); - assert(memcmp(ct, want, clen) == 0); - utf8 = xcb_compound_text_to_utf8(ct, clen, &ulen); - assert(utf8 != NULL); - assert(ulen == sizeof s - 1); - assert(memcmp(utf8, s, ulen) == 0); - free(utf8); + assert(n >= 6); + assert(memcmp(ct, "\033%G", 3) == 0); + assert(memcmp(ct+n-3, "\033%@", 3) == 0); free(ct); } @@ -83,6 +77,6 @@ main(void) checktext("😀"); checktext("❤️"); checktext("A😀한"); - checkfallback(); + checkutf8run(); return 0; } diff --git a/win.c b/win.c index f65ad38..044378a 100644 --- a/win.c +++ b/win.c @@ -16,8 +16,6 @@ static xcb_pixmap_t pix; static u32int *img; static int depth; -extern int fontready(void); - static xcb_screen_t* getscr(xcb_connection_t *c, int n) { @@ -142,8 +140,7 @@ wininit(void) mask = XCB_CW_BACK_PIXMAP; xcb_change_window_attributes(conn, win, mask, &pix); img = emalloc(Imgw * Imgh * sizeof(img[0])); - fontinit(fontdir); - if(!fontready()){ + if(!fontinit(fontdir)){ fprint(2, "strans: popup disabled: no usable fonts\n"); wincleanup(); return 0; diff --git a/xim/ximtext.c b/xim/ximtext.c index 366cc78..bf9bd57 100644 --- a/xim/ximtext.c +++ b/xim/ximtext.c @@ -3,7 +3,7 @@ #include #include -char* +static char* ximutf8compound(const char *s, size_t len, size_t *outlen) { static const char begin[] = "\033%G";