forked from enlightenment/efl
elput: fix key/keyname strings in key events
todo: move all this duplicated code somewhere
This commit is contained in:
parent
53157f4a4f
commit
f7ae2a7de8
|
@ -224,6 +224,7 @@ _keyboard_init(Elput_Seat *seat, struct xkb_keymap *keymap)
|
||||||
|
|
||||||
kbd->state = xkb_state_new(kbd->info->keymap.map);
|
kbd->state = xkb_state_new(kbd->info->keymap.map);
|
||||||
if (!kbd->state) goto err;
|
if (!kbd->state) goto err;
|
||||||
|
kbd->maskless_state = xkb_state_new(kbd->info->keymap.map);
|
||||||
|
|
||||||
seat->kbd = kbd;
|
seat->kbd = kbd;
|
||||||
seat->count.kbd = 1;
|
seat->count.kbd = 1;
|
||||||
|
@ -481,13 +482,32 @@ in this Software without prior written authorization from The Open Group.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_elput_symbol_rep_find(xkb_keysym_t keysym, char *buffer, int size, unsigned int code)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
n = xkb_keysym_to_utf8(keysym, buffer, size);
|
||||||
|
|
||||||
|
/* check if we are a control code */
|
||||||
|
if (n > 0 && !(
|
||||||
|
(buffer[0] > 0x0 && buffer[0] < 0x20) || /* others 0x0 to 0x1F control codes */
|
||||||
|
buffer[0] == 0x7F)) /*delete control code */
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (xkb_keysym_get_name(keysym, buffer, size) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
snprintf(buffer, size, "Keycode-%u", code);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *event)
|
_keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *event)
|
||||||
{
|
{
|
||||||
Elput_Device *dev;
|
Elput_Device *dev;
|
||||||
Elput_Keyboard *kbd;
|
Elput_Keyboard *kbd;
|
||||||
enum libinput_key_state state;
|
enum libinput_key_state state;
|
||||||
xkb_keysym_t sym = XKB_KEY_NoSymbol;
|
xkb_keysym_t sym_name, sym = XKB_KEY_NoSymbol;
|
||||||
const xkb_keysym_t *syms;
|
const xkb_keysym_t *syms;
|
||||||
unsigned int code = 0;
|
unsigned int code = 0;
|
||||||
unsigned int nsyms;
|
unsigned int nsyms;
|
||||||
|
@ -522,12 +542,11 @@ _keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *e
|
||||||
|
|
||||||
nsyms = xkb_key_get_syms(kbd->state, code, &syms);
|
nsyms = xkb_key_get_syms(kbd->state, code, &syms);
|
||||||
if (nsyms == 1) sym = syms[0];
|
if (nsyms == 1) sym = syms[0];
|
||||||
|
sym_name = xkb_state_key_get_one_sym(kbd->maskless_state, code);
|
||||||
|
|
||||||
memset(key, 0, sizeof(key));
|
|
||||||
xkb_keysym_get_name(sym, key, sizeof(key));
|
|
||||||
|
|
||||||
memset(keyname, 0, sizeof(keyname));
|
_elput_symbol_rep_find(sym, key, sizeof(key), code);
|
||||||
memcpy(keyname, key, sizeof(keyname));
|
_elput_symbol_rep_find(sym_name, keyname, sizeof(keyname), code);
|
||||||
|
|
||||||
if (keyname[0] == '\0')
|
if (keyname[0] == '\0')
|
||||||
snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
|
snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
|
||||||
|
@ -1541,6 +1560,7 @@ _evdev_keyboard_destroy(Elput_Keyboard *kbd)
|
||||||
|
|
||||||
if (kbd->state) xkb_state_unref(kbd->state);
|
if (kbd->state) xkb_state_unref(kbd->state);
|
||||||
if (kbd->info) _keyboard_info_destroy(kbd->info, kbd->external_map);
|
if (kbd->info) _keyboard_info_destroy(kbd->info, kbd->external_map);
|
||||||
|
if (kbd->maskless_state) xkb_state_unref(kbd->maskless_state);
|
||||||
|
|
||||||
xkb_context_unref(kbd->context);
|
xkb_context_unref(kbd->context);
|
||||||
xkb_keymap_unref(kbd->pending_map);
|
xkb_keymap_unref(kbd->pending_map);
|
||||||
|
|
|
@ -137,6 +137,7 @@ struct _Elput_Keyboard
|
||||||
|
|
||||||
struct xkb_state *state;
|
struct xkb_state *state;
|
||||||
struct xkb_keymap *pending_map;
|
struct xkb_keymap *pending_map;
|
||||||
|
struct xkb_state *maskless_state;
|
||||||
struct xkb_context *context;
|
struct xkb_context *context;
|
||||||
struct xkb_rule_names names;
|
struct xkb_rule_names names;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue