summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_mouse_keys.md6
-rw-r--r--quantum/mousekey.c27
-rw-r--r--quantum/mousekey.h4
3 files changed, 21 insertions, 16 deletions
diff --git a/docs/feature_mouse_keys.md b/docs/feature_mouse_keys.md
index 905da36e43..8e474c4245 100644
--- a/docs/feature_mouse_keys.md
+++ b/docs/feature_mouse_keys.md
@@ -87,9 +87,9 @@ This is an extension of the accelerated mode. The kinetic mode uses a quadratic
87|`MK_KINETIC_SPEED` |undefined|Enable kinetic mode | 87|`MK_KINETIC_SPEED` |undefined|Enable kinetic mode |
88|`MOUSEKEY_DELAY` |5 |Delay between pressing a movement key and cursor movement | 88|`MOUSEKEY_DELAY` |5 |Delay between pressing a movement key and cursor movement |
89|`MOUSEKEY_INTERVAL` |10 |Time between cursor movements in milliseconds | 89|`MOUSEKEY_INTERVAL` |10 |Time between cursor movements in milliseconds |
90|`MOUSEKEY_MOVE_DELTA` |5 |Step size for accelerating from initial to base speed | 90|`MOUSEKEY_MOVE_DELTA` |16 |Step size for accelerating from initial to base speed |
91|`MOUSEKEY_INITIAL_SPEED` |100 |Initial speed of the cursor in pixel per second | 91|`MOUSEKEY_INITIAL_SPEED` |100 |Initial speed of the cursor in pixel per second |
92|`MOUSEKEY_BASE_SPEED` |1000 |Maximum cursor speed at which acceleration stops | 92|`MOUSEKEY_BASE_SPEED` |5000 |Maximum cursor speed at which acceleration stops |
93|`MOUSEKEY_DECELERATED_SPEED` |400 |Decelerated cursor speed | 93|`MOUSEKEY_DECELERATED_SPEED` |400 |Decelerated cursor speed |
94|`MOUSEKEY_ACCELERATED_SPEED` |3000 |Accelerated cursor speed | 94|`MOUSEKEY_ACCELERATED_SPEED` |3000 |Accelerated cursor speed |
95|`MOUSEKEY_WHEEL_INITIAL_MOVEMENTS` |16 |Initial number of movements of the mouse wheel | 95|`MOUSEKEY_WHEEL_INITIAL_MOVEMENTS` |16 |Initial number of movements of the mouse wheel |
@@ -100,7 +100,7 @@ This is an extension of the accelerated mode. The kinetic mode uses a quadratic
100Tips: 100Tips:
101 101
102* The smoothness of the cursor movement depends on the `MOUSEKEY_INTERVAL` setting. The shorter the interval is set the smoother the movement will be. Setting the value too low makes the cursor unresponsive. Lower settings are possible if the micro processor is fast enough. For example: At an interval of `8` milliseconds, `125` movements per second will be initiated. With a base speed of `1000` each movement will move the cursor by `8` pixels. 102* The smoothness of the cursor movement depends on the `MOUSEKEY_INTERVAL` setting. The shorter the interval is set the smoother the movement will be. Setting the value too low makes the cursor unresponsive. Lower settings are possible if the micro processor is fast enough. For example: At an interval of `8` milliseconds, `125` movements per second will be initiated. With a base speed of `1000` each movement will move the cursor by `8` pixels.
103* Mouse wheel movements are implemented differently from cursor movements. While it's okay for the cursor to move multiple pixels at once for the mouse wheel this would lead to jerky movements. Instead, the mouse wheel operates at step size `1`. Setting mouse wheel speed is done by adjusting the number of wheel movements per second. 103* Mouse wheel movements are implemented differently from cursor movements. While it's okay for the cursor to move multiple pixels at once for the mouse wheel this would lead to jerky movements. Instead, the mouse wheel operates at step size `2`. Setting mouse wheel speed is done by adjusting the number of wheel movements per second.
104 104
105### Constant mode 105### Constant mode
106 106
diff --git a/quantum/mousekey.c b/quantum/mousekey.c
index 64d0e66682..81e887d529 100644
--- a/quantum/mousekey.c
+++ b/quantum/mousekey.c
@@ -66,11 +66,18 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
66/* milliseconds between the initial key press and first repeated motion event (0-2550) */ 66/* milliseconds between the initial key press and first repeated motion event (0-2550) */
67uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; 67uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
68/* milliseconds between repeated motion events (0-255) */ 68/* milliseconds between repeated motion events (0-255) */
69uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; 69# ifdef MK_KINETIC_SPEED
70float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
71# else
72uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
73# endif
70uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 74uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
71uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 75uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
72 76
73# ifndef MK_COMBINED 77# ifndef MK_COMBINED
78# ifndef MK_KINETIC_SPEED
79
80/* Default accelerated mode */
74 81
75static uint8_t move_unit(void) { 82static uint8_t move_unit(void) {
76 uint16_t unit; 83 uint16_t unit;
@@ -108,8 +115,7 @@ static uint8_t wheel_unit(void) {
108 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); 115 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
109} 116}
110 117
111# else /* #ifndef MK_COMBINED */ 118# else /* #ifndef MK_KINETIC_SPEED */
112# ifdef MK_KINETIC_SPEED
113 119
114/* 120/*
115 * Kinetic movement acceleration algorithm 121 * Kinetic movement acceleration algorithm
@@ -147,27 +153,27 @@ static uint8_t move_unit(void) {
147 return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed; 153 return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
148} 154}
149 155
150float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
151
152static uint8_t wheel_unit(void) { 156static uint8_t wheel_unit(void) {
153 float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; 157 float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
154 158
155 if (mousekey_accel & ((1 << 0) | (1 << 2))) { 159 if (mousekey_accel & ((1 << 0) | (1 << 2))) {
156 speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; 160 speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
157 } else if (mousekey_repeat && mouse_timer) { 161 } else if (mousekey_wheel_repeat && mouse_timer) {
158 if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) { 162 if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
159 const float time_elapsed = timer_elapsed(mouse_timer) / 50; 163 const float time_elapsed = timer_elapsed(mouse_timer) / 50;
160 speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; 164 speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
161 } 165 }
162 speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed; 166 speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
163 } 167 }
164
165 mk_wheel_interval = 1000.0f / speed; 168 mk_wheel_interval = 1000.0f / speed;
166 169
167 return 1; 170 return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
168} 171}
169 172
170# else /* #ifndef MK_KINETIC_SPEED */ 173# endif /* #ifndef MK_KINETIC_SPEED */
174# else /* #ifndef MK_COMBINED */
175
176/* Combined mode */
171 177
172static uint8_t move_unit(void) { 178static uint8_t move_unit(void) {
173 uint16_t unit; 179 uint16_t unit;
@@ -205,8 +211,7 @@ static uint8_t wheel_unit(void) {
205 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); 211 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
206} 212}
207 213
208# endif /* #ifndef MK_KINETIC_SPEED */ 214# endif /* #ifndef MK_COMBINED */
209# endif /* #ifndef MK_COMBINED */
210 215
211void mousekey_task(void) { 216void mousekey_task(void) {
212 // report cursor and scroll movement independently 217 // report cursor and scroll movement independently
diff --git a/quantum/mousekey.h b/quantum/mousekey.h
index 03da5f282a..d44f47fc1f 100644
--- a/quantum/mousekey.h
+++ b/quantum/mousekey.h
@@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
39# ifndef MK_KINETIC_SPEED 39# ifndef MK_KINETIC_SPEED
40# define MOUSEKEY_MOVE_DELTA 8 40# define MOUSEKEY_MOVE_DELTA 8
41# else 41# else
42# define MOUSEKEY_MOVE_DELTA 5 42# define MOUSEKEY_MOVE_DELTA 16
43# endif 43# endif
44# endif 44# endif
45# ifndef MOUSEKEY_WHEEL_DELTA 45# ifndef MOUSEKEY_WHEEL_DELTA
@@ -82,7 +82,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
82# define MOUSEKEY_INITIAL_SPEED 100 82# define MOUSEKEY_INITIAL_SPEED 100
83# endif 83# endif
84# ifndef MOUSEKEY_BASE_SPEED 84# ifndef MOUSEKEY_BASE_SPEED
85# define MOUSEKEY_BASE_SPEED 1000 85# define MOUSEKEY_BASE_SPEED 5000
86# endif 86# endif
87# ifndef MOUSEKEY_DECELERATED_SPEED 87# ifndef MOUSEKEY_DECELERATED_SPEED
88# define MOUSEKEY_DECELERATED_SPEED 400 88# define MOUSEKEY_DECELERATED_SPEED 400