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

Take care of scroll divisor remainders for PS/2 drag scroll #20732

Merged
merged 2 commits into from
Sep 25, 2023
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
13 changes: 10 additions & 3 deletions drivers/ps2/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,27 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {
SCROLL_SENT,
} scroll_state = SCROLL_NONE;
static uint16_t scroll_button_time = 0;
static int16_t scroll_x, scroll_y;

if (PS2_MOUSE_SCROLL_BTN_MASK == (mouse_report->buttons & (PS2_MOUSE_SCROLL_BTN_MASK))) {
// All scroll buttons are pressed

if (scroll_state == SCROLL_NONE) {
scroll_button_time = timer_read();
scroll_state = SCROLL_BTN;
scroll_x = 0;
scroll_y = 0;
}

// If the mouse has moved, update the report to scroll instead of move the mouse
if (mouse_report->x || mouse_report->y) {
scroll_state = SCROLL_SENT;
mouse_report->v = -mouse_report->y / (PS2_MOUSE_SCROLL_DIVISOR_V);
mouse_report->h = mouse_report->x / (PS2_MOUSE_SCROLL_DIVISOR_H);
scroll_state = SCROLL_SENT;
scroll_y += mouse_report->y;
scroll_x += mouse_report->x;
mouse_report->v = -scroll_y / (PS2_MOUSE_SCROLL_DIVISOR_V);
mouse_report->h = scroll_x / (PS2_MOUSE_SCROLL_DIVISOR_H);
scroll_y += (mouse_report->v * (PS2_MOUSE_SCROLL_DIVISOR_V));
scroll_x -= (mouse_report->h * (PS2_MOUSE_SCROLL_DIVISOR_H));
mouse_report->x = 0;
mouse_report->y = 0;
#ifdef PS2_MOUSE_INVERT_H
Expand Down