aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordhong44 <daniel.hong@live.com>2020-07-16 02:47:43 -0400
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commitd0abad27abd6d58f88985c1c28463ee51b7a116e (patch)
treee41d2e5891405aa1f61b5243da7b222fd3a64c7b
parent86e30c26095bb9fdcb8edc23d7d5e879382087cf (diff)
downloadqmk_firmware-d0abad27abd6d58f88985c1c28463ee51b7a116e.tar.gz
qmk_firmware-d0abad27abd6d58f88985c1c28463ee51b7a116e.zip
Fix the mousekey scrolling (#9174)
Mousekey scrolling should have a separate repeat variable to keep track of scrolling acceleration, instead of being tied to mouse movement scolling in mousekeys. The send function should record when the last movement was made since this is when movement is actually sent. Doing this fixes the bug where the initial press of a mousekey scroll button causes a double scroll. Signed-off-by: Daniel Hong <daniel.hong@live.com>
-rw-r--r--tmk_core/common/mousekey.c82
1 files changed, 43 insertions, 39 deletions
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 42bf231f4..390c74e0f 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -35,7 +35,7 @@ static report_mouse_t mouse_report = {0};
35static void mousekey_debug(void); 35static void mousekey_debug(void);
36static uint8_t mousekey_accel = 0; 36static uint8_t mousekey_accel = 0;
37static uint8_t mousekey_repeat = 0; 37static uint8_t mousekey_repeat = 0;
38static uint16_t last_timer = 0; 38static uint8_t mousekey_wheel_repeat = 0;
39 39
40#ifndef MK_3_SPEED 40#ifndef MK_3_SPEED
41 41
@@ -94,12 +94,12 @@ static uint8_t wheel_unit(void) {
94 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2; 94 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
95 } else if (mousekey_accel & (1 << 2)) { 95 } else if (mousekey_accel & (1 << 2)) {
96 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed); 96 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
97 } else if (mousekey_repeat == 0) { 97 } else if (mousekey_wheel_repeat == 0) {
98 unit = MOUSEKEY_WHEEL_DELTA; 98 unit = MOUSEKEY_WHEEL_DELTA;
99 } else if (mousekey_repeat >= mk_wheel_time_to_max) { 99 } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
100 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; 100 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
101 } else { 101 } else {
102 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; 102 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
103 } 103 }
104 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); 104 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
105} 105}
@@ -147,14 +147,17 @@ static uint8_t wheel_unit(void) {
147void mousekey_task(void) { 147void mousekey_task(void) {
148 // report cursor and scroll movement independently 148 // report cursor and scroll movement independently
149 report_mouse_t const tmpmr = mouse_report; 149 report_mouse_t const tmpmr = mouse_report;
150 if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) { 150
151 mouse_report.x = 0;
152 mouse_report.y = 0;
153 mouse_report.v = 0;
154 mouse_report.h = 0;
155
156 if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
151 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; 157 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
152 mouse_report.v = 0; 158 if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
153 mouse_report.h = 0; 159 if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
154 if (mouse_report.x > 0) mouse_report.x = move_unit(); 160
155 if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
156 if (mouse_report.y > 0) mouse_report.y = move_unit();
157 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
158 /* diagonal move [1/sqrt(2)] */ 161 /* diagonal move [1/sqrt(2)] */
159 if (mouse_report.x && mouse_report.y) { 162 if (mouse_report.x && mouse_report.y) {
160 mouse_report.x = times_inv_sqrt2(mouse_report.x); 163 mouse_report.x = times_inv_sqrt2(mouse_report.x);
@@ -166,18 +169,12 @@ void mousekey_task(void) {
166 mouse_report.y = 1; 169 mouse_report.y = 1;
167 } 170 }
168 } 171 }
169 mousekey_send();
170 last_timer_c = last_timer;
171 mouse_report = tmpmr;
172 } 172 }
173 if ((mouse_report.v || mouse_report.h) && timer_elapsed(last_timer_w) > (mousekey_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) { 173 if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
174 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; 174 if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
175 mouse_report.x = 0; 175 if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
176 mouse_report.y = 0; 176 if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
177 if (mouse_report.v > 0) mouse_report.v = wheel_unit(); 177
178 if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
179 if (mouse_report.h > 0) mouse_report.h = wheel_unit();
180 if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
181 /* diagonal move [1/sqrt(2)] */ 178 /* diagonal move [1/sqrt(2)] */
182 if (mouse_report.v && mouse_report.h) { 179 if (mouse_report.v && mouse_report.h) {
183 mouse_report.v = times_inv_sqrt2(mouse_report.v); 180 mouse_report.v = times_inv_sqrt2(mouse_report.v);
@@ -189,10 +186,10 @@ void mousekey_task(void) {
189 mouse_report.h = 1; 186 mouse_report.h = 1;
190 } 187 }
191 } 188 }
192 mousekey_send();
193 last_timer_w = last_timer;
194 mouse_report = tmpmr;
195 } 189 }
190
191 if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
192 mouse_report = tmpmr;
196} 193}
197 194
198void mousekey_on(uint8_t code) { 195void mousekey_on(uint8_t code) {
@@ -228,6 +225,7 @@ void mousekey_on(uint8_t code) {
228 mousekey_accel |= (1 << 1); 225 mousekey_accel |= (1 << 1);
229 else if (code == KC_MS_ACCEL2) 226 else if (code == KC_MS_ACCEL2)
230 mousekey_accel |= (1 << 2); 227 mousekey_accel |= (1 << 2);
228
231} 229}
232 230
233void mousekey_off(uint8_t code) { 231void mousekey_off(uint8_t code) {
@@ -263,7 +261,8 @@ void mousekey_off(uint8_t code) {
263 mousekey_accel &= ~(1 << 1); 261 mousekey_accel &= ~(1 << 1);
264 else if (code == KC_MS_ACCEL2) 262 else if (code == KC_MS_ACCEL2)
265 mousekey_accel &= ~(1 << 2); 263 mousekey_accel &= ~(1 << 2);
266 if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) mousekey_repeat = 0; 264 if (mouse_report.x == 0 && mouse_report.y == 0) mousekey_repeat = 0;
265 if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
267} 266}
268 267
269#else /* #ifndef MK_3_SPEED */ 268#else /* #ifndef MK_3_SPEED */
@@ -285,20 +284,22 @@ uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0
285void mousekey_task(void) { 284void mousekey_task(void) {
286 // report cursor and scroll movement independently 285 // report cursor and scroll movement independently
287 report_mouse_t const tmpmr = mouse_report; 286 report_mouse_t const tmpmr = mouse_report;
288 if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) { 287 mouse_report.x = 0;
289 mouse_report.h = 0; 288 mouse_report.y = 0;
290 mouse_report.v = 0; 289 mouse_report.v = 0;
291 mousekey_send(); 290 mouse_report.h = 0;
292 last_timer_c = last_timer; 291
293 mouse_report = tmpmr; 292 if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
293 mouse_report.x = tmpmr.x;
294 mouse_report.y = tmpmr.y;
294 } 295 }
295 if ((mouse_report.h || mouse_report.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) { 296 if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
296 mouse_report.x = 0; 297 mouse_report.v = tmpmr.v;
297 mouse_report.y = 0; 298 mouse_report.h = tmpmr.h;
298 mousekey_send();
299 last_timer_w = last_timer;
300 mouse_report = tmpmr;
301 } 299 }
300
301 if (mouse_report.x || mouse_report.y || mouse_report.v || mouse_report.h) mousekey_send();
302 mouse_report = tmpmr;
302} 303}
303 304
304void adjust_speed(void) { 305void adjust_speed(void) {
@@ -413,13 +414,16 @@ void mousekey_off(uint8_t code) {
413 414
414void mousekey_send(void) { 415void mousekey_send(void) {
415 mousekey_debug(); 416 mousekey_debug();
417 uint16_t time = timer_read();
418 if (mouse_report.x || mouse_report.y) last_timer_c = time;
419 if (mouse_report.v || mouse_report.h) last_timer_w = time;
416 host_mouse_send(&mouse_report); 420 host_mouse_send(&mouse_report);
417 last_timer = timer_read();
418} 421}
419 422
420void mousekey_clear(void) { 423void mousekey_clear(void) {
421 mouse_report = (report_mouse_t){}; 424 mouse_report = (report_mouse_t){};
422 mousekey_repeat = 0; 425 mousekey_repeat = 0;
426 mousekey_wheel_repeat = 0;
423 mousekey_accel = 0; 427 mousekey_accel = 0;
424} 428}
425 429