fix: preserve emoji commits through XIM
This commit is contained in:
@@ -15,8 +15,8 @@ $(PROG): $(OBJS) ../ipc.c ../ipc.h
|
||||
|
||||
$(OBJS): ../ipc.h
|
||||
|
||||
$(TEST): ../tests/xim_test.c keymap.c keymap.h
|
||||
$(CC) $(CFLAGS) -o $@ ../tests/xim_test.c keymap.c $(XIM_LIBS)
|
||||
$(TEST): ../tests/xim_test.c keymap.c keymap.h ximtext.c ximtext.h
|
||||
$(CC) $(CFLAGS) -o $@ ../tests/xim_test.c keymap.c ximtext.c $(XIM_LIBS)
|
||||
|
||||
check: $(TEST)
|
||||
./$(TEST)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <xcb-imdkit/encoding.h>
|
||||
#include "ipc.h"
|
||||
#include "keymap.h"
|
||||
#include "ximtext.h"
|
||||
|
||||
typedef struct Ic Ic;
|
||||
struct Ic
|
||||
@@ -97,7 +98,7 @@ commit(xcb_im_input_context_t *ic, char *s, int len)
|
||||
|
||||
if(len == 0)
|
||||
return;
|
||||
ct = xcb_utf8_to_compound_text(s, len, &clen);
|
||||
ct = ximcompound(s, len, &clen);
|
||||
if(ct == NULL)
|
||||
return;
|
||||
xcb_im_commit_string(xim, ic, XCB_XIM_LOOKUP_CHARS, ct, clen, 0);
|
||||
|
||||
28
xim/ximtext.c
Normal file
28
xim/ximtext.c
Normal 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;
|
||||
}
|
||||
3
xim/ximtext.h
Normal file
3
xim/ximtext.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <stddef.h>
|
||||
|
||||
char *ximcompound(const char*, size_t, size_t*);
|
||||
Reference in New Issue
Block a user