Add additional options for Drag Scroll config (#20523)
This commit is contained in:
		@@ -434,6 +434,75 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
 | 
			
		||||
 | 
			
		||||
This allows you to toggle between scrolling and cursor movement by pressing the DRAG_SCROLL key.  
 | 
			
		||||
 | 
			
		||||
### Advanced Drag Scroll
 | 
			
		||||
 | 
			
		||||
Sometimes, like with the Cirque trackpad, you will run into issues where the scrolling may be too fast.
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
```c
 | 
			
		||||
enum custom_keycodes {
 | 
			
		||||
    DRAG_SCROLL = SAFE_RANGE,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
bool set_scrolling = false;
 | 
			
		||||
 | 
			
		||||
// Modify these values to adjust the scrolling speed
 | 
			
		||||
#define SCROLL_DIVISOR_H 8.0
 | 
			
		||||
#define SCROLL_DIVISOR_V 8.0
 | 
			
		||||
 | 
			
		||||
// Variables to store accumulated scroll values
 | 
			
		||||
float scroll_accumulated_h = 0;
 | 
			
		||||
float scroll_accumulated_v = 0;
 | 
			
		||||
 | 
			
		||||
// Function to handle mouse reports and perform drag scrolling
 | 
			
		||||
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
 | 
			
		||||
    // Check if drag scrolling is active
 | 
			
		||||
    if (set_scrolling) {
 | 
			
		||||
        // Calculate and accumulate scroll values based on mouse movement and divisors
 | 
			
		||||
        scroll_accumulated_h += (float)mouse_report.x / SCROLL_DIVISOR_H;
 | 
			
		||||
        scroll_accumulated_v += (float)mouse_report.y / SCROLL_DIVISOR_V;
 | 
			
		||||
 | 
			
		||||
        // Assign integer parts of accumulated scroll values to the mouse report
 | 
			
		||||
        mouse_report.h = (int8_t)scroll_accumulated_h;
 | 
			
		||||
        mouse_report.v = (int8_t)scroll_accumulated_v;
 | 
			
		||||
 | 
			
		||||
        // Update accumulated scroll values by subtracting the integer parts
 | 
			
		||||
        scroll_accumulated_h -= (int8_t)scroll_accumulated_h;
 | 
			
		||||
        scroll_accumulated_v -= (int8_t)scroll_accumulated_v;
 | 
			
		||||
 | 
			
		||||
        // Clear the X and Y values of the mouse report
 | 
			
		||||
        mouse_report.x = 0;
 | 
			
		||||
        mouse_report.y = 0;
 | 
			
		||||
    }
 | 
			
		||||
    return mouse_report;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function to handle key events and enable/disable drag scrolling
 | 
			
		||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
 | 
			
		||||
    switch (keycode) {
 | 
			
		||||
        case DRAG_SCROLL:
 | 
			
		||||
            // Toggle set_scrolling when DRAG_SCROLL key is pressed or released
 | 
			
		||||
            set_scrolling = record->event.pressed;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function to handle layer changes and disable drag scrolling when not in AUTO_MOUSE_DEFAULT_LAYER
 | 
			
		||||
layer_state_t layer_state_set_user(layer_state_t state) {
 | 
			
		||||
    // Disable set_scrolling if the current layer is not the AUTO_MOUSE_DEFAULT_LAYER
 | 
			
		||||
    if (get_highest_layer(state) != AUTO_MOUSE_DEFAULT_LAYER) {
 | 
			
		||||
        set_scrolling = false;
 | 
			
		||||
    }
 | 
			
		||||
    return state;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Split Examples
 | 
			
		||||
 | 
			
		||||
The following examples make use the `SPLIT_POINTING_ENABLE` functionality and show how to manipulate the mouse report for a scrolling mode.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user