Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Magic handling more consistent in Action Keycode handling #9126

Merged
merged 9 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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

Expand Down
6 changes: 2 additions & 4 deletions quantum/keycode_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down