From 5394fb379339f09c2bfc15d334d5b20cd7a4fee9 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 20 Feb 2024 20:33:58 +0200 Subject: [PATCH 1/4] fix(bkb) drag-scroll was dumping spill-over distance > reducing effectively the attenable scroll-speed. From another POV, scroll-buffer's input-speed division was getting rid of the remainder. The effect was a subtle jerk with sensible defaults (SCROLL_DPI: 100) but in higher DPIs or with *maccel* [1] enabled and redirecting to drag-scroll, all expected addionall velocity, dissipates. NOTE: to enable *maccel*, you need to reverse the lines in `pointing_device_task_kb()` so that `pointing_device_task_user()` is invoked first. WARNING: there might be an issue when drag-scroll DPI is 100[2]. [1]: https://github.com/finrod09/qmk_userspace_features/tree/maccel-assym_s_curve/maccel [2]: https://discord.com/channels/681309835135811648/1203417572742135808/1209118208997466142 --- keyboards/bastardkb/charybdis/charybdis.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index c9f0e6317283..11040a6133b1 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -197,14 +197,21 @@ static void pointing_device_task_charybdis(report_mouse_t* mouse_report) { # endif // CHARYBDIS_DRAGSCROLL_REVERSE_Y mouse_report->x = 0; mouse_report->y = 0; - if (abs(scroll_buffer_x) > CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { - mouse_report->h = scroll_buffer_x > 0 ? 1 : -1; - scroll_buffer_x = 0; + if (abs(scroll_buffer_x) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { + const int16_t sign_x = scroll_buffer_x > 0 ? 1 : -1; + mouse_report->h = sign_x; + scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; } - if (abs(scroll_buffer_y) > CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { - mouse_report->v = scroll_buffer_y > 0 ? 1 : -1; - scroll_buffer_y = 0; + if (abs(scroll_buffer_y) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { + const int16_t sign_y = scroll_buffer_y > 0 ? 1 : -1; + mouse_report->v = sign_y; + scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; } + + mouse_report->x = mouse_report->y = 0; + } else { // not a drag-scroll event + // Clean up, or next draa-scroll actevation would start abruptly. + scroll_buffer_x = scroll_buffer_y = 0; } } From a5c342fa7cd8f2e94beaf8629e73ff8dbf4019b9 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 21 Feb 2024 00:10:27 +0200 Subject: [PATCH 2/4] enh(bkb) break scroll travelling when reversing > The previous fix allows for "travelling", keep scrolling while mouse has stopped moving, if enough distnance accumulated, and that's good for big files. But when reversing direction, mouse has to work against accumulated distance before acting. - refact: new dir-checks required changing the axis-reversal macros to work via temp-vars. --- keyboards/bastardkb/charybdis/charybdis.c | 37 +++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index 11040a6133b1..bf38446ed99a 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -186,32 +186,45 @@ static void pointing_device_task_charybdis(report_mouse_t* mouse_report) { static int16_t scroll_buffer_y = 0; if (g_charybdis_config.is_dragscroll_enabled) { # ifdef CHARYBDIS_DRAGSCROLL_REVERSE_X - scroll_buffer_x -= mouse_report->x; + const int16_t m_x = -mouse_report->x; # else - scroll_buffer_x += mouse_report->x; + const int16_t m_x = mouse_report->x; # endif // CHARYBDIS_DRAGSCROLL_REVERSE_X # ifdef CHARYBDIS_DRAGSCROLL_REVERSE_Y - scroll_buffer_y -= mouse_report->y; + const int16_t m_y = -mouse_report->y; # else - scroll_buffer_y += mouse_report->y; + const int16_t m_y = mouse_report->y; # endif // CHARYBDIS_DRAGSCROLL_REVERSE_Y - mouse_report->x = 0; - mouse_report->y = 0; + scroll_buffer_x += m_x; + scroll_buffer_y += m_y; + if (abs(scroll_buffer_x) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { const int16_t sign_x = scroll_buffer_x > 0 ? 1 : -1; - mouse_report->h = sign_x; - scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; + mouse_report->h = sign_x; + if (m_x == 0 || ((m_x > 0) && (scroll_buffer_x > 0)) || ((m_x < 0) && (scroll_buffer_x < 0))) { + // Spill-over accumulated distance to the next cycle. + scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; + } else { + // Cancel accunulated distance if mouse-direction reversed. + scroll_buffer_x = 0; + } } if (abs(scroll_buffer_y) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { const int16_t sign_y = scroll_buffer_y > 0 ? 1 : -1; - mouse_report->v = sign_y; - scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; + mouse_report->v = sign_y; + if (m_y == 0 || ((m_y > 0) && (scroll_buffer_y > 0)) || ((m_y < 0) && (scroll_buffer_y < 0))) { + // Spill-over accumulated distance to the next cycle. + scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; + } else { + // Cancel accunulated distance if mouse-direction reversed. + scroll_buffer_y = 0; + } } mouse_report->x = mouse_report->y = 0; - } else { // not a drag-scroll event + } else { // not a drag-scroll event // Clean up, or next draa-scroll actevation would start abruptly. - scroll_buffer_x = scroll_buffer_y = 0; + scroll_buffer_x = scroll_buffer_y = 0; } } From 3ab7c87dcef1b76aa53523fc101a2d3ee14637bb Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 21 Feb 2024 00:51:30 +0200 Subject: [PATCH 3/4] refact(bkb) simpler to check earlier scroll-reversal > since it avoids subtracting from an increasing accumulator. - refact: group ops by axis (not by stage). --- keyboards/bastardkb/charybdis/charybdis.c | 38 +++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index bf38446ed99a..f9f6ccb1a12c 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -190,35 +190,33 @@ static void pointing_device_task_charybdis(report_mouse_t* mouse_report) { # else const int16_t m_x = mouse_report->x; # endif // CHARYBDIS_DRAGSCROLL_REVERSE_X + if (((m_x > 0) && (scroll_buffer_x < 0)) || ((m_x < 0) && (scroll_buffer_x > 0))) { + // Immediately cancel accunulated distance if mouse-direction reversed. + scroll_buffer_x = m_x; + } else { + scroll_buffer_x += m_x; + } + if (abs(scroll_buffer_x) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { + const int16_t sign_x = scroll_buffer_x > 0 ? 1 : -1; + mouse_report->h = sign_x; + scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; // Spill-over + } + # ifdef CHARYBDIS_DRAGSCROLL_REVERSE_Y const int16_t m_y = -mouse_report->y; # else const int16_t m_y = mouse_report->y; # endif // CHARYBDIS_DRAGSCROLL_REVERSE_Y - scroll_buffer_x += m_x; - scroll_buffer_y += m_y; - - if (abs(scroll_buffer_x) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { - const int16_t sign_x = scroll_buffer_x > 0 ? 1 : -1; - mouse_report->h = sign_x; - if (m_x == 0 || ((m_x > 0) && (scroll_buffer_x > 0)) || ((m_x < 0) && (scroll_buffer_x < 0))) { - // Spill-over accumulated distance to the next cycle. - scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; - } else { - // Cancel accunulated distance if mouse-direction reversed. - scroll_buffer_x = 0; - } + if (((m_y > 0) && (scroll_buffer_y < 0)) || ((m_y < 0) && (scroll_buffer_y > 0))) { + // Immediately cancel accunulated distance if mouse-direction reversed. + scroll_buffer_y = m_y; + } else { + scroll_buffer_y += m_y; } if (abs(scroll_buffer_y) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { const int16_t sign_y = scroll_buffer_y > 0 ? 1 : -1; mouse_report->v = sign_y; - if (m_y == 0 || ((m_y > 0) && (scroll_buffer_y > 0)) || ((m_y < 0) && (scroll_buffer_y < 0))) { - // Spill-over accumulated distance to the next cycle. - scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; - } else { - // Cancel accunulated distance if mouse-direction reversed. - scroll_buffer_y = 0; - } + scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; // Spill-over } mouse_report->x = mouse_report->y = 0; From 0cc4ef3bb7300062e393186ac9ab0b42e9b7521e Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 21 Feb 2024 01:50:51 +0200 Subject: [PATCH 4/4] Feat(bkb) can now coalesce drag-scroll vs queueing > MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ±1 scroll-wheel events. - doc: explain new `CHARYBDIS_DRAGSCROLL_SEND_COALESCED` define. --- keyboards/bastardkb/charybdis/charybdis.c | 24 +++++++++++++++++------ keyboards/bastardkb/charybdis/readme.md | 9 ++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index f9f6ccb1a12c..2d3d5194b5e7 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -196,10 +196,16 @@ static void pointing_device_task_charybdis(report_mouse_t* mouse_report) { } else { scroll_buffer_x += m_x; } - if (abs(scroll_buffer_x) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { + const int16_t abs_x = abs(scroll_buffer_x); + if (abs_x >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { const int16_t sign_x = scroll_buffer_x > 0 ? 1 : -1; - mouse_report->h = sign_x; - scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; // Spill-over +# ifdef CHARYBDIS_DRAGSCROLL_SEND_COALESCED + mouse_report->h = sign_x * (abs_x / CHARYBDIS_DRAGSCROLL_BUFFER_SIZE); + scroll_buffer_x = sign_x * (abs_x % CHARYBDIS_DRAGSCROLL_BUFFER_SIZE); +# else + mouse_report->h = sign_x; + scroll_buffer_x -= sign_x * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; +# endif // CHARYBDIS_DRAGSCROLL_SEND_COALESCED } # ifdef CHARYBDIS_DRAGSCROLL_REVERSE_Y @@ -213,10 +219,16 @@ static void pointing_device_task_charybdis(report_mouse_t* mouse_report) { } else { scroll_buffer_y += m_y; } - if (abs(scroll_buffer_y) >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { + const int16_t abs_y = abs(scroll_buffer_y); + if (abs_y >= CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { const int16_t sign_y = scroll_buffer_y > 0 ? 1 : -1; - mouse_report->v = sign_y; - scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; // Spill-over +# ifdef CHARYBDIS_DRAGSCROLL_SEND_COALESCED + mouse_report->v = sign_y * (abs_y / CHARYBDIS_DRAGSCROLL_BUFFER_SIZE); + scroll_buffer_y = sign_y * (abs_y % CHARYBDIS_DRAGSCROLL_BUFFER_SIZE); +# else + mouse_report->v = sign_y; + scroll_buffer_y -= sign_y * CHARYBDIS_DRAGSCROLL_BUFFER_SIZE; +# endif // CHARYBDIS_DRAGSCROLL_SEND_COALESCED } mouse_report->x = mouse_report->y = 0; diff --git a/keyboards/bastardkb/charybdis/readme.md b/keyboards/bastardkb/charybdis/readme.md index 01eef250cd9f..8e6b5e5f2a12 100644 --- a/keyboards/bastardkb/charybdis/readme.md +++ b/keyboards/bastardkb/charybdis/readme.md @@ -86,9 +86,16 @@ To invert the vertical scrolling direction (_ie._ mimic macOS "natural" scroll d ```c #define CHARYBDIS_DRAGSCROLL_REVERSE_Y ``` - This only affects the vertical scroll direction. + +By default, accumulated drag-scroll ±1 events from fast moves are queued and send through even after "wheel" has stopped moving. To send scroll-wheel events with values greater than ±1, +define `CHARYBDIS_DRAGSCROLL_SEND_COALESCED`: + +```c +#define CHARYBDIS_DRAGSCROLL_SEND_COALESCED +``` + ### Sniping mode Sniping mode slows down the pointer for more precise gestures. It is useful when combined with a higher default DPI.