Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix asymmetric behavior of scroll direction #9

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ static int16_t add16(int16_t a, int16_t b) {
return r;
}

// divmod16 divides *v by div, returns the quotient, and assigns the remainder
// to *v.
static int16_t divmod16(int16_t *v, int16_t div) {
int16_t r = *v / div;
*v -= r * div;
return r;
}

// clip2int8 clips an integer fit into int8_t.
static inline int8_t clip2int8(int16_t v) {
return (v) < -127 ? -127 : (v) > 127 ? 127 : (int8_t)v;
Expand Down Expand Up @@ -159,11 +167,9 @@ static void motion_to_mouse_move(keyball_motion_t *m, report_mouse_t *r, bool is

static void motion_to_mouse_scroll(keyball_motion_t *m, report_mouse_t *r, bool is_left) {
// consume motion of trackball.
uint8_t div = keyball_get_scroll_div() - 1;
int16_t x = m->x >> div;
m->x -= x << div;
int16_t y = m->y >> div;
m->y -= y << div;
int16_t div = 1 << (keyball_get_scroll_div() - 1);
int16_t x = divmod16(&m->x, div);
int16_t y = divmod16(&m->y, div);

// apply to mouse report.
#if KEYBALL_MODEL == 61 || KEYBALL_MODEL == 39 || KEYBALL_MODEL == 147 || KEYBALL_MODEL == 44
Expand Down
Loading