diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index c9f0e6317283..2d3d5194b5e7 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -186,25 +186,55 @@ 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 + 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; + } + 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; +# 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 - 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; - if (abs(scroll_buffer_x) > CHARYBDIS_DRAGSCROLL_BUFFER_SIZE) { - mouse_report->h = scroll_buffer_x > 0 ? 1 : -1; - 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) { - mouse_report->v = scroll_buffer_y > 0 ? 1 : -1; - scroll_buffer_y = 0; + 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; +# 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; + } else { // not a drag-scroll event + // Clean up, or next draa-scroll actevation would start abruptly. + scroll_buffer_x = scroll_buffer_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.