X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Fkeymap.c;h=ace3f49b69c01303a9a601b7f097086c4ec9b214;hb=0142e20bf0012eada5ba40caaa63466bfbb095a2;hp=ddc321052479756f2b0ec3333966048ced9568e3;hpb=c3d57b69e02fce40455c96f4a9ac6b68b89ce027;p=max%2Ftmk_keyboard.git diff --git a/common/keymap.c b/common/keymap.c index ddc32105..ace3f49b 100644 --- a/common/keymap.c +++ b/common/keymap.c @@ -20,12 +20,13 @@ along with this program. If not, see . #include "keycode.h" #include "layer_switch.h" #include "action.h" +#include "action_macro.h" #include "debug.h" static action_t keycode_to_action(uint8_t keycode); -#ifdef USE_KEYMAP_V2 + /* converts key to action */ action_t action_for_key(uint8_t layer, key_t key) { @@ -38,42 +39,19 @@ action_t action_for_key(uint8_t layer, key_t key) } } + +/* Macro */ __attribute__ ((weak)) -void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) +const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { + return MACRO_NONE; } -#else -/* - * legacy keymap support - */ -/* translation for legacy keymap */ -action_t action_for_key(uint8_t layer, key_t key) -{ - /* convert from legacy keycode to action */ - /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */ - uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col); - action_t action; - switch (keycode) { - case KC_FN0 ... KC_FN31: - { - uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); - uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); - if (key) { - action.code = ACTION_KEYMAP_TAP_KEY(layer, key); - } else { - action.code = ACTION_KEYMAP_MOMENTARY(layer); - } - } - return action; - default: - return keycode_to_action(keycode); - } -} -/* not used for legacy keymap */ + +/* Function */ +__attribute__ ((weak)) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { } -#endif @@ -83,14 +61,9 @@ static action_t keycode_to_action(uint8_t keycode) action_t action; switch (keycode) { case KC_A ... KC_EXSEL: + case KC_LCTRL ... KC_RGUI: action.code = ACTION_KEY(keycode); break; - case KC_LCTRL ... KC_LGUI: - action.code = ACTION_LMOD(keycode); - break; - case KC_RCTRL ... KC_RGUI: - action.code = ACTION_RMOD(keycode); - break; case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); break; @@ -109,3 +82,40 @@ static action_t keycode_to_action(uint8_t keycode) } return action; } + + + +#ifdef USE_LEGACY_KEYMAP +/* + * Legacy keymap support + * Consider using new keymap API instead. + */ +__attribute__ ((weak)) +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ + return keymap_get_keycode(layer, key.row, key.col); +} + + +/* Legacy keymap support */ +__attribute__ ((weak)) +action_t keymap_fn_to_action(uint8_t keycode) +{ + action_t action = { .code = ACTION_NO }; + switch (keycode) { + case KC_FN0 ... KC_FN31: + { + uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); + uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); + if (key) { + action.code = ACTION_KEYMAP_TAP_KEY(layer, key); + } else { + action.code = ACTION_KEYMAP_MOMENTARY(layer); + } + } + return action; + default: + return action; + } +} +#endif