Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mousekeys inertia zero friction improvements #23677

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/feature_mouse_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Recommended settings in your keymap’s `config.h` file:
|`MOUSEKEY_MAX_SPEED` |32 |Maximum cursor speed at which acceleration stops |
|`MOUSEKEY_TIME_TO_MAX` |32 |Number of frames until maximum cursor speed is reached |
|`MOUSEKEY_FRICTION` |24 |How quickly the cursor stops after releasing a key |
|`MOUSEKEY_STOP_SPEED` |1 |Lowest possible decelerating velocity before it snaps to 0 |
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Japanese isn't particularly good. Is it alright that I only updated the English documentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine.

|`MOUSEKEY_MOVE_DELTA` |1 |How much to move on first frame (1 strongly recommended) |

Tips:
Expand All @@ -199,7 +200,8 @@ Tips:
* Set `MOUSEKEY_INTERVAL` to a value of 1000 / your monitor's FPS. For 60 FPS, 1000/60 = 16.
* Set `MOUSEKEY_MAX_SPEED` based on your screen resolution and refresh rate, like Width / FPS. For example, 1920 pixels / 60 FPS = 32 pixels per frame.
* Set `MOUSEKEY_TIME_TO_MAX` to a value of approximately FPS / 2, to make it reach full speed in half a second (or so).
* Set `MOUSEKEY_FRICTION` to something between 1 and 255. Lower makes the cursor glide longer. Values from 8 to 40 are the most effective.
* Set `MOUSEKEY_FRICTION` to something between 0 and 255. Lower makes the cursor glide longer. Values from 8 to 40 are the most effective.
* Set `MOUSEKEY_STOP_SPEED` to something between 0 and `MOUSEKEY_MAX_SPEED`. Increase this for easier stopping if you set `MOUSEKEY_FRICTION` to 0.
* Keep `MOUSEKEY_MOVE_DELTA` at 1. This allows precise movements before the gliding effect starts.
* Mouse wheel options are the same as the default accelerated mode, and do not use inertia.

Expand Down
6 changes: 3 additions & 3 deletions quantum/mousekey.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in quantum/mousekey.c

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
* Copyright 2011 Jun Wako <wakojun@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -288,16 +288,16 @@
// simulate acceleration and deceleration

// deceleration
if ((direction > -1) && (velocity < 0))
velocity = (velocity + 1) * (256 - MOUSEKEY_FRICTION) / 256;
else if ((direction < 1) && (velocity > 0))
if (velocity != 0)
velocity = velocity * (256 - MOUSEKEY_FRICTION) / 256;

// acceleration
if ((direction > 0) && (velocity < mk_time_to_max))
velocity++;
else if ((direction < 0) && (velocity > -mk_time_to_max))
velocity--;
else if (velocity <= MOUSEKEY_STOP_SPEED && velocity >= -MOUSEKEY_STOP_SPEED)
velocity = 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't quite sure what to do here regarding the styleguide. The guide is unambiguous in saying that braces must always be used... but since I am extending an existing unbraced if/else chain it felt wrong to differently format only my lines in the function.

I suppose I could have reformatted the entire function, but I worried that doing so would be considered out-of-scope for the purposes of this PR.


return velocity;
}
Expand Down
3 changes: 3 additions & 0 deletions quantum/mousekey.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define MOUSEKEY_MAX_SPEED 10
# endif
# endif
# ifndef MOUSEKEY_STOP_SPEED
# define MOUSEKEY_STOP_SPEED 1
# endif
# ifndef MOUSEKEY_TIME_TO_MAX
# if defined(MOUSEKEY_INERTIA)
# define MOUSEKEY_TIME_TO_MAX 32
Expand Down
Loading