qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

unicodemap.c (1171B)


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