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

fix: preserve accumulated drag-scroll distance, queued or coalesced #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
54 changes: 42 additions & 12 deletions keyboards/bastardkb/charybdis/charybdis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
9 changes: 8 additions & 1 deletion keyboards/bastardkb/charybdis/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading