fix(xim): honor reset and X11 keyboard state
This commit is contained in:
@@ -4,18 +4,61 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb-imdkit/encoding.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||
|
||||
uint32_t keymaplookup(const uint32_t*, int, uint16_t);
|
||||
uint32_t keymaplookup(struct xkb_state*, uint8_t, uint16_t);
|
||||
char *ximcompound(const char*, size_t, size_t*);
|
||||
|
||||
enum
|
||||
{
|
||||
ShiftMask = 1<<0,
|
||||
LockMask = 1<<1,
|
||||
Mod2Mask = 1<<4,
|
||||
Mod5Mask = 1<<7,
|
||||
Group1 = 1<<13,
|
||||
};
|
||||
|
||||
static struct xkb_state*
|
||||
keystate(const char *layout)
|
||||
{
|
||||
struct xkb_context *context;
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_rule_names names;
|
||||
struct xkb_state *state;
|
||||
|
||||
memset(&names, 0, sizeof names);
|
||||
names.layout = layout;
|
||||
context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
assert(context != NULL);
|
||||
keymap = xkb_keymap_new_from_names(context, &names,
|
||||
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
assert(keymap != NULL);
|
||||
state = xkb_state_new(keymap);
|
||||
assert(state != NULL);
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
return state;
|
||||
}
|
||||
|
||||
static void
|
||||
checkkeys(void)
|
||||
{
|
||||
struct xkb_state *state;
|
||||
|
||||
state = keystate("de,ru");
|
||||
assert(keymaplookup(state, 38, 0) == XKB_KEY_a);
|
||||
assert(keymaplookup(state, 38, ShiftMask) == XKB_KEY_A);
|
||||
assert(keymaplookup(state, 38, LockMask) == XKB_KEY_A);
|
||||
assert(keymaplookup(state, 38, LockMask|ShiftMask) == XKB_KEY_a);
|
||||
assert(keymaplookup(state, 26, Mod5Mask) == XKB_KEY_EuroSign);
|
||||
assert(keymaplookup(state, 26, Group1) == XKB_KEY_Cyrillic_u);
|
||||
assert(keymaplookup(state, 87, 0) == XKB_KEY_KP_End);
|
||||
assert(keymaplookup(state, 87, Mod2Mask) == XKB_KEY_KP_1);
|
||||
xkb_state_unref(state);
|
||||
assert(keymaplookup(NULL, 38, 0) == XKB_KEY_NoSymbol);
|
||||
}
|
||||
|
||||
static void
|
||||
checktext(const char *s)
|
||||
{
|
||||
@@ -53,11 +96,7 @@ checkcorpus(void)
|
||||
{
|
||||
static const char *text[] = {
|
||||
"한글",
|
||||
"かなカナ",
|
||||
"漢字",
|
||||
"𠀋",
|
||||
"😀",
|
||||
"❤️",
|
||||
"👩💻",
|
||||
};
|
||||
size_t i;
|
||||
@@ -69,28 +108,9 @@ checkcorpus(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
static const uint32_t letters[] = {
|
||||
XKB_KEY_a, XKB_KEY_A, XKB_KEY_Cyrillic_ef, XKB_KEY_Cyrillic_EF,
|
||||
};
|
||||
static const uint32_t inferred[] = { XKB_KEY_a, XKB_KEY_NoSymbol };
|
||||
static const uint32_t punctuation[] = { XKB_KEY_1, XKB_KEY_exclam };
|
||||
static const uint32_t missing[] = {
|
||||
XKB_KEY_a, XKB_KEY_A, XKB_KEY_NoSymbol, XKB_KEY_NoSymbol,
|
||||
};
|
||||
|
||||
xcb_compound_text_init();
|
||||
|
||||
assert(keymaplookup(letters, 4, 0) == XKB_KEY_a);
|
||||
assert(keymaplookup(letters, 4, ShiftMask) == XKB_KEY_A);
|
||||
assert(keymaplookup(letters, 4, LockMask) == XKB_KEY_A);
|
||||
assert(keymaplookup(letters, 4, LockMask|ShiftMask) == XKB_KEY_a);
|
||||
assert(keymaplookup(letters, 4, Group1) == XKB_KEY_Cyrillic_ef);
|
||||
assert(keymaplookup(letters, 4, Group1|ShiftMask) == XKB_KEY_Cyrillic_EF);
|
||||
assert(keymaplookup(inferred, 2, ShiftMask) == XKB_KEY_A);
|
||||
assert(keymaplookup(punctuation, 2, LockMask) == XKB_KEY_1);
|
||||
assert(keymaplookup(punctuation, 2, LockMask|ShiftMask) == XKB_KEY_exclam);
|
||||
assert(keymaplookup(missing, 4, Group1) == XKB_KEY_a);
|
||||
assert(keymaplookup(NULL, 0, 0) == XKB_KEY_NoSymbol);
|
||||
checkkeys();
|
||||
checkcorpus();
|
||||
checktext("A😀한");
|
||||
checkutf8run();
|
||||
|
||||
Reference in New Issue
Block a user