forked from mirrors/qmk_userspace
Fix keycode parameter extraction to match the new DD keycodes (#18977)
* Add macros to extract parameters from keycode values Implement both encoding and decoding for keycodes like TO(layer) or LM(layer, mod) in one place, so that the decoding won't get out of sync with the encoding. While at it, fix some macros for creating keycode values that did not apply the appropriate masks to parameters (and therefore could allow the result to be out of range if a wrong parameter was passed). * keymap_common: Use extraction macros for keycodes * pointing_device_auto_mouse: Use extraction macros for keycodes Fixes #18970. * process_autocorrect: Use extraction macros for keycodes * process_caps_word: Use extraction macros for keycodes (Also fix a minor bug - SH_TG was not handled properly) * process_leader: Use extraction macros for keycodes (Technically the code is not 100% correct, because it always assumes that the LT() or MT() action was a tap, but it's a separate issue that already existed before the keycode changes.) * process_unicode: Use extraction macros for keycodes * process_unicodemap: Use extraction macros for keycodes
This commit is contained in:
parent
5f9b7c035b
commit
a7b2f4233c
8 changed files with 81 additions and 38 deletions
|
@ -91,7 +91,7 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord
|
|||
} else {
|
||||
*mods |= MOD_RSFT;
|
||||
}
|
||||
*keycode &= 0xFF; // Get the basic keycode.
|
||||
*keycode = QK_MODS_GET_BASIC_KEYCODE(*keycode); // Get the basic keycode.
|
||||
return true;
|
||||
#ifndef NO_ACTION_TAPPING
|
||||
// Exclude tap-hold keys when they are held down
|
||||
|
@ -101,13 +101,20 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord
|
|||
// Exclude Layer Tap, if layers are disabled
|
||||
// but action tapping is still enabled.
|
||||
return false;
|
||||
# else
|
||||
// Exclude hold keycode
|
||||
if (!record->tap.count) {
|
||||
return false;
|
||||
}
|
||||
*keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(*keycode);
|
||||
break;
|
||||
# endif
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
// Exclude hold keycode
|
||||
if (!record->tap.count) {
|
||||
return false;
|
||||
}
|
||||
*keycode &= 0xFF;
|
||||
*keycode = QK_MOD_TAP_GET_TAP_KEYCODE(*keycode);
|
||||
break;
|
||||
#else
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
|
@ -119,10 +126,12 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord
|
|||
// and mask for base keycode when they are tapped.
|
||||
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
if (*keycode >= 0x56F0 || !record->tap.count) {
|
||||
// Note: IS_SWAP_HANDS_KEYCODE() actually tests for the special action keycodes like SH_TG, SH_TT, ...,
|
||||
// which currently overlap the SH_T(kc) range.
|
||||
if (IS_SWAP_HANDS_KEYCODE(*keycode) || !record->tap.count) {
|
||||
return false;
|
||||
}
|
||||
*keycode &= 0xFF;
|
||||
*keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(*keycode);
|
||||
break;
|
||||
#else
|
||||
// Exclude if disabled
|
||||
|
|
|
@ -109,7 +109,7 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
|
|||
// * Otherwise stop Caps Word.
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
if (record->tap.count == 0) { // Mod-tap key is held.
|
||||
const uint8_t mods = (keycode >> 8) & 0x1f;
|
||||
const uint8_t mods = QK_MOD_TAP_GET_MODS(keycode);
|
||||
switch (mods) {
|
||||
case MOD_LSFT:
|
||||
keycode = KC_LSFT;
|
||||
|
@ -127,7 +127,7 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
keycode &= 0xff;
|
||||
keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -137,16 +137,18 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
|
|||
if (record->tap.count == 0) {
|
||||
return true;
|
||||
}
|
||||
keycode &= 0xff;
|
||||
keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
|
||||
break;
|
||||
#endif // NO_ACTION_TAPPING
|
||||
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
|
||||
if (keycode > 0x56F0 || record->tap.count == 0) {
|
||||
// Note: IS_SWAP_HANDS_KEYCODE() actually tests for the special action keycodes like SH_TG, SH_TT, ...,
|
||||
// which currently overlap the SH_T(kc) range.
|
||||
if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) {
|
||||
return true;
|
||||
}
|
||||
keycode &= 0xff;
|
||||
keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode);
|
||||
break;
|
||||
#endif // SWAP_HANDS_ENABLE
|
||||
}
|
||||
|
|
|
@ -54,8 +54,10 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) {
|
|||
# endif // LEADER_NO_TIMEOUT
|
||||
{
|
||||
# ifndef LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
|
||||
keycode = keycode & 0xFF;
|
||||
if (IS_QK_MOD_TAP(keycode)) {
|
||||
keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
|
||||
} else if (IS_QK_LAYER_TAP(keycode)) {
|
||||
keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
|
||||
}
|
||||
# endif // LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
bool process_unicode(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX) {
|
||||
register_unicode(keycode & 0x7FFF);
|
||||
register_unicode(QK_UNICODE_GET_CODE_POINT(keycode));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
|
||||
if (keycode >= QK_UNICODEMAP_PAIR) {
|
||||
// Keycode is a pair: extract index based on Shift / Caps Lock state
|
||||
uint16_t index = keycode - QK_UNICODEMAP_PAIR;
|
||||
uint16_t index;
|
||||
|
||||
uint8_t mods = get_mods() | get_weak_mods();
|
||||
#ifndef NO_ACTION_ONESHOT
|
||||
|
@ -34,13 +34,15 @@ __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
|
|||
bool shift = mods & MOD_MASK_SHIFT;
|
||||
bool caps = host_keyboard_led_state().caps_lock;
|
||||
if (shift ^ caps) {
|
||||
index >>= 7;
|
||||
index = QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(keycode);
|
||||
} else {
|
||||
index = QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(keycode);
|
||||
}
|
||||
|
||||
return index & 0x7F;
|
||||
return index;
|
||||
} else {
|
||||
// Keycode is a regular index
|
||||
return keycode - QK_UNICODEMAP;
|
||||
return QK_UNICODEMAP_GET_INDEX(keycode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue