From b7dc2eb9ab2bb3c6ac9ac8e975728002e0e9d62d Mon Sep 17 00:00:00 2001 From: Manna Harbour <51143715+manna-harbour@users.noreply.github.com> Date: Fri, 3 Jul 2020 06:54:15 +1000 Subject: [PATCH] Add movement hook to ps2_mouse (#8805) Process mouse movement in the keymap before it is sent to the host. Example uses include filtering noise, adding acceleration, and automatically activating a layer. To use, define the following function in your keymap: void ps2_mouse_moved_user(report_mouse_t *mouse_report); --- docs/feature_ps2_mouse.md | 10 ++++++++++ tmk_core/protocol/ps2_mouse.c | 5 +++++ tmk_core/protocol/ps2_mouse.h | 3 +++ 3 files changed, 18 insertions(+) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index c1bd8bff50..e549810855 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -294,3 +294,13 @@ To debug the mouse, add `debug_mouse = true` or enable via bootmagic. #define PS2_MOUSE_DEBUG_HID #define PS2_MOUSE_DEBUG_RAW ``` + +### Movement Hook :id=movement-hook + +Process mouse movement in the keymap before it is sent to the host. Example +uses include filtering noise, adding acceleration, and automatically activating +a layer. To use, define the following function in your keymap: + +```c +void ps2_mouse_moved_user(report_mouse_t *mouse_report); +``` diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index a0e52bc7c3..8df465026b 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -68,6 +68,8 @@ void ps2_mouse_init(void) { __attribute__((weak)) void ps2_mouse_init_user(void) {} +__attribute__((weak)) void ps2_mouse_moved_user(report_mouse_t *mouse_report) {} + void ps2_mouse_task(void) { static uint8_t buttons_prev = 0; extern int tp_buttons; @@ -98,6 +100,9 @@ void ps2_mouse_task(void) { #if PS2_MOUSE_SCROLL_BTN_MASK ps2_mouse_scroll_button_task(&mouse_report); #endif + if (mouse_report.x || mouse_report.y || mouse_report.v) { + ps2_mouse_moved_user(&mouse_report); + } #ifdef PS2_MOUSE_DEBUG_HID // Used to debug the bytes sent to the host ps2_mouse_print_report(&mouse_report); diff --git a/tmk_core/protocol/ps2_mouse.h b/tmk_core/protocol/ps2_mouse.h index 30053ef187..d743fb3d85 100644 --- a/tmk_core/protocol/ps2_mouse.h +++ b/tmk_core/protocol/ps2_mouse.h @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include "debug.h" +#include "report.h" #define PS2_MOUSE_SEND(command, message) \ do { \ @@ -174,4 +175,6 @@ void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution); void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate); +void ps2_mouse_moved_user(report_mouse_t *mouse_report); + #endif