From d4afbda97df2e9f3d32f2ea7e38194c54aa6e814 Mon Sep 17 00:00:00 2001 From: Alex Miller <39163867+doesntfazer@users.noreply.github.com> Date: Fri, 21 Apr 2023 14:45:42 -0400 Subject: [PATCH 1/2] Add additional options for Drag Scroll config I thought it was important to document different ways you can change drag scrolling to make it an even better feature. --- docs/feature_pointing_device.md | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 0089dc702404..ec11167033d9 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -434,6 +434,47 @@ 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 10 +#define SCROLL_DIVISOR_V 10 + +report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { + if (set_scrolling) { + mouse_report.h = mouse_report.x / SCROLL_DIVISOR_H; + mouse_report.v = mouse_report.y / SCROLL_DIVISOR_V; + mouse_report.x = 0; + mouse_report.y = 0; + } + return mouse_report; +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case DRAG_SCROLL: + set_scrolling = record->event.pressed; + break; + default: + break; + } + return true; +} + +``` + + ## Split Examples The following examples make use the `SPLIT_POINTING_ENABLE` functionality and show how to manipulate the mouse report for a scrolling mode. From 2e77cfe39f304fc8cc68c2e0adb3521b03e433e1 Mon Sep 17 00:00:00 2001 From: Alex Miller <39163867+doesntfazer@users.noreply.github.com> Date: Fri, 21 Apr 2023 16:34:23 -0400 Subject: [PATCH 2/2] Fixed some issues with example code in drag scroll Fixed a couple of issue with the example code that I provided. 2 issues, if you left the mouse layer while still holding drag scroll it would stay held down. Fixed that issue. In addition to that, if you move the pointing device too slowly, it wouldn't scroll. Caused by the way that the scroll values were being stored. --- docs/feature_pointing_device.md | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index ec11167033d9..4da5d64a1a56 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -448,22 +448,41 @@ enum custom_keycodes { bool set_scrolling = false; // Modify these values to adjust the scrolling speed -#define SCROLL_DIVISOR_H 10 -#define SCROLL_DIVISOR_V 10 +#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) { - mouse_report.h = mouse_report.x / SCROLL_DIVISOR_H; - mouse_report.v = mouse_report.y / SCROLL_DIVISOR_V; + // 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: @@ -472,6 +491,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { 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; +} + ```