Skip to content

Commit

Permalink
smoother mouse movement code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardakilic committed Sep 10, 2024
1 parent c68ae6c commit bb817f2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
30 changes: 29 additions & 1 deletion keyboards/horizon/keymaps/default_trackball/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@

// Enable if you want to
// #define PIMORONI_TRACKBALL_INVERT_X
// #define PIMORONI_TRACKBALL_INVERT_Y
// #define PIMORONI_TRACKBALL_INVERT_Y
// #define POINTING_DEVICE_ROTATION_90
// #define SPLIT_POINTING_ENABLE
// #define POINTING_DEVICE_RIGHT

// trackball smoothing start
// https://github.com/qmk/qmk_firmware/blob/master/keyboards/sofle/keymaps/foureight84/config.h
// #define POINTING_DEVICE_TASK_THROTTLE_MS 8
// Trackball smoothing


/*
https://www.reddit.com/r/ErgoMechKeyboards/comments/qx7oqg/how_do_you_get_smoother_mouse_keys_with_qmkvia/
https://github.com/manna-harbour/miryoku_qmk/blob/bdb9fd81e8aa2afb3882f7c0f6ae2d3ba448ac93/users/manna-harbour_miryoku/config.h#L23-L33
// Mouse key speed and acceleration.
#undef MOUSEKEY_DELAY
#define MOUSEKEY_DELAY 0
#undef MOUSEKEY_INTERVAL
#define MOUSEKEY_INTERVAL 16
#undef MOUSEKEY_WHEEL_DELAY
#define MOUSEKEY_WHEEL_DELAY 0
#undef MOUSEKEY_MAX_SPEED
#define MOUSEKEY_MAX_SPEED 6
#undef MOUSEKEY_TIME_TO_MAX
#define MOUSEKEY_TIME_TO_MAX 64
*/
45 changes: 45 additions & 0 deletions keyboards/horizon/keymaps/default_trackball/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,51 @@ void trackball_register_button(bool pressed, enum mouse_buttons button){
}
#endif

// Smooth mouse scroll movement START
// https://github.com/qmk/qmk_firmware/blob/master/keyboards/sofle/keymaps/foureight84/keymap.c
static uint32_t last_mouse_activity = 0;
static report_mouse_t last_mouse_report = {0};
static bool is_scrolling = false;

report_mouse_t smooth_mouse_movement(report_mouse_t mouse_report) {
// Linear interpolation and ease-in-out
static fract8 fract = 0.5;
int8_t x = 0;
int8_t y = 0;
int8_t h = 0;
int8_t v = 0;

if (!is_scrolling) {
x = ease8InOutApprox(lerp8by8(last_mouse_report.x, mouse_report.x, fract));
y = ease8InOutApprox(lerp8by8(last_mouse_report.y, mouse_report.y, fract));
} else {
h = ease8InOutApprox(lerp8by8(last_mouse_report.x, mouse_report.x, fract));
v = ease8InOutApprox(lerp8by8(last_mouse_report.y, mouse_report.y, fract));
}

// update the new smoothed report
mouse_report.x = x;
mouse_report.y = y;
mouse_report.h = h;
mouse_report.v = v;

return mouse_report;
}

report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {

if (has_mouse_report_changed(&last_mouse_report, &mouse_report)) {
last_mouse_activity = timer_read32();
memcpy(&last_mouse_report, &mouse_report, sizeof(mouse_report));
}

return smooth_mouse_movement(mouse_report);
}
// Smooth mousescroll movement END


// LAYERS

enum layer_names {
_BASE,
_SYMBOL,
Expand Down

0 comments on commit bb817f2

Please sign in to comment.