summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2017-05-26 16:34:10 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2017-05-26 16:27:42 -0400
commitf7ae2a7de8cfc9a2c6731eb4ee3a87460eb4685e (patch)
tree1c15cb236c68453c33ad26b30d6401d7c08429aa
parent53157f4a4fb8a070fb083790ebc6199f19d3c390 (diff)
elput: fix key/keyname strings in key events
todo: move all this duplicated code somewhere
-rw-r--r--src/lib/elput/elput_evdev.c30
-rw-r--r--src/lib/elput/elput_private.h1
2 files changed, 26 insertions, 5 deletions
diff --git a/src/lib/elput/elput_evdev.c b/src/lib/elput/elput_evdev.c
index 4e5a960231..0ce57d9f23 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -224,6 +224,7 @@ _keyboard_init(Elput_Seat *seat, struct xkb_keymap *keymap)
224 224
225 kbd->state = xkb_state_new(kbd->info->keymap.map); 225 kbd->state = xkb_state_new(kbd->info->keymap.map);
226 if (!kbd->state) goto err; 226 if (!kbd->state) goto err;
227 kbd->maskless_state = xkb_state_new(kbd->info->keymap.map);
227 228
228 seat->kbd = kbd; 229 seat->kbd = kbd;
229 seat->count.kbd = 1; 230 seat->count.kbd = 1;
@@ -482,12 +483,31 @@ in this Software without prior written authorization from The Open Group.
482} 483}
483 484
484static void 485static void
486_elput_symbol_rep_find(xkb_keysym_t keysym, char *buffer, int size, unsigned int code)
487{
488 int n = 0;
489
490 n = xkb_keysym_to_utf8(keysym, buffer, size);
491
492 /* check if we are a control code */
493 if (n > 0 && !(
494 (buffer[0] > 0x0 && buffer[0] < 0x20) || /* others 0x0 to 0x1F control codes */
495 buffer[0] == 0x7F)) /*delete control code */
496 return;
497
498 if (xkb_keysym_get_name(keysym, buffer, size) != 0)
499 return;
500
501 snprintf(buffer, size, "Keycode-%u", code);
502}
503
504static void
485_keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *event) 505_keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *event)
486{ 506{
487 Elput_Device *dev; 507 Elput_Device *dev;
488 Elput_Keyboard *kbd; 508 Elput_Keyboard *kbd;
489 enum libinput_key_state state; 509 enum libinput_key_state state;
490 xkb_keysym_t sym = XKB_KEY_NoSymbol; 510 xkb_keysym_t sym_name, sym = XKB_KEY_NoSymbol;
491 const xkb_keysym_t *syms; 511 const xkb_keysym_t *syms;
492 unsigned int code = 0; 512 unsigned int code = 0;
493 unsigned int nsyms; 513 unsigned int nsyms;
@@ -522,12 +542,11 @@ _keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *e
522 542
523 nsyms = xkb_key_get_syms(kbd->state, code, &syms); 543 nsyms = xkb_key_get_syms(kbd->state, code, &syms);
524 if (nsyms == 1) sym = syms[0]; 544 if (nsyms == 1) sym = syms[0];
545 sym_name = xkb_state_key_get_one_sym(kbd->maskless_state, code);
525 546
526 memset(key, 0, sizeof(key));
527 xkb_keysym_get_name(sym, key, sizeof(key));
528 547
529 memset(keyname, 0, sizeof(keyname)); 548 _elput_symbol_rep_find(sym, key, sizeof(key), code);
530 memcpy(keyname, key, sizeof(keyname)); 549 _elput_symbol_rep_find(sym_name, keyname, sizeof(keyname), code);
531 550
532 if (keyname[0] == '\0') 551 if (keyname[0] == '\0')
533 snprintf(keyname, sizeof(keyname), "Keycode-%u", code); 552 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
@@ -1541,6 +1560,7 @@ _evdev_keyboard_destroy(Elput_Keyboard *kbd)
1541 1560
1542 if (kbd->state) xkb_state_unref(kbd->state); 1561 if (kbd->state) xkb_state_unref(kbd->state);
1543 if (kbd->info) _keyboard_info_destroy(kbd->info, kbd->external_map); 1562 if (kbd->info) _keyboard_info_destroy(kbd->info, kbd->external_map);
1563 if (kbd->maskless_state) xkb_state_unref(kbd->maskless_state);
1544 1564
1545 xkb_context_unref(kbd->context); 1565 xkb_context_unref(kbd->context);
1546 xkb_keymap_unref(kbd->pending_map); 1566 xkb_keymap_unref(kbd->pending_map);
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index ee74cfc67f..a2d46acbf5 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -137,6 +137,7 @@ struct _Elput_Keyboard
137 137
138 struct xkb_state *state; 138 struct xkb_state *state;
139 struct xkb_keymap *pending_map; 139 struct xkb_keymap *pending_map;
140 struct xkb_state *maskless_state;
140 struct xkb_context *context; 141 struct xkb_context *context;
141 struct xkb_rule_names names; 142 struct xkb_rule_names names;
142 143