aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
authorfrancislan <francis.lan16@gmail.com>2020-03-13 09:49:44 -0700
committerGitHub <noreply@github.com>2020-03-13 12:49:44 -0400
commit3cd2a27ac0f963bc2023c3004f6f8eff0eb62a81 (patch)
treecb50af68f1c25943003ed12446822c599e607fdc /tmk_core/common
parent28d94b72484967f12b521e87b2745bc24d792471 (diff)
downloadqmk_firmware-3cd2a27ac0f963bc2023c3004f6f8eff0eb62a81.tar.gz
qmk_firmware-3cd2a27ac0f963bc2023c3004f6f8eff0eb62a81.zip
Decouple mouse cursor and mouse wheel in accelerated mode (#6685)
* Decouples mouse cursor and mouse wheel movements in accelerated mode. * Fixed comment indentation. * Updated docs Co-authored-by: Francis LAN <francislan@google.com>
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/mousekey.c70
-rw-r--r--tmk_core/common/mousekey.h6
2 files changed, 52 insertions, 24 deletions
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 2df7728a4..00357f5f6 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -39,6 +39,9 @@ static uint16_t last_timer = 0;
39 39
40#ifndef MK_3_SPEED 40#ifndef MK_3_SPEED
41 41
42static uint16_t last_timer_c = 0;
43static uint16_t last_timer_w = 0;
44
42/* 45/*
43 * Mouse keys acceleration algorithm 46 * Mouse keys acceleration algorithm
44 * http://en.wikipedia.org/wiki/Mouse_keys 47 * http://en.wikipedia.org/wiki/Mouse_keys
@@ -56,6 +59,10 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
56/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */ 59/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
57// int8_t mk_curve = 0; 60// int8_t mk_curve = 0;
58/* wheel params */ 61/* wheel params */
62/* milliseconds between the initial key press and first repeated motion event (0-2550) */
63uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
64/* milliseconds between repeated motion events (0-255) */
65uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
59uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 66uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
60uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 67uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
61 68
@@ -96,33 +103,48 @@ static uint8_t wheel_unit(void) {
96} 103}
97 104
98void mousekey_task(void) { 105void mousekey_task(void) {
99 if (timer_elapsed(last_timer) < (mousekey_repeat ? mk_interval : mk_delay * 10)) { 106 // report cursor and scroll movement independently
100 return; 107 report_mouse_t const tmpmr = mouse_report;
101 } 108 if ((mouse_report.x || mouse_report.y) &&
102 if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) { 109 timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
103 return; 110 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
104 } 111 mouse_report.v = 0;
105 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++; 112 mouse_report.h = 0;
106 if (mouse_report.x > 0) mouse_report.x = move_unit(); 113 if (mouse_report.x > 0) mouse_report.x = move_unit();
107 if (mouse_report.x < 0) mouse_report.x = move_unit() * -1; 114 if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
108 if (mouse_report.y > 0) mouse_report.y = move_unit(); 115 if (mouse_report.y > 0) mouse_report.y = move_unit();
109 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; 116 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
110 /* diagonal move [1/sqrt(2)] */ 117 /* diagonal move [1/sqrt(2)] */
111 if (mouse_report.x && mouse_report.y) { 118 if (mouse_report.x && mouse_report.y) {
112 mouse_report.x = times_inv_sqrt2(mouse_report.x); 119 mouse_report.x = times_inv_sqrt2(mouse_report.x);
113 if (mouse_report.x == 0) { 120 if (mouse_report.x == 0) { mouse_report.x = 1; }
114 mouse_report.x = 1; 121 mouse_report.y = times_inv_sqrt2(mouse_report.y);
122 if (mouse_report.y == 0) { mouse_report.y = 1; }
115 } 123 }
116 mouse_report.y = times_inv_sqrt2(mouse_report.y); 124 mousekey_send();
117 if (mouse_report.y == 0) { 125 last_timer_c = last_timer;
118 mouse_report.y = 1; 126 mouse_report = tmpmr;
127 }
128 if ((mouse_report.v || mouse_report.h) &&
129 timer_elapsed(last_timer_w) > (mousekey_repeat ? mk_wheel_interval: mk_wheel_delay * 10)) {
130 if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
131 mouse_report.x = 0;
132 mouse_report.y = 0;
133 if (mouse_report.v > 0) mouse_report.v = wheel_unit();
134 if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
135 if (mouse_report.h > 0) mouse_report.h = wheel_unit();
136 if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
137 /* diagonal move [1/sqrt(2)] */
138 if (mouse_report.v && mouse_report.h) {
139 mouse_report.v = times_inv_sqrt2(mouse_report.v);
140 if (mouse_report.v == 0) { mouse_report.v = 1; }
141 mouse_report.h = times_inv_sqrt2(mouse_report.h);
142 if (mouse_report.h == 0) { mouse_report.h = 1; }
119 } 143 }
144 mousekey_send();
145 last_timer_w = last_timer;
146 mouse_report = tmpmr;
120 } 147 }
121 if (mouse_report.v > 0) mouse_report.v = wheel_unit();
122 if (mouse_report.v < 0) mouse_report.v = wheel_unit() * -1;
123 if (mouse_report.h > 0) mouse_report.h = wheel_unit();
124 if (mouse_report.h < 0) mouse_report.h = wheel_unit() * -1;
125 mousekey_send();
126} 148}
127 149
128void mousekey_on(uint8_t code) { 150void mousekey_on(uint8_t code) {
diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h
index 48946987c..05e453823 100644
--- a/tmk_core/common/mousekey.h
+++ b/tmk_core/common/mousekey.h
@@ -55,6 +55,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
55# ifndef MOUSEKEY_TIME_TO_MAX 55# ifndef MOUSEKEY_TIME_TO_MAX
56# define MOUSEKEY_TIME_TO_MAX 20 56# define MOUSEKEY_TIME_TO_MAX 20
57# endif 57# endif
58# ifndef MOUSEKEY_WHEEL_DELAY
59# define MOUSEKEY_WHEEL_DELAY 300
60# endif
61# ifndef MOUSEKEY_WHEEL_INTERVAL
62# define MOUSEKEY_WHEEL_INTERVAL 100
63# endif
58# ifndef MOUSEKEY_WHEEL_MAX_SPEED 64# ifndef MOUSEKEY_WHEEL_MAX_SPEED
59# define MOUSEKEY_WHEEL_MAX_SPEED 8 65# define MOUSEKEY_WHEEL_MAX_SPEED 8
60# endif 66# endif