From 7cd04d97b51b4e47e8175bcd29bf3d4460e5d298 Mon Sep 17 00:00:00 2001 From: Oleg Kostyuk Date: Wed, 23 Apr 2014 01:20:50 +0300 Subject: [PATCH] Added support for per-layer FN-translations --- keyboard/ergodox/.gitignore | 1 + keyboard/ergodox/keymap.c | 6 ++ keyboard/ergodox/keymap_cub.h | 61 +++++++++++++++++++-- keyboard/ergodox/keymap_passwords_example.h | 23 ++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 keyboard/ergodox/.gitignore create mode 100644 keyboard/ergodox/keymap_passwords_example.h diff --git a/keyboard/ergodox/.gitignore b/keyboard/ergodox/.gitignore new file mode 100644 index 0000000..65198a9 --- /dev/null +++ b/keyboard/ergodox/.gitignore @@ -0,0 +1 @@ +keymap_passwords.h diff --git a/keyboard/ergodox/keymap.c b/keyboard/ergodox/keymap.c index d0c1c72..6a1e4d6 100644 --- a/keyboard/ergodox/keymap.c +++ b/keyboard/ergodox/keymap.c @@ -218,6 +218,11 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) } } +#if defined(KEYMAP_CUB) + +// function keymap_fn_to_action will be defined in keymap_cub.h + +#else /* translates Fn keycode to action */ action_t keymap_fn_to_action(uint8_t keycode) { @@ -229,4 +234,5 @@ action_t keymap_fn_to_action(uint8_t keycode) } return action; } +#endif diff --git a/keyboard/ergodox/keymap_cub.h b/keyboard/ergodox/keymap_cub.h index cfe0b29..c0fbd66 100644 --- a/keyboard/ergodox/keymap_cub.h +++ b/keyboard/ergodox/keymap_cub.h @@ -251,8 +251,8 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KEYMAP( // Layer7: F-keys only, leftled:top/white // left hand - TRNS,NO, NO, NO, NO, NO, NO, - TRNS,F13, F14, F15, F16, NO, TRNS, + FN0, NO, NO, NO, NO, NO, NO, + FN1, F13, F14, F15, F16, NO, FN23, TRNS,F17, F18, F19, F20, NO, TRNS,F21, F22, F23, F24, NO, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS, @@ -261,7 +261,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TRNS,TRNS,TRNS, // right hand NO, NO, NO, NO, NO, NO, TRNS, - TRNS,NO, F1, F2, F3, F4, TRNS, + FN23,NO, F1, F2, F3, F4, TRNS, NO, F5, F6, F7, F8, TRNS, TRNS,NO, F9, F10, F11, F12, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS, @@ -339,7 +339,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; -/* id for user defined functions */ +/* id for user defined functions & macros */ enum function_id { TEENSY_KEY, CUSTOM_KEY, @@ -347,6 +347,13 @@ enum function_id { R_CTRL_ALT_ENT, }; +enum macro_id { + XMONAD_RESET, + PASSWORD1, + PASSWORD2, + PASSWORD3, +}; + /* * Fn action definition */ @@ -397,6 +404,13 @@ static const uint16_t PROGMEM fn_actions[] = { [27] = ACTION_LAYER_TAP_KEY(2, KC_V), // FN27 = momentary Layer2 on V key, to use with Numpad keys }; +static const uint16_t PROGMEM fn_actions_7[] = { + [0] = ACTION_MACRO(XMONAD_RESET), // FN0 = xmonad-reanimator + [1] = ACTION_MACRO(PASSWORD1), // FN1 = default password + [2] = ACTION_MACRO(PASSWORD1), // FN2 = other password + [3] = ACTION_MACRO(PASSWORD1), // FN3 = mega password +}; + void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { // print("action_function called\n"); @@ -482,3 +496,42 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) } +#include "keymap_passwords.h" +const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { + if (record->event.pressed) { + switch (id) { + case XMONAD_RESET: return MACRO_XMONAD_RESET; + case PASSWORD1: return MACRO_PASSWORD1; + } + } + return MACRO_NONE; +} + +#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) +#define FN_ACTIONS_7_SIZE (sizeof(fn_actions_7) / sizeof(fn_actions_7[0])) + +/* + * translates Fn keycode to action + * for some layers, use different translation table + */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + uint8_t layer = biton32(layer_state); + + action_t action; + action.code = ACTION_NO; + + if (layer == 7 && FN_INDEX(keycode) < FN_ACTIONS_7_SIZE) { + action.code = pgm_read_word(&fn_actions_7[FN_INDEX(keycode)]); + } + + // by default, use fn_actions from default layer 0 + // this is needed to get mapping for same key, that was used switch to some layer, + // to have possibility to switch layers back + if (action.code == ACTION_NO && FN_INDEX(keycode) < FN_ACTIONS_SIZE) { + action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); + } + + return action; +} + diff --git a/keyboard/ergodox/keymap_passwords_example.h b/keyboard/ergodox/keymap_passwords_example.h new file mode 100644 index 0000000..ed53b99 --- /dev/null +++ b/keyboard/ergodox/keymap_passwords_example.h @@ -0,0 +1,23 @@ +#define MACRO_XMONAD_RESET MACRO( \ + I(15), \ + D(LCTL), D(LALT), T(F2), W(255), U(LALT), U(LCTL), W(255), \ + T(X), T(M), T(O), T(N), T(UP), T(ENT), W(255), \ + D(LCTL), D(LALT), T(F5), W(255), U(LALT), U(LCTL), W(255), \ + END) \ + +#define MACRO_PASSWORD1 MACRO( \ + I(15), \ + T(E), T(X), T(A), T(M), T(P), T(L), T(E), \ + END) \ + +#define MACRO_PASSWORD2 MACRO( \ + I(15), \ + T(E), T(X), T(A), T(M), T(P), T(L), T(E), \ + END) \ + +#define MACRO_PASSWORD2 MACRO( \ + I(15), \ + T(E), T(X), T(A), T(M), T(P), T(L), T(E), \ + END) \ + + -- 2.39.2