From c725b6bf89878aebe9c5ffa2f6c05abd9ea98117 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Mon, 20 Jun 2022 02:15:55 +0800 Subject: [Core] Mouse key kinetic mode fix (#17176) Co-authored-by: Drashna Jaelre --- quantum/mousekey.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'quantum/mousekey.c') 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; /* milliseconds between the initial key press and first repeated motion event (0-2550) */ uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; /* milliseconds between repeated motion events (0-255) */ -uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; +# ifdef MK_KINETIC_SPEED +float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; +# else +uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; +# endif uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; # ifndef MK_COMBINED +# ifndef MK_KINETIC_SPEED + +/* Default accelerated mode */ static uint8_t move_unit(void) { uint16_t unit; @@ -108,8 +115,7 @@ static uint8_t wheel_unit(void) { return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); } -# else /* #ifndef MK_COMBINED */ -# ifdef MK_KINETIC_SPEED +# else /* #ifndef MK_KINETIC_SPEED */ /* * Kinetic movement acceleration algorithm @@ -147,27 +153,27 @@ static uint8_t move_unit(void) { return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed; } -float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; - static uint8_t wheel_unit(void) { float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; if (mousekey_accel & ((1 << 0) | (1 << 2))) { speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; - } else if (mousekey_repeat && mouse_timer) { + } else if (mousekey_wheel_repeat && mouse_timer) { if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) { const float time_elapsed = timer_elapsed(mouse_timer) / 50; speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; } speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed; } - mk_wheel_interval = 1000.0f / speed; - return 1; + return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1; } -# else /* #ifndef MK_KINETIC_SPEED */ +# endif /* #ifndef MK_KINETIC_SPEED */ +# else /* #ifndef MK_COMBINED */ + +/* Combined mode */ static uint8_t move_unit(void) { uint16_t unit; @@ -205,8 +211,7 @@ static uint8_t wheel_unit(void) { return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit)); } -# endif /* #ifndef MK_KINETIC_SPEED */ -# endif /* #ifndef MK_COMBINED */ +# endif /* #ifndef MK_COMBINED */ void mousekey_task(void) { // report cursor and scroll movement independently -- cgit v1.2.3