refactor: trim popup and XIM helpers

This commit is contained in:
2026-08-12 17:33:14 +09:00
parent 8d68e00f2b
commit de536da0bb
6 changed files with 12 additions and 27 deletions

1
dat.h
View File

@@ -17,7 +17,6 @@ enum
LangVI = 0x16,
Fontsz = 32,
Fontbase = 4,
Nglyphs = 0x20000,
Maxrunes = 64,
Maxutf = Maxrunes * UTFmax + 1,

2
fn.h
View File

@@ -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);

7
font.c
View File

@@ -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;
}

View File

@@ -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;
}

5
win.c
View File

@@ -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;

View File

@@ -3,7 +3,7 @@
#include <string.h>
#include <xcb-imdkit/encoding.h>
char*
static char*
ximutf8compound(const char *s, size_t len, size_t *outlen)
{
static const char begin[] = "\033%G";