mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-16 21:01:31 +00:00
opt in option, move to store_or_get_action
This commit is contained in:
parent
1dc3373fda
commit
f512383a6e
@ -144,6 +144,8 @@ If you define these options you will enable the associated feature, which may in
|
||||
* NKRO by default requires to be turned on, this forces it on during keyboard startup regardless of EEPROM setting. NKRO can still be turned off but will be turned on again if the keyboard reboots.
|
||||
* `#define STRICT_LAYER_RELEASE`
|
||||
* force a key release to be evaluated using the current layer stack instead of remembering which layer it came from (used for advanced cases)
|
||||
* `#define KEYCODE_CACHE_ENABLE`
|
||||
* Cache keycode for pressed keys, to be used on key release, across entire physical keyboard layout.
|
||||
|
||||
## Behaviors That Can Be Configured
|
||||
|
||||
|
@ -288,10 +288,11 @@ uint8_t read_source_layers_cache(keypos_t key) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
# ifdef KEYCODE_CACHE_ENABLE
|
||||
uint16_t keycode_map[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)][16] = {{KC_NO}};
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
uint16_t encoder_keycode_map[(NUM_ENCODERS + (CHAR_BIT)-1) / (CHAR_BIT)][16] = {{KC_NO}};
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
|
||||
/** \brief update keycode map
|
||||
*
|
||||
@ -318,12 +319,12 @@ void update_keycode_map(keypos_t key, uint16_t keycode) {
|
||||
const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col;
|
||||
update_keycode_map_impl(entry_number, keycode, keycode_map);
|
||||
}
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) {
|
||||
const uint16_t entry_number = key.col;
|
||||
update_keycode_map_impl(entry_number, keycode, encoder_keycode_map);
|
||||
}
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
}
|
||||
|
||||
/** \brief read keycode map
|
||||
@ -335,14 +336,15 @@ uint16_t read_keycode_map(keypos_t key) {
|
||||
const uint16_t entry_number = (uint16_t)(key.row * MATRIX_COLS) + key.col;
|
||||
return read_keycode_map_impl(entry_number, keycode_map);
|
||||
}
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
# ifdef ENCODER_MAP_ENABLE
|
||||
else if (key.row == KEYLOC_ENCODER_CW || key.row == KEYLOC_ENCODER_CCW) {
|
||||
const uint16_t entry_number = key.col;
|
||||
return read_keycode_map_impl(entry_number, encoder_keycode_map);
|
||||
}
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
# endif // ENCODER_MAP_ENABLE
|
||||
return KC_NO;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/** \brief Store or get action (FIXME: Needs better summary)
|
||||
@ -359,14 +361,27 @@ action_t store_or_get_action(bool pressed, keypos_t key) {
|
||||
}
|
||||
|
||||
uint8_t layer;
|
||||
|
||||
# ifdef KEYCODE_CACHE_ENABLE
|
||||
uint16_t keycode;
|
||||
# endif
|
||||
if (pressed) {
|
||||
layer = layer_switch_get_layer(key);
|
||||
update_source_layers_cache(key, layer);
|
||||
# ifdef KEYCODE_CACHE_ENABLE
|
||||
keycode = keymap_key_to_keycode(layer, key);
|
||||
update_keycode_map(key, keycode);
|
||||
# endif
|
||||
} else {
|
||||
layer = read_source_layers_cache(key);
|
||||
# ifdef KEYCODE_CACHE_ENABLE
|
||||
keycode = read_keycode_map(key);
|
||||
# endif
|
||||
}
|
||||
# ifndef KEYCODE_CACHE_ENABLE
|
||||
return action_for_key(layer, key);
|
||||
# else
|
||||
return action_for_keycode(keycode);
|
||||
# endif
|
||||
#else
|
||||
return layer_switch_get_action(key);
|
||||
#endif
|
||||
|
@ -160,8 +160,11 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
|
||||
|
||||
void update_source_layers_cache(keypos_t key, uint8_t layer);
|
||||
uint8_t read_source_layers_cache(keypos_t key);
|
||||
void update_keycode_map(keypos_t key, uint16_t keycode);
|
||||
# ifdef KEYCODE_CACHE_ENABLE
|
||||
void update_keycode_map(keypos_t key, uint16_t keycode);
|
||||
uint16_t read_keycode_map(keypos_t key);
|
||||
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
|
||||
# endif
|
||||
#endif
|
||||
action_t store_or_get_action(bool pressed, keypos_t key);
|
||||
|
||||
|
@ -231,17 +231,14 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
|
||||
/* TODO: Use store_or_get_action() or a similar function. */
|
||||
if (!disable_action_cache) {
|
||||
uint8_t layer;
|
||||
uint16_t keycode;
|
||||
|
||||
if (event.pressed && update_layer_cache) {
|
||||
layer = layer_switch_get_layer(event.key);
|
||||
update_source_layers_cache(event.key, layer);
|
||||
keycode = keymap_key_to_keycode(layer, event.key);
|
||||
update_keycode_map(event.key, keycode);
|
||||
} else {
|
||||
keycode = read_keycode_map(event.key);
|
||||
layer = read_source_layers_cache(event.key);
|
||||
}
|
||||
return keycode;
|
||||
return keymap_key_to_keycode(layer, event.key);
|
||||
} else
|
||||
#endif
|
||||
return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
|
||||
|
Loading…
Reference in New Issue
Block a user