summaryrefslogtreecommitdiff
path: root/src/lib/elput
diff options
context:
space:
mode:
authorChris Michael <cpmichael@osg.samsung.com>2016-05-26 12:36:51 -0400
committerChris Michael <cpmichael@osg.samsung.com>2016-05-26 12:49:24 -0400
commit2c043ca2057af6338ad8ff43c044d3b0f602898c (patch)
tree247d677234085289f5d01754b090e3d40a757e6f /src/lib/elput
parent1ed8759e1abd0d46a3835bea09a5926172a8aead (diff)
elput: Add APIs to support keyboard key remapping
This patch adds 2 new API functions which can enable keyboard key remapping, and set which keys are to be remapped. @feature Signed-off-by: Chris Michael <cpmichael@osg.samsung.com>
Diffstat (limited to 'src/lib/elput')
-rw-r--r--src/lib/elput/Elput.h28
-rw-r--r--src/lib/elput/elput_evdev.c21
-rw-r--r--src/lib/elput/elput_input.c66
-rw-r--r--src/lib/elput/elput_private.h3
4 files changed, 117 insertions, 1 deletions
diff --git a/src/lib/elput/Elput.h b/src/lib/elput/Elput.h
index 8d3d6f6669..a7f0b7e4da 100644
--- a/src/lib/elput/Elput.h
+++ b/src/lib/elput/Elput.h
@@ -351,6 +351,34 @@ EAPI void elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh
351 */ 351 */
352EAPI void elput_input_devices_calibrate(Elput_Manager *manager, int w, int h); 352EAPI void elput_input_devices_calibrate(Elput_Manager *manager, int w, int h);
353 353
354/**
355 * Enable key remap functionality
356 *
357 * @param manager
358 * @param enable
359 *
360 * @return EINA_TRUE on success, EINA_FALSE otherwise
361 *
362 * @ingroup Elput_Input_Group
363 * @since 1.18
364 */
365EAPI Eina_Bool elput_input_key_remap_enable(Elput_Manager *manager, Eina_Bool enable);
366
367/**
368 * Set a given set of keys as remapped keys
369 *
370 * @param manager
371 * @param from_keys
372 * @param to_keys
373 * @param num
374 *
375 * @return EINA_TRUE on success, EINA_FALSE otherwise
376 *
377 * @ingroup Elput_Input_Group
378 * @since 1.18
379 */
380EAPI Eina_Bool elput_input_key_remap_set(Elput_Manager *manager, int *from_keys, int *to_keys, int num);
381
354# endif 382# endif
355 383
356# undef EAPI 384# undef EAPI
diff --git a/src/lib/elput/elput_evdev.c b/src/lib/elput/elput_evdev.c
index 82768d6b35..c083a1783b 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -384,6 +384,20 @@ _keyboard_keymap_update(Elput_Seat *seat)
384} 384}
385 385
386static int 386static int
387_keyboard_remapped_key_get(Elput_Device *edev, int code)
388{
389 void *ret = NULL;
390
391 if (!edev) return code;
392 if (!edev->key_remap) return code;
393 if (!edev->key_remap_hash) return code;
394
395 ret = eina_hash_find(edev->key_remap_hash, &code);
396 if (ret) code = (int)(intptr_t)ret;
397 return code;
398}
399
400static int
387_keyboard_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes) 401_keyboard_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
388{ 402{
389 unsigned long hbytes = 0; 403 unsigned long hbytes = 0;
@@ -456,7 +470,9 @@ _keyboard_key(struct libinput_device *idevice, struct libinput_event_keyboard *e
456 ((state == LIBINPUT_KEY_STATE_RELEASED) && (count != 0))) 470 ((state == LIBINPUT_KEY_STATE_RELEASED) && (count != 0)))
457 return; 471 return;
458 472
459 code = libinput_event_keyboard_get_key(event) + 8; 473 code = libinput_event_keyboard_get_key(event);
474 code = _keyboard_remapped_key_get(dev, code) + 8;
475
460 timestamp = libinput_event_keyboard_get_time(event); 476 timestamp = libinput_event_keyboard_get_time(event);
461 477
462 if (state == LIBINPUT_KEY_STATE_PRESSED) 478 if (state == LIBINPUT_KEY_STATE_PRESSED)
@@ -1280,6 +1296,9 @@ _evdev_device_destroy(Elput_Device *edev)
1280 1296
1281 libinput_device_unref(edev->device); 1297 libinput_device_unref(edev->device);
1282 eina_stringshare_del(edev->output_name); 1298 eina_stringshare_del(edev->output_name);
1299
1300 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1301
1283 free(edev); 1302 free(edev);
1284} 1303}
1285 1304
diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c
index b427c38ed1..e838c9b212 100644
--- a/src/lib/elput/elput_input.c
+++ b/src/lib/elput/elput_input.c
@@ -510,3 +510,69 @@ elput_input_devices_calibrate(Elput_Manager *manager, int w, int h)
510 } 510 }
511 } 511 }
512} 512}
513
514EAPI Eina_Bool
515elput_input_key_remap_enable(Elput_Manager *manager, Eina_Bool enable)
516{
517 Elput_Seat *eseat;
518 Elput_Device *edev;
519 Eina_List *l, *ll;
520
521 EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
522
523 EINA_LIST_FOREACH(manager->input.seats, l, eseat)
524 {
525 EINA_LIST_FOREACH(eseat->devices, ll, edev)
526 {
527 if (!(edev->caps & EVDEV_SEAT_KEYBOARD)) continue;
528
529 edev->key_remap = enable;
530 if ((!enable) && (edev->key_remap_hash))
531 {
532 eina_hash_free(edev->key_remap_hash);
533 edev->key_remap_hash = NULL;
534 }
535 }
536 }
537
538 return EINA_TRUE;
539}
540
541EAPI Eina_Bool
542elput_input_key_remap_set(Elput_Manager *manager, int *from_keys, int *to_keys, int num)
543{
544 Elput_Seat *eseat;
545 Elput_Device *edev;
546 Eina_List *l, *ll;
547 int i = 0;
548
549 EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
550 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
551 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
552 EINA_SAFETY_ON_TRUE_RETURN_VAL((num <= 0), EINA_FALSE);
553
554 EINA_LIST_FOREACH(manager->input.seats, l, eseat)
555 {
556 EINA_LIST_FOREACH(eseat->devices, ll, edev)
557 {
558 if (!(edev->caps & EVDEV_SEAT_KEYBOARD)) continue;
559
560 if (!edev->key_remap) continue;
561 if (!edev->key_remap_hash)
562 edev->key_remap_hash = eina_hash_int32_new(NULL);
563 if (!edev->key_remap_hash) continue;
564
565 for (i = 0; i < num; i++)
566 {
567 if ((!from_keys[i]) || (!to_keys[i]))
568 continue;
569 }
570
571 for (i = 0; i < num; i++)
572 eina_hash_add(edev->key_remap_hash, &from_keys[i],
573 (void *)(intptr_t)to_keys[i]);
574 }
575 }
576
577 return EINA_TRUE;
578}
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index dc34f24099..2d9de141f9 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -217,7 +217,10 @@ struct _Elput_Device
217 217
218 Elput_Device_Capability caps; 218 Elput_Device_Capability caps;
219 219
220 Eina_Hash *key_remap_hash;
221
220 Eina_Bool left_handed : 1; 222 Eina_Bool left_handed : 1;
223 Eina_Bool key_remap : 1;
221}; 224};
222 225
223struct _Elput_Manager 226struct _Elput_Manager