Skip to content

Commit 40380c2

Browse files
authored
Add additional options for Drag Scroll config (#20523)
1 parent a68b620 commit 40380c2

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docs/feature_pointing_device.md

+69
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,75 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
434434
435435
This allows you to toggle between scrolling and cursor movement by pressing the DRAG_SCROLL key.
436436
437+
### Advanced Drag Scroll
438+
439+
Sometimes, like with the Cirque trackpad, you will run into issues where the scrolling may be too fast.
440+
441+
Here is a slightly more advanced example of drag scrolling. You will be able to change the scroll speed based on the values in set in `SCROLL_DIVISOR_H` and `SCROLL_DIVISOR_V`. This bit of code is also set up so that instead of toggling the scrolling state with set_scrolling = !set_scrolling, the set_scrolling variable is set directly to record->event.pressed. This way, the drag scrolling will only be active while the DRAG_SCROLL button is held down.
442+
443+
```c
444+
enum custom_keycodes {
445+
DRAG_SCROLL = SAFE_RANGE,
446+
};
447+
448+
bool set_scrolling = false;
449+
450+
// Modify these values to adjust the scrolling speed
451+
#define SCROLL_DIVISOR_H 8.0
452+
#define SCROLL_DIVISOR_V 8.0
453+
454+
// Variables to store accumulated scroll values
455+
float scroll_accumulated_h = 0;
456+
float scroll_accumulated_v = 0;
457+
458+
// Function to handle mouse reports and perform drag scrolling
459+
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
460+
// Check if drag scrolling is active
461+
if (set_scrolling) {
462+
// Calculate and accumulate scroll values based on mouse movement and divisors
463+
scroll_accumulated_h += (float)mouse_report.x / SCROLL_DIVISOR_H;
464+
scroll_accumulated_v += (float)mouse_report.y / SCROLL_DIVISOR_V;
465+
466+
// Assign integer parts of accumulated scroll values to the mouse report
467+
mouse_report.h = (int8_t)scroll_accumulated_h;
468+
mouse_report.v = (int8_t)scroll_accumulated_v;
469+
470+
// Update accumulated scroll values by subtracting the integer parts
471+
scroll_accumulated_h -= (int8_t)scroll_accumulated_h;
472+
scroll_accumulated_v -= (int8_t)scroll_accumulated_v;
473+
474+
// Clear the X and Y values of the mouse report
475+
mouse_report.x = 0;
476+
mouse_report.y = 0;
477+
}
478+
return mouse_report;
479+
}
480+
481+
// Function to handle key events and enable/disable drag scrolling
482+
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
483+
switch (keycode) {
484+
case DRAG_SCROLL:
485+
// Toggle set_scrolling when DRAG_SCROLL key is pressed or released
486+
set_scrolling = record->event.pressed;
487+
break;
488+
default:
489+
break;
490+
}
491+
return true;
492+
}
493+
494+
// Function to handle layer changes and disable drag scrolling when not in AUTO_MOUSE_DEFAULT_LAYER
495+
layer_state_t layer_state_set_user(layer_state_t state) {
496+
// Disable set_scrolling if the current layer is not the AUTO_MOUSE_DEFAULT_LAYER
497+
if (get_highest_layer(state) != AUTO_MOUSE_DEFAULT_LAYER) {
498+
set_scrolling = false;
499+
}
500+
return state;
501+
}
502+
503+
```
504+
505+
437506
## Split Examples
438507

439508
The following examples make use the `SPLIT_POINTING_ENABLE` functionality and show how to manipulate the mouse report for a scrolling mode.

0 commit comments

Comments
 (0)