fix: repair XIM context lifecycle
This commit is contained in:
37
xim/keymap.c
Normal file
37
xim/keymap.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "keymap.h"
|
||||
|
||||
enum
|
||||
{
|
||||
ShiftMask = 1<<0,
|
||||
LockMask = 1<<1,
|
||||
GroupShift = 13,
|
||||
GroupMask = 3,
|
||||
};
|
||||
|
||||
uint32_t
|
||||
keymaplookup(const uint32_t *syms, int nsyms, uint16_t state)
|
||||
{
|
||||
uint32_t lo, hi, lower, upper;
|
||||
int col, group, shift;
|
||||
|
||||
if(syms == NULL || nsyms <= 0)
|
||||
return XKB_KEY_NoSymbol;
|
||||
group = (state >> GroupShift) & GroupMask;
|
||||
col = group * 2;
|
||||
if(col >= nsyms || syms[col] == XKB_KEY_NoSymbol)
|
||||
col = 0;
|
||||
lo = syms[col];
|
||||
if(lo == XKB_KEY_NoSymbol)
|
||||
return XKB_KEY_NoSymbol;
|
||||
hi = col + 1 < nsyms ? syms[col + 1] : XKB_KEY_NoSymbol;
|
||||
lower = xkb_keysym_to_lower(lo);
|
||||
upper = xkb_keysym_to_upper(lo);
|
||||
if(hi == XKB_KEY_NoSymbol)
|
||||
hi = lower != upper ? upper : lo;
|
||||
shift = (state & ShiftMask) != 0;
|
||||
/* Lock reverses Shift only for keys with an alphabetic case pair. */
|
||||
if((state & LockMask) && lower != upper)
|
||||
shift = !shift;
|
||||
return shift ? hi : lo;
|
||||
}
|
||||
Reference in New Issue
Block a user