fix: preserve emoji commits through XIM

This commit is contained in:
2026-08-12 16:40:58 +09:00
parent 3f5e107230
commit 71af269efe
5 changed files with 62 additions and 3 deletions

28
xim/ximtext.c Normal file
View File

@@ -0,0 +1,28 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <xcb-imdkit/encoding.h>
#include "ximtext.h"
char*
ximcompound(const char *s, size_t len, size_t *outlen)
{
static const char utf8[] = "\033%G";
char *ct;
if(s == NULL || len > SIZE_MAX - sizeof utf8)
return NULL;
ct = xcb_utf8_to_compound_text(s, len, outlen);
if(ct != NULL)
return ct;
/* X11 Compound Text reserves ESC % G for an embedded UTF-8 run. */
ct = malloc(len + sizeof utf8);
if(ct == NULL)
return NULL;
memcpy(ct, utf8, sizeof utf8 - 1);
memcpy(ct + sizeof utf8 - 1, s, len);
ct[len + sizeof utf8 - 1] = '\0';
if(outlen != NULL)
*outlen = len + sizeof utf8 - 1;
return ct;
}