From e8657afbb623a9b72ac5874afc2376fa960a8b04 Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Mon, 15 Apr 2024 23:36:47 +0900 Subject: [PATCH] Hooks to override applying motion to mouse report for https://github.com/Yowkees/keyball/issues/559 --- keyboards/keyball/lib/keyball/keyball.c | 8 ++++---- keyboards/keyball/lib/keyball/keyball.h | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/keyboards/keyball/lib/keyball/keyball.c b/keyboards/keyball/lib/keyball/keyball.c index cc57e8d26a87..a19d8bc7371c 100644 --- a/keyboards/keyball/lib/keyball/keyball.c +++ b/keyboards/keyball/lib/keyball/keyball.c @@ -166,7 +166,7 @@ void pointing_device_driver_set_cpi(uint16_t cpi) { keyball_set_cpi(cpi); } -static void motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is_left) { +__attribute__((weak)) void keyball_on_apply_motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is_left) { #if KEYBALL_MODEL == 61 || KEYBALL_MODEL == 39 || KEYBALL_MODEL == 147 || KEYBALL_MODEL == 44 r->x = clip2int8(m->y); r->y = clip2int8(m->x); @@ -185,7 +185,7 @@ static void motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is m->y = 0; } -static void motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left) { +__attribute__((weak)) void keyball_on_apply_motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left) { // consume motion of trackball. int16_t div = 1 << (keyball_get_scroll_div() - 1); int16_t x = divmod16(&m->x, div); @@ -223,9 +223,9 @@ static void motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool static void motion_to_mouse(keyball_motion_t *m, report_mouse_t *r, bool is_left, bool as_scroll) { if (as_scroll) { - motion_to_mouse_scroll(m, r, is_left); + keyball_on_apply_motion_to_mouse_scroll(m, r, is_left); } else { - motion_to_mouse_move(m, r, is_left); + keyball_on_apply_motion_to_mouse_move(m, r, is_left); } } diff --git a/keyboards/keyball/lib/keyball/keyball.h b/keyboards/keyball/lib/keyball/keyball.h index 28c5cc0b66fd..7074ed372503 100644 --- a/keyboards/keyball/lib/keyball/keyball.h +++ b/keyboards/keyball/lib/keyball/keyball.h @@ -174,6 +174,22 @@ typedef enum { extern keyball_t keyball; +////////////////////////////////////////////////////////////////////////////// +// Hook points + +/// keyball_on_adjust_layout is called when the keyboard layout adjustted +void keyball_on_adjust_layout(keyball_adjust_t v); + +/// keyball_on_apply_motion_to_mouse_move applies trackball's motion m to r as +/// mouse movement. +/// You can change the default algorithm by override this function. +void keyball_on_apply_motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is_left); + +/// keyball_on_apply_motion_to_mouse_scroll applies trackball's motion m to r +/// as mouse scroll. +/// You can change the default algorithm by override this function. +void keyball_on_apply_motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left); + ////////////////////////////////////////////////////////////////////////////// // Public API functions