Make Magic handling more consistent in Action Keycode handling (#9126)

Co-authored-by: Ryan <fauxpark@gmail.com>
master
Drashna Jaelre 2023-02-12 09:48:14 -08:00 committed by GitHub
parent 6ceff1367d
commit b47f179a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -211,6 +211,9 @@ If you define these options you will enable the associated feature, which may in
* Sets the delay for Tap Hold keys (`LT`, `MT`) when using `KC_CAPS_LOCK` keycode, as this has some special handling on MacOS. The value is in milliseconds, and defaults to 80 ms if not defined. For macOS, you may want to set this to 200 or higher.
* `#define KEY_OVERRIDE_REPEAT_DELAY 500`
* Sets the key repeat interval for [key overrides](feature_key_overrides.md).
* `#define LEGACY_MAGIC_HANDLING`
* Enables magic configuration handling for advanced keycodes (such as Mod Tap and Layer Tap)
## RGB Light Configuration

View File

@ -16,14 +16,12 @@
#include "keycode_config.h"
extern keymap_config_t keymap_config;
/** \brief keycode_config
*
* This function is used to check a specific keycode against the bootmagic config,
* and will return the corrected keycode, when appropriate.
*/
uint16_t keycode_config(uint16_t keycode) {
__attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
switch (keycode) {
case KC_CAPS_LOCK:
case KC_LOCKING_CAPS_LOCK:
@ -123,7 +121,7 @@ uint16_t keycode_config(uint16_t keycode) {
* and will remove or replace mods, based on that.
*/
uint8_t mod_config(uint8_t mod) {
__attribute__((weak)) uint8_t mod_config(uint8_t mod) {
if (keymap_config.swap_lalt_lgui) {
if ((mod & MOD_RGUI) == MOD_LGUI) {
mod &= ~MOD_LGUI;

View File

@ -74,11 +74,19 @@ action_t action_for_keycode(uint16_t keycode) {
case QK_MODS ... QK_MODS_MAX:;
// Has a modifier
// Split it up
#ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_KEY(QK_MODS_GET_MODS(keycode), QK_MODS_GET_BASIC_KEYCODE(keycode)); // adds modifier to key
#else // LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_KEY(mod_config(QK_MODS_GET_MODS(keycode)), keycode_config(QK_MODS_GET_BASIC_KEYCODE(keycode))); // adds modifier to key
#endif // LEGACY_MAGIC_HANDLING
break;
#ifndef NO_ACTION_LAYER
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
# ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION_LAYER_TAP_KEY(QK_LAYER_TAP_GET_LAYER(keycode), QK_LAYER_TAP_GET_TAP_KEYCODE(keycode));
# else // LEGACY_MAGIC_HANDLING
action.code = ACTION_LAYER_TAP_KEY(QK_LAYER_TAP_GET_LAYER(keycode), keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode)));
# endif // LEGACY_MAGIC_HANDLING
break;
case QK_TO ... QK_TO_MAX:;
// Layer set "GOTO"
@ -126,12 +134,20 @@ action_t action_for_keycode(uint16_t keycode) {
#ifndef NO_ACTION_TAPPING
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
mod = mod_config(QK_MOD_TAP_GET_MODS(keycode));
# ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_TAP_KEY(mod, QK_MOD_TAP_GET_TAP_KEYCODE(keycode));
# else // LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_TAP_KEY(mod, keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode)));
# endif // LEGACY_MAGIC_HANDLING
break;
#endif
#ifdef SWAP_HANDS_ENABLE
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
# ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION(ACT_SWAP_HANDS, QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode));
# else // LEGACY_MAGIC_HANDLING
action.code = ACTION(ACT_SWAP_HANDS, keycode_config(QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode)));
# endif // LEGACY_MAGIC_HANDLING
break;
#endif