From b47f179a4a331240874b3c9664dc0bc334b42220 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 12 Feb 2023 09:48:14 -0800 Subject: [PATCH] Make Magic handling more consistent in Action Keycode handling (#9126) Co-authored-by: Ryan --- docs/config_options.md | 3 +++ quantum/keycode_config.c | 6 ++---- quantum/keymap_common.c | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/config_options.md b/docs/config_options.md index f8b31ccb5b..5bfb7c5d58 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -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 diff --git a/quantum/keycode_config.c b/quantum/keycode_config.c index 5b5cc5d28e..9dd7097c86 100644 --- a/quantum/keycode_config.c +++ b/quantum/keycode_config.c @@ -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; diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index c4336440f9..f4982e8291 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -72,13 +72,21 @@ action_t action_for_keycode(uint16_t keycode) { action.code = ACTION_TRANSPARENT; break; case QK_MODS ... QK_MODS_MAX:; - // Has a modifier - // Split it up + // 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" @@ -125,13 +133,21 @@ action_t action_for_keycode(uint16_t keycode) { #endif #ifndef NO_ACTION_TAPPING case QK_MOD_TAP ... QK_MOD_TAP_MAX: - mod = mod_config(QK_MOD_TAP_GET_MODS(keycode)); + 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