Skip to content

Commit f35dee5

Browse files
authored
Take care of scroll divisor remainders for PS/2 drag scroll (qmk#20732)
1 parent 960d6e0 commit f35dee5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/ps2/ps2_mouse.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,27 @@ static inline void ps2_mouse_scroll_button_task(report_mouse_t *mouse_report) {
265265
SCROLL_SENT,
266266
} scroll_state = SCROLL_NONE;
267267
static uint16_t scroll_button_time = 0;
268+
static int16_t scroll_x, scroll_y;
268269

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

272273
if (scroll_state == SCROLL_NONE) {
273274
scroll_button_time = timer_read();
274275
scroll_state = SCROLL_BTN;
276+
scroll_x = 0;
277+
scroll_y = 0;
275278
}
276279

277280
// If the mouse has moved, update the report to scroll instead of move the mouse
278281
if (mouse_report->x || mouse_report->y) {
279-
scroll_state = SCROLL_SENT;
280-
mouse_report->v = -mouse_report->y / (PS2_MOUSE_SCROLL_DIVISOR_V);
281-
mouse_report->h = mouse_report->x / (PS2_MOUSE_SCROLL_DIVISOR_H);
282+
scroll_state = SCROLL_SENT;
283+
scroll_y += mouse_report->y;
284+
scroll_x += mouse_report->x;
285+
mouse_report->v = -scroll_y / (PS2_MOUSE_SCROLL_DIVISOR_V);
286+
mouse_report->h = scroll_x / (PS2_MOUSE_SCROLL_DIVISOR_H);
287+
scroll_y += (mouse_report->v * (PS2_MOUSE_SCROLL_DIVISOR_V));
288+
scroll_x -= (mouse_report->h * (PS2_MOUSE_SCROLL_DIVISOR_H));
282289
mouse_report->x = 0;
283290
mouse_report->y = 0;
284291
#ifdef PS2_MOUSE_INVERT_H

0 commit comments

Comments
 (0)