ei-demo-client: use xkb_keymap_new_from_buffer()

This is the more correct approach since we get a sized buffer from the
server and people may use this as reference code in their implementation.
Technically we cannot expect a true zero-terminated string from EIS.

Unfortunately this means we need to work around
libxkbcommon#307 to strip trailing zeroes from the buffer if any exist.
This commit is contained in:
Peter Hutterer 2024-07-24 10:13:48 +10:00
parent a924888f0f
commit 3e2e43e352

View file

@ -104,7 +104,14 @@ setup_xkb_keymap(struct ei_keymap *keymap)
return;
}
_unref_(xkb_keymap) *xkbmap = xkb_keymap_new_from_string(ctx, memmap_get_data(memmap),
/* workaround for libxkbcommon#307 (fixed in libxkbcommon 1.6.0) - strip the trailing null byte */
size_t sz = memmap_get_size(memmap);
char *data = memmap_get_data(memmap);
while (sz > 0 && data[sz - 1] == '\0')
--sz;
_unref_(xkb_keymap) *xkbmap = xkb_keymap_new_from_buffer(ctx, memmap_get_data(memmap),
memmap_get_size(memmap),
XKB_KEYMAP_FORMAT_TEXT_V1,
XKB_KEYMAP_COMPILE_NO_FLAGS);
if (!xkbmap)