diff options
author | Drashna Jaelre <drashna@live.com> | 2020-03-22 06:29:05 -0700 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2020-06-12 17:00:27 +0900 |
commit | a4fcea7a9045d6f31ffaec3bb8131a7c11f29a70 (patch) | |
tree | ec89c174497a6a00a3e621b37e62b803b36e022b | |
parent | 63df792fcc1b600e24c12102ce7f719d0ca9b09a (diff) |
Add Post Processing to process_record (#4892)
* Improve process_record system
Code based on @colinta's
* Rename and better handle functions
* Fix incorrect function call to process_record_user
* Add documentation for post_process_record
* Add both get_event_keycode and get_record_keycode functions
And add some comments about these functions
* Update code format
* Cleanup merge artifacts
-rw-r--r-- | quantum/quantum.c | 20 | ||||
-rw-r--r-- | quantum/quantum.h | 2 | ||||
-rw-r--r-- | tmk_core/common/action.c | 8 | ||||
-rw-r--r-- | tmk_core/common/action.h | 2 |
4 files changed, 26 insertions, 6 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index b31c98852c..354fa480bb 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -117,6 +117,10 @@ __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *reco __attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } +__attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) { post_process_record_user(keycode, record); } + +__attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {} + void reset_keyboard(void) { clear_keyboard(); #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) @@ -169,9 +173,15 @@ uint16_t get_event_keycode(keyevent_t event) { 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. - */ +/* Get keycode, and then call keyboard function */ +void post_process_record_quantum(keyrecord_t *record) { + uint16_t keycode = get_record_keycode(record); + post_process_record_kb(keycode, record); +} + +/* Core keycode function, hands off handling to other functions, + then processes internal quantum keycodes, and then processes + ACTIONs. */ bool process_record_quantum(keyrecord_t *record) { uint16_t keycode = get_record_keycode(record); @@ -191,7 +201,7 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef WPM_ENABLE if (record->event.pressed) { - update_wpm(keycode); + update_wpm(keycode); } #endif @@ -665,7 +675,7 @@ void matrix_scan_quantum() { #endif #ifdef WPM_ENABLE - decay_wpm(); + decay_wpm(); #endif #ifdef HAPTIC_ENABLE diff --git a/quantum/quantum.h b/quantum/quantum.h index e811616f0e..06450e67a6 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -266,6 +266,8 @@ 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); +void post_process_record_kb(uint16_t keycode, keyrecord_t *record); +void post_process_record_user(uint16_t keycode, keyrecord_t *record); #ifndef BOOTMAGIC_LITE_COLUMN # define BOOTMAGIC_LITE_COLUMN 0 diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 174faf856a..19c3569d55 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -151,6 +151,8 @@ void process_record_nocache(keyrecord_t *record) { process_record(record); } __attribute__((weak)) bool process_record_quantum(keyrecord_t *record) { return true; } +__attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {} + #ifndef NO_ACTION_TAPPING /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress. * @@ -185,6 +187,11 @@ void process_record(keyrecord_t *record) { if (!process_record_quantum(record)) return; + process_record_handler(record); + post_process_record_quantum(record); +} + +void process_record_handler(keyrecord_t *record) { action_t action = store_or_get_action(record->event.pressed, record->event.key); dprint("ACTION: "); debug_action(action); @@ -988,7 +995,6 @@ bool is_tap_action(action_t action) { * FIXME: Needs documentation. */ void debug_event(keyevent_t event) { dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); } - /** \brief Debug print (FIXME: Needs better description) * * FIXME: Needs documentation. diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 15f4ce15c0..dd22023f9b 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -84,6 +84,8 @@ void process_hand_swap(keyevent_t *record); void process_record_nocache(keyrecord_t *record); void process_record(keyrecord_t *record); +void process_record_handler(keyrecord_t *record); +void post_process_record_quantum(keyrecord_t *record); void process_action(keyrecord_t *record, action_t action); void register_code(uint8_t code); void unregister_code(uint8_t code); |