diff options
| author | Albert Y <76888457+filterpaper@users.noreply.github.com> | 2022-06-20 02:15:55 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-19 11:15:55 -0700 |
| commit | c725b6bf89878aebe9c5ffa2f6c05abd9ea98117 (patch) | |
| tree | 35b485444d0cefb5388baf232aa4bca8ce7e68f1 /quantum/mousekey.c | |
| parent | d6eff188e97661b420541abe745c054a47d55bae (diff) | |
[Core] Mouse key kinetic mode fix (#17176)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'quantum/mousekey.c')
| -rw-r--r-- | quantum/mousekey.c | 27 |
1 files changed, 16 insertions, 11 deletions
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) */ |
| 67 | uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; | 67 | uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; |
| 68 | /* milliseconds between repeated motion events (0-255) */ | 68 | /* milliseconds between repeated motion events (0-255) */ |
| 69 | uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; | 69 | # ifdef MK_KINETIC_SPEED |
| 70 | float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; | ||
| 71 | # else | ||
| 72 | uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; | ||
| 73 | # endif | ||
| 70 | uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; | 74 | uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; |
| 71 | uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; | 75 | uint8_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 | ||
| 75 | static uint8_t move_unit(void) { | 82 | static 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 | ||
| 150 | float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; | ||
| 151 | |||
| 152 | static uint8_t wheel_unit(void) { | 156 | static 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 | ||
| 172 | static uint8_t move_unit(void) { | 178 | static 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 | ||
| 211 | void mousekey_task(void) { | 216 | void mousekey_task(void) { |
| 212 | // report cursor and scroll movement independently | 217 | // report cursor and scroll movement independently |
