diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/quantum.c | 32 | ||||
-rw-r--r-- | quantum/quantum.h | 2 |
2 files changed, 24 insertions, 10 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index 8c928441c5..48c338fc85 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -225,27 +225,39 @@ static uint16_t scs_timer[2] = {0, 0}; */ static bool grave_esc_was_shifted = false; -bool process_record_quantum(keyrecord_t *record) { +/* Convert record into usable keycode via the contained event. */ +uint16_t get_record_keycode(keyrecord_t *record) { + return get_event_keycode(record->event); +} - /* This gets the keycode from the key pressed */ - keypos_t key = record->event.key; - uint16_t keycode; + +/* Convert event into usable keycode. Checks the layer cache to ensure that it + * retains the correct keycode after a layer change, if the key is still pressed. + */ +uint16_t get_event_keycode(keyevent_t event) { #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { uint8_t layer; - if (record->event.pressed) { - layer = layer_switch_get_layer(key); - update_source_layers_cache(key, layer); + if (event.pressed) { + layer = layer_switch_get_layer(event.key); + update_source_layers_cache(event.key, layer); } else { - layer = read_source_layers_cache(key); + layer = read_source_layers_cache(event.key); } - keycode = keymap_key_to_keycode(layer, key); + return keymap_key_to_keycode(layer, event.key); } else #endif - keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); + return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); +} + +/* Main keycode processing function. Hands off handling to other functions, + * then processes internal Quantum keycodes, then processes ACTIONs. + */ +bool process_record_quantum(keyrecord_t *record) { + uint16_t keycode = get_record_keycode(record); // This is how you use actions here // if (keycode == KC_LEAD) { diff --git a/quantum/quantum.h b/quantum/quantum.h index c12ac9ab8a..d0b2bedb1b 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -224,6 +224,8 @@ void matrix_init_kb(void); void matrix_scan_kb(void); void matrix_init_user(void); void matrix_scan_user(void); +uint16_t get_record_keycode(keyrecord_t *record); +uint16_t get_event_keycode(keyevent_t event); bool process_action_kb(keyrecord_t *record); bool process_record_kb(uint16_t keycode, keyrecord_t *record); bool process_record_user(uint16_t keycode, keyrecord_t *record); |