logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

unicodemap.c (1171B)


  1. // Copyright 2023 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "unicodemap.h"
  4. #include "unicode.h"
  5. #include "keycodes.h"
  6. #include "quantum_keycodes.h"
  7. #include "modifiers.h"
  8. #include "host.h"
  9. #include "action_util.h"
  10. uint8_t unicodemap_index(uint16_t keycode) {
  11. if (keycode >= QK_UNICODEMAP_PAIR) {
  12. // Keycode is a pair: extract index based on Shift / Caps Lock state
  13. uint16_t index;
  14. uint8_t mods = get_mods() | get_weak_mods();
  15. #ifndef NO_ACTION_ONESHOT
  16. mods |= get_oneshot_mods();
  17. #endif
  18. bool shift = mods & MOD_MASK_SHIFT;
  19. bool caps = host_keyboard_led_state().caps_lock;
  20. if (shift ^ caps) {
  21. index = QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(keycode);
  22. } else {
  23. index = QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(keycode);
  24. }
  25. return index;
  26. } else {
  27. // Keycode is a regular index
  28. return QK_UNICODEMAP_GET_INDEX(keycode);
  29. }
  30. }
  31. uint32_t unicodemap_get_code_point(uint8_t index) {
  32. return pgm_read_dword(unicode_map + index);
  33. }
  34. void register_unicodemap(uint8_t index) {
  35. register_unicode(unicodemap_get_code_point(index));
  36. }