Browse Source

Refactor kinetic mouse key feature (#21164)

pull/21472/head
フィルターペーパー 10 months ago
committed by GitHub
parent
commit
df5984022f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 16 deletions
  1. +1
    -1
      docs/feature_mouse_keys.md
  2. +24
    -15
      quantum/mousekey.c

+ 1
- 1
docs/feature_mouse_keys.md View File

@ -101,7 +101,7 @@ This is an extension of the accelerated mode. The kinetic mode uses a quadratic
Tips:
* 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.
* 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.
* 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.
### Constant mode


+ 24
- 15
quantum/mousekey.c View File

@ -175,7 +175,7 @@ static uint8_t wheel_unit(void) {
/*
* Kinetic movement acceleration algorithm
*
* current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B
* current speed = I + A * T/50 + A * (T/50)^2 * 1/2 | maximum B
*
* T: time since the mouse movement started
* E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the
@ -192,37 +192,46 @@ const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;
static uint8_t move_unit(void) {
uint16_t speed = mk_initial_speed;
if (mousekey_accel & ((1 << 0) | (1 << 2))) {
speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
if (mousekey_accel & (1 << 0)) {
speed = mk_decelerated_speed;
} else if (mousekey_accel & (1 << 2)) {
speed = mk_accelerated_speed;
} else if (mousekey_repeat && mouse_timer) {
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
speed = speed > mk_base_speed ? mk_base_speed : speed;
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + (MOUSEKEY_MOVE_DELTA * time_elapsed * time_elapsed) / 2;
if (speed > mk_base_speed) {
speed = mk_base_speed;
}
}
/* convert speed to USB mouse speed 1 to 127 */
speed = (uint8_t)(speed / (1000U / mk_interval));
speed = speed < 1 ? 1 : speed;
return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
if (speed > MOUSEKEY_MOVE_MAX) {
speed = MOUSEKEY_MOVE_MAX;
} else if (speed < 1) {
speed = 1;
}
return speed;
}
static uint8_t wheel_unit(void) {
uint16_t 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;
if (mousekey_accel & (1 << 0)) {
speed = MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
} else if (mousekey_accel & (1 << 2)) {
speed = MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS;
} else if (mousekey_wheel_repeat && mouse_timer) {
if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + (1 * time_elapsed * time_elapsed) / 2;
}
if (speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
speed = MOUSEKEY_WHEEL_BASE_MOVEMENTS;
}
speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
}
mk_wheel_interval = 1000U / speed;
return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
return 1;
}
# endif /* #ifndef MK_KINETIC_SPEED */


Loading…
Cancel
Save