From ef3eb2f329af6f0501951635c199629575325974 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Thu, 27 Apr 2023 11:46:36 +0800 Subject: [PATCH 1/7] Add a user callback for pre process record quantum --- quantum/action.c | 4 ++++ quantum/action.h | 2 ++ quantum/quantum.c | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/quantum/action.c b/quantum/action.c index 9a6bbcca1162..ac3417f3be82 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -66,6 +66,10 @@ __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *reco #endif __attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { + return pre_process_record_quantum_user(record); +} + +__attribute__((weak)) bool pre_process_record_quantum_user(keyrecord_t *record) { return true; } diff --git a/quantum/action.h b/quantum/action.h index 2a2c294c5a9e..6b00d9c4d188 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -107,6 +107,8 @@ bool is_swap_hands_on(void); void process_hand_swap(keyevent_t *record); #endif +bool pre_process_record_quantum(keyrecord_t *record); +bool pre_process_record_quantum_user(keyrecord_t *record); void process_record_nocache(keyrecord_t *record); void process_record(keyrecord_t *record); void process_record_handler(keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index 0587f215fe3a..5477d7f75404 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -209,7 +209,7 @@ bool pre_process_record_quantum(keyrecord_t *record) { true)) { return false; } - return true; // continue processing + return pre_process_record_quantum_user(record); } /* Get keycode, and then call keyboard function */ From 3a9b9fcb0cd8f7eef3936d4b530d8162a5304b74 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:21:04 +0800 Subject: [PATCH 2/7] Move functions into quantum.c with kb and user versions --- quantum/action.c | 9 +-------- quantum/action.h | 2 -- quantum/quantum.c | 10 +++++++++- quantum/quantum.h | 3 +++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/quantum/action.c b/quantum/action.c index ac3417f3be82..1dc3e31746a4 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -30,6 +30,7 @@ along with this program. If not, see . #include "wait.h" #include "keycode_config.h" #include "debug.h" +#include "quantum.h" #ifdef BACKLIGHT_ENABLE # include "backlight.h" @@ -65,14 +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 pre_process_record_quantum_user(record); -} - -__attribute__((weak)) bool pre_process_record_quantum_user(keyrecord_t *record) { - return true; -} - /** \brief Called to execute an action. * * FIXME: Needs documentation. diff --git a/quantum/action.h b/quantum/action.h index 6b00d9c4d188..2a2c294c5a9e 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -107,8 +107,6 @@ bool is_swap_hands_on(void); void process_hand_swap(keyevent_t *record); #endif -bool pre_process_record_quantum(keyrecord_t *record); -bool pre_process_record_quantum_user(keyrecord_t *record); void process_record_nocache(keyrecord_t *record); void process_record(keyrecord_t *record); void process_record_handler(keyrecord_t *record); diff --git a/quantum/quantum.c b/quantum/quantum.c index 5477d7f75404..2b45fe82033b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -132,6 +132,14 @@ __attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t __attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {} +__attribute__((weak)) bool pre_process_record_quantum_kb(keyrecord_t *record) { + return pre_process_record_quantum_user(record); +} + +__attribute__((weak)) bool pre_process_record_quantum_user(keyrecord_t *record) { + return true; +} + void shutdown_quantum(void) { clear_keyboard(); #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) @@ -209,7 +217,7 @@ bool pre_process_record_quantum(keyrecord_t *record) { true)) { return false; } - return pre_process_record_quantum_user(record); + return pre_process_record_quantum_kb(record); } /* Get keycode, and then call keyboard function */ diff --git a/quantum/quantum.h b/quantum/quantum.h index 38186a48a35e..0267e0d83a75 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -266,6 +266,9 @@ 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); +bool pre_process_record_quantum(keyrecord_t *record); +bool pre_process_record_quantum_kb(keyrecord_t *record); +bool pre_process_record_quantum_user(keyrecord_t *record); void reset_keyboard(void); void soft_reset_keyboard(void); From 778d4a5a78e42031accc6fd9944e71b6577758ea Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:20:08 +0800 Subject: [PATCH 3/7] Add documentation and code links --- docs/understanding_qmk.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/understanding_qmk.md b/docs/understanding_qmk.md index 7b436a45beaa..a27043d01572 100644 --- a/docs/understanding_qmk.md +++ b/docs/understanding_qmk.md @@ -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_quantum_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/3a9b9fcb0cd8f7eef3936d4b530d8162a5304b74/quantum/quantum.c#L135) + * [`bool pre_process_record_quantum_user(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/3a9b9fcb0cd8f7eef3936d4b530d8162a5304b74/quantum/quantum.c#L139) * [`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) From b00e9676dd840b1e467f02427ef0da095a2d5227 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:45:02 +0800 Subject: [PATCH 4/7] Re-order function declaration --- quantum/quantum.c | 16 ++++++++-------- quantum/quantum.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 2b45fe82033b..a8d81fe5b2ad 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -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_quantum_kb(keyrecord_t *record) { + return pre_process_record_quantum_user(record); +} + +__attribute__((weak)) bool pre_process_record_quantum_user(keyrecord_t *record) { + return true; +} + __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } @@ -132,14 +140,6 @@ __attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t __attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {} -__attribute__((weak)) bool pre_process_record_quantum_kb(keyrecord_t *record) { - return pre_process_record_quantum_user(record); -} - -__attribute__((weak)) bool pre_process_record_quantum_user(keyrecord_t *record) { - return true; -} - void shutdown_quantum(void) { clear_keyboard(); #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) diff --git a/quantum/quantum.h b/quantum/quantum.h index 0267e0d83a75..ce69b830d1d6 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -261,14 +261,14 @@ 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_quantum_kb(keyrecord_t *record); +bool pre_process_record_quantum_user(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); void post_process_record_kb(uint16_t keycode, keyrecord_t *record); void post_process_record_user(uint16_t keycode, keyrecord_t *record); -bool pre_process_record_quantum(keyrecord_t *record); -bool pre_process_record_quantum_kb(keyrecord_t *record); -bool pre_process_record_quantum_user(keyrecord_t *record); void reset_keyboard(void); void soft_reset_keyboard(void); From 5417e1337b5d304fcda7f82f3b37eaa4f763ce37 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Fri, 28 Apr 2023 08:28:20 +0800 Subject: [PATCH 5/7] Shorten function names, add keycode --- docs/understanding_qmk.md | 4 ++-- quantum/quantum.c | 11 ++++++----- quantum/quantum.h | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/understanding_qmk.md b/docs/understanding_qmk.md index a27043d01572..9c5f0419a116 100644 --- a/docs/understanding_qmk.md +++ b/docs/understanding_qmk.md @@ -130,8 +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_quantum_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/3a9b9fcb0cd8f7eef3936d4b530d8162a5304b74/quantum/quantum.c#L135) - * [`bool pre_process_record_quantum_user(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/3a9b9fcb0cd8f7eef3936d4b530d8162a5304b74/quantum/quantum.c#L139) + * [`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) diff --git a/quantum/quantum.c b/quantum/quantum.c index a8d81fe5b2ad..b358f595d226 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -114,11 +114,11 @@ __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_quantum_kb(keyrecord_t *record) { - return pre_process_record_quantum_user(record); +__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_quantum_user(keyrecord_t *record) { +__attribute__((weak)) bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } @@ -210,14 +210,15 @@ 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) { + uint16_t keycode = get_record_keycode(record, true); if (!( #ifdef COMBO_ENABLE - process_combo(get_record_keycode(record, true), record) && + process_combo(keycode, record) && #endif true)) { return false; } - return pre_process_record_quantum_kb(record); + return pre_process_record_kb(keycode, record); } /* Get keycode, and then call keyboard function */ diff --git a/quantum/quantum.h b/quantum/quantum.h index ce69b830d1d6..fec92a5244a5 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -262,8 +262,8 @@ 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_quantum_kb(keyrecord_t *record); -bool pre_process_record_quantum_user(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); From de2237fcc7448f5eda9cb7984153e30e75125034 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Fri, 28 Apr 2023 16:24:49 +0800 Subject: [PATCH 6/7] Deobfuscate process_combo function call --- quantum/quantum.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index b358f595d226..950be3182e78 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -211,13 +211,11 @@ 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) { uint16_t keycode = get_record_keycode(record, true); - if (!( #ifdef COMBO_ENABLE - process_combo(keycode, record) && -#endif - true)) { + if (!(process_combo(keycode, record))) { return false; } +#endif return pre_process_record_kb(keycode, record); } From 1db77c24b09279065461f9fe0351fe2ac5339463 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Sun, 30 Apr 2023 08:10:40 +0800 Subject: [PATCH 7/7] Add an additional layer 0 unit test key --- tests/basic/test_action_layer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index b7ecfa52ef8e..0aa4b780078f 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp @@ -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);