summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorSung-Jin Park <input.hacker@gmail.com>2015-12-28 09:18:05 -0500
committerChris Michael <cpmichael@osg.samsung.com>2015-12-28 09:24:58 -0500
commit936350d37fd7d2ba695584db079cfc98eb13faed (patch)
treeead2459b3db125eb383b9b2d9b0d387b7a1ea5c2 /src/lib/ecore_drm
parentd91e403a98f5343b31aaaa2bda2e24cf27156cf8 (diff)
ecore-drm: Add APIs to support key remap functionality
Summary: This adds two new APIs to enable/set key remap functionality and a number of keys to be remapped to the other keys. As of now there is no api to do this therefore we need to remap using linux utility such as 'setkeycodes'. By adding/calling these apis, each Ecore_Drm_Evdev device will have its specific key remap hash and we can apply each remapping keys for each key/keyboard device. Test Plan: (1) Enable key remap and set remapping of a key on a specific keyboard device (2) Plug in the keyboard device and check the key is being remapped or not (3) Check the other keys are coming normally (4) Check the the remapping key on a specific keyboard doesn't affect to any other devices Signed-off-by: Sung-Jin Park <input.hacker@gmail.com> Reviewers: raster, zmike, gwanglim, ManMower, devilhorns Subscribers: JHyun, ohduna, cedric, jpeg Differential Revision: https://phab.enlightenment.org/D3463
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/Ecore_Drm.h35
-rw-r--r--src/lib/ecore_drm/ecore_drm_evdev.c109
-rw-r--r--src/lib/ecore_drm/ecore_drm_private.h3
3 files changed, 144 insertions, 3 deletions
diff --git a/src/lib/ecore_drm/Ecore_Drm.h b/src/lib/ecore_drm/Ecore_Drm.h
index 47c60048cf..b7dccce576 100644
--- a/src/lib/ecore_drm/Ecore_Drm.h
+++ b/src/lib/ecore_drm/Ecore_Drm.h
@@ -940,6 +940,41 @@ EAPI Eina_Bool ecore_drm_output_possible_crtc_get(Ecore_Drm_Output *output, unsi
940 */ 940 */
941EAPI Eina_Bool ecore_drm_output_mode_set(Ecore_Drm_Output *output, Ecore_Drm_Output_Mode *mode, int x, int y); 941EAPI Eina_Bool ecore_drm_output_mode_set(Ecore_Drm_Output *output, Ecore_Drm_Output_Mode *mode, int x, int y);
942 942
943/**
944 * Enable key remap functionality on a Ecore_Drm_Evdev
945 *
946 * This function will enable the key remap functionality to the given Ecore_Drm_Evdev
947 *
948 * @param edev The Ecore_Drm_Evdev to enable the key remap on
949 * @param enable A valid Eina_Bool to enable or disable the key remap on the device
950 *
951 * @return EINA_FALSE is returned if the Ecore_Drm_Evdev is not valid, or if no libinput device has been
952 * assigned to it yet. EINA_TRUE will be returned if enabling key remap for this device succeeded.
953 *
954 * @ingroup Ecore_Drm_Input_Group
955 * @since 1.17
956 */
957EAPI Eina_Bool ecore_drm_evdev_key_remap_enable(Ecore_Drm_Evdev *edev, Eina_Bool enable);
958
959/**
960 * Set a given set of keys as remapped keys on a Ecore_Drm_Evdev
961 *
962 * This function will create a hash table of remapping keys as a member of the given Ecore_Drm_Evdev
963 *
964 * @param edev The Ecore_Drm_Evdev to set the remapping keys on
965 * @param from_keys A set of keycodes which contains the original keycode
966 * @param to_keys A set of keycodes which contains the keycode to be remapped
967 * @param num The number of keys to be applied
968 *
969 * @return EINA_FALSE is returned if the Ecore_Drm_Evdev is not valid, if no libinput device has been
970 * assigned to it yet, if key remap is not enabled yet, or the some of the given parameters such as
971 * from_keys, to_keys, num are not valid. EINA_TRUE will be returned if setting key remap for this device succeeded.
972 *
973 * @ingroup Ecore_Drm_Input_Group
974 * @since 1.17
975 */
976EAPI Eina_Bool ecore_drm_evdev_key_remap_set(Ecore_Drm_Evdev *edev, int *from_keys, int *to_keys, int num);
977
943# ifdef __cplusplus 978# ifdef __cplusplus
944} 979}
945# endif 980# endif
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c
index 824fb099a8..1052f98f7c 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -247,13 +247,29 @@ _device_modifiers_update(Ecore_Drm_Evdev *edev)
247 247
248} 248}
249 249
250static int
251_device_remapped_key_get(Ecore_Drm_Evdev *edev, int code)
252{
253 void *ret = NULL;
254
255 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
256 if (!edev->key_remap_enabled) return code;
257 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
258
259 ret = eina_hash_find(edev->key_remap_hash, &code);
260
261 if (ret) code = (int)(intptr_t)ret;
262
263 return code;
264}
265
250static void 266static void
251_device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event) 267_device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
252{ 268{
253 Ecore_Drm_Evdev *edev; 269 Ecore_Drm_Evdev *edev;
254 Ecore_Drm_Input *input; 270 Ecore_Drm_Input *input;
255 uint32_t timestamp; 271 uint32_t timestamp, nsyms;
256 uint32_t code, nsyms; 272 uint32_t code = 0;
257 const xkb_keysym_t *syms; 273 const xkb_keysym_t *syms;
258 enum libinput_key_state state; 274 enum libinput_key_state state;
259 int key_count; 275 int key_count;
@@ -267,7 +283,12 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
267 if (!(input = edev->seat->input)) return; 283 if (!(input = edev->seat->input)) return;
268 284
269 timestamp = libinput_event_keyboard_get_time(event); 285 timestamp = libinput_event_keyboard_get_time(event);
270 code = libinput_event_keyboard_get_key(event) + 8; 286 code = libinput_event_keyboard_get_key(event);
287
288 if (!code) return;
289
290 code = _device_remapped_key_get(edev, code) + 8;
291
271 state = libinput_event_keyboard_get_key_state(event); 292 state = libinput_event_keyboard_get_key_state(event);
272 key_count = libinput_event_keyboard_get_seat_key_count(event); 293 key_count = libinput_event_keyboard_get_seat_key_count(event);
273 294
@@ -835,6 +856,7 @@ _ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *edev)
835 856
836 if (edev->path) eina_stringshare_del(edev->path); 857 if (edev->path) eina_stringshare_del(edev->path);
837 if (edev->device) libinput_device_unref(edev->device); 858 if (edev->device) libinput_device_unref(edev->device);
859 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
838 860
839 free(edev); 861 free(edev);
840} 862}
@@ -942,3 +964,84 @@ cont:
942 continue; 964 continue;
943 } 965 }
944} 966}
967
968/**
969 * @brief Enable key remap functionality on the given device
970 *
971 * @param edev The Ecore_Drm_Evdev to enable the key remap on.
972 * @param enable An Eina_Bool value to enable or disable the key remap on the device.
973 * @return EINA_FALSE is returned if the Ecore_Drm_Evdev is not valid, or if no libinput device has been
974 * assigned to it yet. EINA_TRUE will be returned if enabling key remap for this device succeeded.
975 *
976 * This function enables/disables key remap functionality with the given enable value.
977 * If the given enable value is EINA_FALSE, the key remap functionality wil be disable and
978 * the existing hash table for remapping keys will be freed.
979 */
980EAPI Eina_Bool
981ecore_drm_evdev_key_remap_enable(Ecore_Drm_Evdev *edev, Eina_Bool enable)
982{
983 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
984 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
985
986 edev->key_remap_enabled = enable;
987
988 if (enable == EINA_FALSE && edev->key_remap_hash)
989 {
990 eina_hash_free(edev->key_remap_hash);
991 edev->key_remap_hash = NULL;
992 }
993
994 return EINA_TRUE;
995}
996
997/**
998 * @brief Set a set of keys as remapping keys on the given device.
999 *
1000 * @param edev The Ecore_Drm_Evdev to set the remapping keys on
1001 * @param from_keys A set of keys which contains the original keycodes
1002 * @param to_keys A set of keys which contains the keycodes to be remapped
1003 * @param num The number of keys to be applied
1004 * @return EINA_FALSE is returned if the Ecore_Drm_Evdev is not valid, if no libinput device has been
1005 * assigned to it yet, if key remap is not enabled yet, or the some of the given parameters such as
1006 * from_keys, to_keys, num are not valid. EINA_TRUE will be returned if setting key remap for this device succeeded.
1007 *
1008 * This function will create a hash table of remapping keys as a member of the given device.
1009 * This hash table will be used in _device_remapped_key_get() later on.
1010 * Whenever a key event is coming from the the backend of ecore drm layer
1011 * the keycode of it can be replaced with the key found in the hash table.
1012 * If there is no key found, the coming keycode will be used.
1013 */
1014EAPI Eina_Bool
1015ecore_drm_evdev_key_remap_set(Ecore_Drm_Evdev *edev, int *from_keys, int *to_keys, int num)
1016{
1017 int i;
1018
1019 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1020 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1021 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1022 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1023 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1024 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1025
1026 if (!edev->key_remap_hash) edev->key_remap_hash = eina_hash_int32_new(NULL);
1027
1028 if (!edev->key_remap_hash)
1029 {
1030 ERR("Failed to set remap key information : creating a hash is failed.");
1031 return EINA_FALSE;
1032 }
1033
1034 for (i = 0; i < num ; i++)
1035 {
1036 if ((!from_keys[i]) || (!to_keys[i]))
1037 {
1038 ERR("Failed to set remap key information : given arguments are invalid.");
1039 return EINA_FALSE;
1040 }
1041 }
1042
1043 for (i = 0; i < num ; i++)
1044 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1045
1046 return EINA_TRUE;
1047}
diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h
index fbc6bda00e..6d30dee56b 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -225,6 +225,9 @@ struct _Ecore_Drm_Evdev
225 unsigned int depressed, latched, locked, group; 225 unsigned int depressed, latched, locked, group;
226 } xkb; 226 } xkb;
227 227
228 Eina_Hash *key_remap_hash;
229 Eina_Bool key_remap_enabled : 1;
230
228 /* Ecore_Drm_Evdev_Capabilities caps; */ 231 /* Ecore_Drm_Evdev_Capabilities caps; */
229 Ecore_Drm_Seat_Capabilities seat_caps; 232 Ecore_Drm_Seat_Capabilities seat_caps;
230}; 233};