Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a user callback for pre process record #20584

Merged
merged 7 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/understanding_qmk.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ The `process_record()` function itself is deceptively simple, but hidden within
* [`void action_exec(keyevent_t event)`](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/action.c#L78-L140)
* [`void pre_process_record_quantum(keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/quantum.c#L204)
* [`bool process_combo(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/process_keycode/process_combo.c#L521)
* [`bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/27119fa77e8a1b95fff80718d3db4f3e32849298/quantum/quantum.c#L117)
* [`bool pre_process_record_user(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/27119fa77e8a1b95fff80718d3db4f3e32849298/quantum/quantum.c#L121)
* [`void process_record(keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/action.c#L254)
* [`bool process_record_quantum(keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/quantum.c#L224)
* [Map this record to a keycode](https://github.com/qmk/qmk_firmware/blob/325da02e57fe7374e77b82cb00360ba45167e25c/quantum/quantum.c#L225)
Expand Down
5 changes: 1 addition & 4 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "wait.h"
#include "keycode_config.h"
#include "debug.h"
#include "quantum.h"

#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
Expand Down Expand Up @@ -65,10 +66,6 @@ __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *reco
}
#endif

__attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) {
return true;
}

/** \brief Called to execute an action.
*
* FIXME: Needs documentation.
Expand Down
17 changes: 12 additions & 5 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ __attribute__((weak)) void tap_code16(uint16_t code) {
tap_code16_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY);
}

__attribute__((weak)) bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record) {
return pre_process_record_user(keycode, record);
}

__attribute__((weak)) bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}

__attribute__((weak)) bool process_action_kb(keyrecord_t *record) {
return true;
}
Expand Down Expand Up @@ -202,14 +210,13 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {

/* Get keycode, and then process pre tapping functionality */
bool pre_process_record_quantum(keyrecord_t *record) {
if (!(
uint16_t keycode = get_record_keycode(record, true);
#ifdef COMBO_ENABLE
process_combo(get_record_keycode(record, true), record) &&
#endif
true)) {
if (!(process_combo(keycode, record))) {
return false;
}
return true; // continue processing
#endif
return pre_process_record_kb(keycode, record);
}

/* Get keycode, and then call keyboard function */
Expand Down
3 changes: 3 additions & 0 deletions quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ void set_single_persistent_default_layer(uint8_t default_layer);

uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
bool pre_process_record_quantum(keyrecord_t *record);
bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record);
bool pre_process_record_user(uint16_t keycode, keyrecord_t *record);
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);
Expand Down
3 changes: 2 additions & 1 deletion tests/basic/test_action_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) {
InSequence s;

KeymapKey layer_0_key_0 = KeymapKey{0, 0, 0, LT(1, KC_T)};
KeymapKey layer_0_key_1 = KeymapKey{0, 1, 0, KC_X};
KeymapKey layer_1_key_1 = KeymapKey{1, 1, 0, RALT(KC_9)};

set_keymap({layer_0_key_0, layer_1_key_1});
set_keymap({layer_0_key_0, layer_0_key_1, layer_1_key_1});

/* Press layer tap and wait for tapping term to switch to layer 1 */
EXPECT_NO_REPORT(driver);
Expand Down