From 0c25c62a6dc53ab229c6d1dd1aa179943c3baf27 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 27 Nov 2023 02:15:05 +0900 Subject: [PATCH] core: Fix bootmagic keymap_config for unimap --- tmk_core/common/action_layer.c | 104 ++++++++++++++++++++++++++++++++- tmk_core/common/command.c | 2 +- tmk_core/common/keymap.c | 69 ---------------------- 3 files changed, 104 insertions(+), 71 deletions(-) diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index be316697..6a1b5f3d 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -142,6 +142,108 @@ static uint8_t current_layer_for_key(keypos_t key) } +#ifdef BOOTMAGIC_ENABLE +#include "keymap.h" +extern keymap_config_t keymap_config; + +static uint8_t config_keymap(uint8_t keycode) +{ + switch (keycode) { + case KC_CAPSLOCK: + case KC_LOCKING_CAPS: + if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) { + return KC_LCTL; + } + return keycode; + case KC_LCTL: + if (keymap_config.swap_control_capslock) { + return KC_CAPSLOCK; + } + return KC_LCTL; + case KC_LALT: + if (keymap_config.swap_lalt_lgui) { + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_LGUI; + } + return KC_LALT; + case KC_LGUI: + if (keymap_config.swap_lalt_lgui) { + return KC_LALT; + } + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_LGUI; + case KC_RALT: + if (keymap_config.swap_ralt_rgui) { + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_RGUI; + } + return KC_RALT; + case KC_RGUI: + if (keymap_config.swap_ralt_rgui) { + return KC_RALT; + } + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_RGUI; + case KC_GRAVE: + if (keymap_config.swap_grave_esc) { + return KC_ESC; + } + return KC_GRAVE; + case KC_ESC: + if (keymap_config.swap_grave_esc) { + return KC_GRAVE; + } + return KC_ESC; + case KC_BSLASH: + if (keymap_config.swap_backslash_backspace) { + return KC_BSPACE; + } + return KC_BSLASH; + case KC_BSPACE: + if (keymap_config.swap_backslash_backspace) { + return KC_BSLASH; + } + return KC_BSPACE; + default: + return keycode; + } +} + +static action_t get_action(uint8_t layer, keypos_t key) +{ + action_t act = action_for_key(layer, key); + switch (act.kind.id) { + case ACT_LMODS: + case ACT_RMODS: + case ACT_LMODS_TAP: + case ACT_RMODS_TAP: + act.key.code = config_keymap(act.key.code); + break; + case ACT_LAYER_TAP: + case ACT_LAYER_TAP_EXT: + act.layer_tap.code = config_keymap(act.layer_tap.code); + break; + default: + break; + } + return act; +} +#else +static action_t get_action(uint8_t layer, keypos_t key) +{ + return action_for_key(layer, key); +} +#endif + + #ifndef NO_TRACK_KEY_PRESS /* record layer on where key is pressed */ static uint8_t layer_pressed[MATRIX_ROWS][MATRIX_COLS] = {}; @@ -161,5 +263,5 @@ action_t layer_switch_get_action(keyevent_t event) #else layer = current_layer_for_key(event.key); #endif - return action_for_key(layer, event.key); + return get_action(layer, event.key); } diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index b93c8248..b429a181 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -19,7 +19,6 @@ along with this program. If not, see . #include "wait.h" #include "keycode.h" #include "host.h" -#include "keymap.h" #include "print.h" #include "debug.h" #include "util.h" @@ -145,6 +144,7 @@ static void command_common_help(void) } #ifdef BOOTMAGIC_ENABLE +#include "keymap.h" __attribute__ ((weak)) void eeconfig_debug(void) {} static void print_eeconfig(void) diff --git a/tmk_core/common/keymap.c b/tmk_core/common/keymap.c index 2bd4a253..1ea1dd8b 100644 --- a/tmk_core/common/keymap.c +++ b/tmk_core/common/keymap.c @@ -27,10 +27,6 @@ along with this program. If not, see . #include #endif -#ifdef BOOTMAGIC_ENABLE -extern keymap_config_t keymap_config; -#endif - static action_t keycode_to_action(uint8_t keycode); @@ -42,71 +38,6 @@ action_t action_for_key(uint8_t layer, keypos_t key) switch (keycode) { case KC_FN0 ... KC_FN31: return keymap_fn_to_action(keycode); -#ifdef BOOTMAGIC_ENABLE - case KC_CAPSLOCK: - case KC_LOCKING_CAPS: - if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) { - return keycode_to_action(KC_LCTL); - } - return keycode_to_action(keycode); - case KC_LCTL: - if (keymap_config.swap_control_capslock) { - return keycode_to_action(KC_CAPSLOCK); - } - return keycode_to_action(KC_LCTL); - case KC_LALT: - if (keymap_config.swap_lalt_lgui) { - if (keymap_config.no_gui) { - return keycode_to_action(KC_NO); - } - return keycode_to_action(KC_LGUI); - } - return keycode_to_action(KC_LALT); - case KC_LGUI: - if (keymap_config.swap_lalt_lgui) { - return keycode_to_action(KC_LALT); - } - if (keymap_config.no_gui) { - return keycode_to_action(KC_NO); - } - return keycode_to_action(KC_LGUI); - case KC_RALT: - if (keymap_config.swap_ralt_rgui) { - if (keymap_config.no_gui) { - return keycode_to_action(KC_NO); - } - return keycode_to_action(KC_RGUI); - } - return keycode_to_action(KC_RALT); - case KC_RGUI: - if (keymap_config.swap_ralt_rgui) { - return keycode_to_action(KC_RALT); - } - if (keymap_config.no_gui) { - return keycode_to_action(KC_NO); - } - return keycode_to_action(KC_RGUI); - case KC_GRAVE: - if (keymap_config.swap_grave_esc) { - return keycode_to_action(KC_ESC); - } - return keycode_to_action(KC_GRAVE); - case KC_ESC: - if (keymap_config.swap_grave_esc) { - return keycode_to_action(KC_GRAVE); - } - return keycode_to_action(KC_ESC); - case KC_BSLASH: - if (keymap_config.swap_backslash_backspace) { - return keycode_to_action(KC_BSPACE); - } - return keycode_to_action(KC_BSLASH); - case KC_BSPACE: - if (keymap_config.swap_backslash_backspace) { - return keycode_to_action(KC_BSLASH); - } - return keycode_to_action(KC_BSPACE); -#endif default: return keycode_to_action(keycode); }