Skip to content

Commit

Permalink
Hooks to override applying motion to mouse report
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Apr 15, 2024
1 parent 12bc228 commit e8657af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
16 changes: 16 additions & 0 deletions keyboards/keyball/lib/keyball/keyball.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e8657af

Please sign in to comment.