From: tmk Date: Wed, 29 May 2019 05:08:03 +0000 (+0900) Subject: core: Add hook_process_action() X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=2b83b9a8f9c6bd0ca5026f62495838dc55cbacf3;p=max%2Ftmk_keyboard.git core: Add hook_process_action() --- diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index 9b139d48..c256892c 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -58,6 +58,8 @@ void action_exec(keyevent_t event) void process_action(keyrecord_t *record) { + if (hook_process_action(record)) return; + keyevent_t event = record->event; #ifndef NO_ACTION_TAPPING uint8_t tap_count = record->tap.count; diff --git a/tmk_core/common/hook.c b/tmk_core/common/hook.c index 4ed2403c..22be9a30 100644 --- a/tmk_core/common/hook.c +++ b/tmk_core/common/hook.c @@ -47,3 +47,8 @@ void hook_keyboard_leds_change(uint8_t led_status) { __attribute__((weak)) void hook_bootmagic(void) {} + +__attribute__((weak)) +bool hook_process_action(keyrecord_t *record) { + return false; +} diff --git a/tmk_core/common/hook.h b/tmk_core/common/hook.h index 140e2779..ddd05c6f 100644 --- a/tmk_core/common/hook.h +++ b/tmk_core/common/hook.h @@ -20,6 +20,7 @@ along with this program. If not, see . #include "keyboard.h" #include "led.h" +#include "action.h" #ifdef __cplusplus extern "C" { @@ -84,6 +85,10 @@ void hook_keyboard_leds_change(uint8_t led_status); /* Default behaviour: do nothing. */ void hook_bootmagic(void); +/* Called on before processing key event */ +/* returns true if the event is consumed and default action is not needed. */ +bool hook_process_action(keyrecord_t *record); + #ifdef __cplusplus } #endif diff --git a/tmk_core/doc/hook.txt b/tmk_core/doc/hook.md similarity index 54% rename from tmk_core/doc/hook.txt rename to tmk_core/doc/hook.md index acd77cce..0cebf858 100644 --- a/tmk_core/doc/hook.txt +++ b/tmk_core/doc/hook.md @@ -6,19 +6,19 @@ The following hooks are available available: Hook function | Timing --------------------------------|----------------------------------------------- -`hook_early_init(void)` | Early in the boot process, before the matrix is initialized and before a connection is made with the host. Thus, this hook has access to very few parameters, but it is a good place to define any custom parameters needed by other early processes. -`hook_late_init(void)` | Near the end of the boot process, after Boot Magic has run and LEDs have been initialized. -`hook_bootmagic(void)` | During the Boot Magic window, after EEPROM and Bootloader checks are made, but before any other built-in Boot Magic checks are made. -`hook_usb_startup_wait_loop(void)` | Continuously, until the device gets ready and into USB configured state. - -`hook_usb_wakeup(void)` | When the device wakes up from USB suspend state. -`hook_usb_suspend_entry(void)` | When the device enters USB suspend state. -`hook_usb_suspend_loop(void)` | Continuously, while the device is in USB suspend state. *Default action:* power down and periodically check the matrix, causing wakeup if needed. -`hook_keyboard_loop(void)` | Continuously, during the main loop, after the matrix is checked. -`hook_matrix_change(keyevent_t event)` | When a matrix state change is detected, before any other actions are processed. -`hook_layer_change(uint32_t layer_state)` | When any layer is changed. -`hook_default_layer_change(uint32_t default_layer_state)` | When any default layer is changed. -`hook_keyboard_leds_change(uint8_t led_status)` | Whenever a change in the LED status is performed. *Default action:* call `keyboard_set_leds(led_status)` +`void hook_early_init(void)` | Early in the boot process, before the matrix is initialized and before a connection is made with the host. Thus, this hook has access to very few parameters, but it is a good place to define any custom parameters needed by other early processes. +`void hook_late_init(void)` | Near the end of the boot process, after Boot Magic has run and LEDs have been initialized. +`void hook_bootmagic(void)` | During the Boot Magic window, after EEPROM and Bootloader checks are made, but before any other built-in Boot Magic checks are made. +`void hook_usb_startup_wait_loop(void)` | Continuously, until the device gets ready and into USB configured state. +`void hook_usb_wakeup(void)` | When the device wakes up from USB suspend state. +`void hook_usb_suspend_entry(void)` | When the device enters USB suspend state. +`void hook_usb_suspend_loop(void)` | Continuously, while the device is in USB suspend state. *Default action:* power down and periodically check the matrix, causing wakeup if needed. +`void hook_keyboard_loop(void)` | Continuously, during the main loop, after the matrix is checked. +`void hook_matrix_change(keyevent_t event)` | When a matrix state change is detected, before any other actions are processed. +`void hook_layer_change(uint32_t layer_state)` | When any layer is changed. +`void hook_default_layer_change(uint32_t default_layer_state)` | When any default layer is changed. +`void hook_keyboard_leds_change(uint8_t led_status)` | Whenever a change in the LED status is performed. *Default action:* call `keyboard_set_leds(led_status)` +`bool hook_process_action(keyrecord_t *record)` | Before key event is processed by tmk_core. Return true if the event is consumed and default action is not needed.